@loreai/core 0.0.1 → 0.10.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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -5
  3. package/dist/bun/agents-file.d.ts +59 -0
  4. package/dist/bun/agents-file.d.ts.map +1 -0
  5. package/dist/bun/config.d.ts +58 -0
  6. package/dist/bun/config.d.ts.map +1 -0
  7. package/dist/bun/curator.d.ts +35 -0
  8. package/dist/bun/curator.d.ts.map +1 -0
  9. package/dist/bun/db/driver.bun.d.ts +5 -0
  10. package/dist/bun/db/driver.bun.d.ts.map +1 -0
  11. package/dist/bun/db/driver.node.d.ts +15 -0
  12. package/dist/bun/db/driver.node.d.ts.map +1 -0
  13. package/dist/bun/db.d.ts +22 -0
  14. package/dist/bun/db.d.ts.map +1 -0
  15. package/dist/bun/distillation.d.ts +32 -0
  16. package/dist/bun/distillation.d.ts.map +1 -0
  17. package/dist/bun/embedding.d.ts +90 -0
  18. package/dist/bun/embedding.d.ts.map +1 -0
  19. package/dist/bun/gradient.d.ts +73 -0
  20. package/dist/bun/gradient.d.ts.map +1 -0
  21. package/dist/bun/index.d.ts +19 -0
  22. package/dist/bun/index.d.ts.map +1 -0
  23. package/dist/bun/index.js +28236 -0
  24. package/dist/bun/index.js.map +7 -0
  25. package/dist/bun/lat-reader.d.ts +69 -0
  26. package/dist/bun/lat-reader.d.ts.map +1 -0
  27. package/dist/bun/log.d.ts +17 -0
  28. package/dist/bun/log.d.ts.map +1 -0
  29. package/dist/bun/ltm.d.ts +138 -0
  30. package/dist/bun/ltm.d.ts.map +1 -0
  31. package/dist/bun/markdown.d.ts +37 -0
  32. package/dist/bun/markdown.d.ts.map +1 -0
  33. package/dist/bun/prompt.d.ts +47 -0
  34. package/dist/bun/prompt.d.ts.map +1 -0
  35. package/dist/bun/recall.d.ts +41 -0
  36. package/dist/bun/recall.d.ts.map +1 -0
  37. package/dist/bun/search.d.ts +113 -0
  38. package/dist/bun/search.d.ts.map +1 -0
  39. package/dist/bun/temporal.d.ts +66 -0
  40. package/dist/bun/temporal.d.ts.map +1 -0
  41. package/dist/bun/types.d.ts +180 -0
  42. package/dist/bun/types.d.ts.map +1 -0
  43. package/dist/bun/worker.d.ts +6 -0
  44. package/dist/bun/worker.d.ts.map +1 -0
  45. package/dist/node/agents-file.d.ts +59 -0
  46. package/dist/node/agents-file.d.ts.map +1 -0
  47. package/dist/node/config.d.ts +58 -0
  48. package/dist/node/config.d.ts.map +1 -0
  49. package/dist/node/curator.d.ts +35 -0
  50. package/dist/node/curator.d.ts.map +1 -0
  51. package/dist/node/db/driver.bun.d.ts +5 -0
  52. package/dist/node/db/driver.bun.d.ts.map +1 -0
  53. package/dist/node/db/driver.node.d.ts +15 -0
  54. package/dist/node/db/driver.node.d.ts.map +1 -0
  55. package/dist/node/db.d.ts +22 -0
  56. package/dist/node/db.d.ts.map +1 -0
  57. package/dist/node/distillation.d.ts +32 -0
  58. package/dist/node/distillation.d.ts.map +1 -0
  59. package/dist/node/embedding.d.ts +90 -0
  60. package/dist/node/embedding.d.ts.map +1 -0
  61. package/dist/node/gradient.d.ts +73 -0
  62. package/dist/node/gradient.d.ts.map +1 -0
  63. package/dist/node/index.d.ts +19 -0
  64. package/dist/node/index.d.ts.map +1 -0
  65. package/dist/node/index.js +28253 -0
  66. package/dist/node/index.js.map +7 -0
  67. package/dist/node/lat-reader.d.ts +69 -0
  68. package/dist/node/lat-reader.d.ts.map +1 -0
  69. package/dist/node/log.d.ts +17 -0
  70. package/dist/node/log.d.ts.map +1 -0
  71. package/dist/node/ltm.d.ts +138 -0
  72. package/dist/node/ltm.d.ts.map +1 -0
  73. package/dist/node/markdown.d.ts +37 -0
  74. package/dist/node/markdown.d.ts.map +1 -0
  75. package/dist/node/prompt.d.ts +47 -0
  76. package/dist/node/prompt.d.ts.map +1 -0
  77. package/dist/node/recall.d.ts +41 -0
  78. package/dist/node/recall.d.ts.map +1 -0
  79. package/dist/node/search.d.ts +113 -0
  80. package/dist/node/search.d.ts.map +1 -0
  81. package/dist/node/temporal.d.ts +66 -0
  82. package/dist/node/temporal.d.ts.map +1 -0
  83. package/dist/node/types.d.ts +180 -0
  84. package/dist/node/types.d.ts.map +1 -0
  85. package/dist/node/worker.d.ts +6 -0
  86. package/dist/node/worker.d.ts.map +1 -0
  87. package/dist/types/agents-file.d.ts +59 -0
  88. package/dist/types/agents-file.d.ts.map +1 -0
  89. package/dist/types/config.d.ts +58 -0
  90. package/dist/types/config.d.ts.map +1 -0
  91. package/dist/types/curator.d.ts +35 -0
  92. package/dist/types/curator.d.ts.map +1 -0
  93. package/dist/types/db/driver.bun.d.ts +5 -0
  94. package/dist/types/db/driver.bun.d.ts.map +1 -0
  95. package/dist/types/db/driver.node.d.ts +15 -0
  96. package/dist/types/db/driver.node.d.ts.map +1 -0
  97. package/dist/types/db.d.ts +22 -0
  98. package/dist/types/db.d.ts.map +1 -0
  99. package/dist/types/distillation.d.ts +32 -0
  100. package/dist/types/distillation.d.ts.map +1 -0
  101. package/dist/types/embedding.d.ts +90 -0
  102. package/dist/types/embedding.d.ts.map +1 -0
  103. package/dist/types/gradient.d.ts +73 -0
  104. package/dist/types/gradient.d.ts.map +1 -0
  105. package/dist/types/index.d.ts +19 -0
  106. package/dist/types/index.d.ts.map +1 -0
  107. package/dist/types/lat-reader.d.ts +69 -0
  108. package/dist/types/lat-reader.d.ts.map +1 -0
  109. package/dist/types/log.d.ts +17 -0
  110. package/dist/types/log.d.ts.map +1 -0
  111. package/dist/types/ltm.d.ts +138 -0
  112. package/dist/types/ltm.d.ts.map +1 -0
  113. package/dist/types/markdown.d.ts +37 -0
  114. package/dist/types/markdown.d.ts.map +1 -0
  115. package/dist/types/prompt.d.ts +47 -0
  116. package/dist/types/prompt.d.ts.map +1 -0
  117. package/dist/types/recall.d.ts +41 -0
  118. package/dist/types/recall.d.ts.map +1 -0
  119. package/dist/types/search.d.ts +113 -0
  120. package/dist/types/search.d.ts.map +1 -0
  121. package/dist/types/temporal.d.ts +66 -0
  122. package/dist/types/temporal.d.ts.map +1 -0
  123. package/dist/types/types.d.ts +180 -0
  124. package/dist/types/types.d.ts.map +1 -0
  125. package/dist/types/worker.d.ts +6 -0
  126. package/dist/types/worker.d.ts.map +1 -0
  127. package/package.json +48 -5
  128. package/src/agents-file.ts +406 -0
  129. package/src/config.ts +132 -0
  130. package/src/curator.ts +220 -0
  131. package/src/db/driver.bun.ts +18 -0
  132. package/src/db/driver.node.ts +54 -0
  133. package/src/db.ts +433 -0
  134. package/src/distillation.ts +433 -0
  135. package/src/embedding.ts +528 -0
  136. package/src/gradient.ts +1387 -0
  137. package/src/index.ts +109 -0
  138. package/src/lat-reader.ts +374 -0
  139. package/src/log.ts +27 -0
  140. package/src/ltm.ts +861 -0
  141. package/src/markdown.ts +129 -0
  142. package/src/prompt.ts +454 -0
  143. package/src/recall.ts +446 -0
  144. package/src/search.ts +330 -0
  145. package/src/temporal.ts +379 -0
  146. package/src/types.ts +199 -0
  147. package/src/worker.ts +26 -0
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Host-agnostic message and part types for Lore's core memory engine.
3
+ *
4
+ * These replace the direct dependency on `@opencode-ai/sdk`'s `Message` and
5
+ * `Part` types so the core can run under any host (OpenCode, Pi, future ACP
6
+ * server, etc.). Each host adapter converts between its native types and these
7
+ * Lore-internal types at the hook boundary.
8
+ *
9
+ * The type surface is intentionally minimal — only the fields that Lore's
10
+ * runtime code actually reads/writes are included. Fields that only exist for
11
+ * the host's UI or for features Lore doesn't touch are omitted.
12
+ */
13
+ export type LoreUserMessage = {
14
+ id: string;
15
+ sessionID: string;
16
+ role: "user";
17
+ time: {
18
+ created: number;
19
+ };
20
+ /** Agent name (e.g. "build", "plan"). Host-specific; stored as metadata. */
21
+ agent: string;
22
+ /** Model used for this turn. Stored as metadata. */
23
+ model: {
24
+ providerID: string;
25
+ modelID: string;
26
+ };
27
+ };
28
+ export type LoreAssistantMessage = {
29
+ id: string;
30
+ sessionID: string;
31
+ role: "assistant";
32
+ time: {
33
+ created: number;
34
+ };
35
+ parentID: string;
36
+ modelID: string;
37
+ providerID: string;
38
+ mode: string;
39
+ path: {
40
+ cwd: string;
41
+ root: string;
42
+ };
43
+ cost: number;
44
+ tokens: {
45
+ input: number;
46
+ output: number;
47
+ reasoning: number;
48
+ cache: {
49
+ read: number;
50
+ write: number;
51
+ };
52
+ };
53
+ };
54
+ /** Discriminated union on `.role`. */
55
+ export type LoreMessage = LoreUserMessage | LoreAssistantMessage;
56
+ export type LoreTextPart = {
57
+ id: string;
58
+ sessionID: string;
59
+ messageID: string;
60
+ type: "text";
61
+ text: string;
62
+ /** Marks Lore-injected synthetic messages (e.g. distilled prefix). */
63
+ synthetic?: boolean;
64
+ /** Optional timing info — present on real messages, faked on synthetics. */
65
+ time?: {
66
+ start: number;
67
+ end?: number;
68
+ };
69
+ };
70
+ export type LoreReasoningPart = {
71
+ id: string;
72
+ sessionID: string;
73
+ messageID: string;
74
+ type: "reasoning";
75
+ text: string;
76
+ };
77
+ export type LoreToolStatePending = {
78
+ status: "pending";
79
+ input: unknown;
80
+ };
81
+ export type LoreToolStateRunning = {
82
+ status: "running";
83
+ input: unknown;
84
+ metadata?: unknown;
85
+ time: {
86
+ start: number;
87
+ };
88
+ };
89
+ export type LoreToolStateCompleted = {
90
+ status: "completed";
91
+ input: unknown;
92
+ output: string;
93
+ metadata?: unknown;
94
+ time: {
95
+ start: number;
96
+ end: number;
97
+ };
98
+ };
99
+ export type LoreToolStateError = {
100
+ status: "error";
101
+ input: unknown;
102
+ error: string;
103
+ metadata?: unknown;
104
+ time: {
105
+ start: number;
106
+ end: number;
107
+ };
108
+ };
109
+ export type LoreToolState = LoreToolStatePending | LoreToolStateRunning | LoreToolStateCompleted | LoreToolStateError;
110
+ export type LoreToolPart = {
111
+ id: string;
112
+ sessionID: string;
113
+ messageID: string;
114
+ type: "tool";
115
+ tool: string;
116
+ callID: string;
117
+ state: LoreToolState;
118
+ };
119
+ /**
120
+ * Discriminated union on `.type`.
121
+ *
122
+ * Only `text`, `reasoning`, and `tool` are processed by Lore's core logic.
123
+ * All other part types (step-start, snapshot, patch, agent, retry, etc.) flow
124
+ * through untouched — they hit the `else` branch with a flat 20-token estimate
125
+ * in `estimateParts()` and are preserved as-is in the message transform.
126
+ *
127
+ * For type-safe narrowing, use `isToolPart()` / `isTextPart()` helpers below.
128
+ */
129
+ export type LorePart = LoreTextPart | LoreReasoningPart | LoreToolPart | LoreGenericPart;
130
+ /**
131
+ * Passthrough for host-specific part types that Lore doesn't process.
132
+ * The `type` field is typed as `string` since Lore only cares that it's not
133
+ * one of the three known types.
134
+ */
135
+ export type LoreGenericPart = {
136
+ type: string;
137
+ [key: string]: unknown;
138
+ };
139
+ export declare function isTextPart(p: LorePart): p is LoreTextPart;
140
+ export declare function isReasoningPart(p: LorePart): p is LoreReasoningPart;
141
+ export declare function isToolPart(p: LorePart): p is LoreToolPart;
142
+ export type LoreMessageWithParts = {
143
+ info: LoreMessage;
144
+ parts: LorePart[];
145
+ };
146
+ /**
147
+ * Abstract interface for single-turn LLM prompt→response.
148
+ *
149
+ * All of Lore's background LLM work (distillation, curation, query expansion)
150
+ * is single-turn: one system+user message in, one text response out. No tool
151
+ * calling, no multi-turn. This interface captures that minimal surface.
152
+ *
153
+ * Host adapters implement this:
154
+ * - OpenCode: wraps `client.session.create()` + `client.session.prompt()`
155
+ * - Pi: wraps `complete()` from `@mariozechner/pi-ai`
156
+ * - Standalone: direct `fetch()` to provider APIs
157
+ */
158
+ export interface LLMClient {
159
+ /**
160
+ * Send a single prompt and return the text response.
161
+ *
162
+ * @param system System prompt text
163
+ * @param user User message text
164
+ * @param opts Optional model selection and worker identification
165
+ * @returns The assistant's text response, or null on failure
166
+ */
167
+ prompt(system: string, user: string, opts?: {
168
+ /** Override model for this call. */
169
+ model?: {
170
+ providerID: string;
171
+ modelID: string;
172
+ };
173
+ /**
174
+ * Opaque worker identifier used by the host to route the request
175
+ * (e.g. OpenCode uses this as the session agent name).
176
+ */
177
+ workerID?: string;
178
+ }): Promise<string | null>;
179
+ }
180
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ export type { LLMClient } from "./types";
2
+ /** Set of ALL worker session IDs across distillation, curator, and query expansion.
3
+ * Used by shouldSkip() in host adapters to avoid storing/distilling worker messages. */
4
+ export declare const workerSessionIDs: Set<string>;
5
+ export declare function isWorkerSession(sessionID: string): boolean;
6
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/worker.ts"],"names":[],"mappings":"AAaA,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMzC;yFACyF;AACzF,eAAO,MAAM,gBAAgB,aAAoB,CAAC;AAElD,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE1D"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * agents-file.ts — AGENTS.md export/import/sync for lore.
3
+ *
4
+ * Lore owns a clearly delimited section inside the file, bounded by HTML
5
+ * comment markers. Everything outside those markers is preserved verbatim.
6
+ * Each knowledge entry is preceded by a hidden <!-- lore:UUID --> comment so
7
+ * the same entry can be tracked across machines and merge conflicts resolved
8
+ * without duplication.
9
+ */
10
+ export declare const LORE_SECTION_START = "<!-- This section is maintained by the coding agent via lore (https://github.com/BYK/loreai) -->";
11
+ export declare const LORE_SECTION_END = "<!-- End lore-managed section -->";
12
+ export type ParsedFileEntry = {
13
+ /** UUID from `<!-- lore:UUID -->` marker, or null for hand-written entries. */
14
+ id: string | null;
15
+ category: string;
16
+ title: string;
17
+ content: string;
18
+ };
19
+ /**
20
+ * Extract ParsedFileEntry objects from a markdown section body.
21
+ * Handles:
22
+ * - `<!-- lore:UUID -->` markers before bullet points → id set
23
+ * - Bare bullet points without markers → id null
24
+ * - Category derived from the nearest preceding `### Heading`
25
+ * - Malformed or non-UUID markers → id null (hand-written)
26
+ * - Duplicate UUIDs → both returned; caller deduplicates
27
+ */
28
+ export declare function parseEntriesFromSection(section: string): ParsedFileEntry[];
29
+ /**
30
+ * Write current knowledge entries into the AGENTS.md file, preserving all
31
+ * non-lore content. Creates the file if it doesn't exist.
32
+ */
33
+ export declare function exportToFile(input: {
34
+ projectPath: string;
35
+ filePath: string;
36
+ }): void;
37
+ /**
38
+ * Returns true if the file needs to be imported:
39
+ * - File exists and has never been processed (no lore markers)
40
+ * - File exists and its lore section differs from what lore would currently produce
41
+ */
42
+ export declare function shouldImport(input: {
43
+ projectPath: string;
44
+ filePath: string;
45
+ }): boolean;
46
+ /**
47
+ * Import knowledge entries from the agents file into the local DB.
48
+ *
49
+ * Behaviour per entry:
50
+ * - Known UUID (already in DB) → update content if it changed (manual edit)
51
+ * - Unknown UUID (other machine)→ create with that exact ID
52
+ * - No UUID (hand-written) → create with a new UUIDv7
53
+ * - Duplicate UUID in same file → first occurrence wins, rest ignored
54
+ */
55
+ export declare function importFromFile(input: {
56
+ projectPath: string;
57
+ filePath: string;
58
+ }): void;
59
+ //# sourceMappingURL=agents-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents-file.d.ts","sourceRoot":"","sources":["../../src/agents-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,eAAO,MAAM,kBAAkB,qGACqE,CAAC;AACrG,eAAO,MAAM,gBAAgB,sCAAsC,CAAC;AAyBpE,MAAM,MAAM,eAAe,GAAG;IAC5B,+EAA+E;IAC/E,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AA+EF;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,EAAE,CAgD1E;AAmFD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAsBP;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAcV;AAMD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CA2DP"}
@@ -0,0 +1,58 @@
1
+ import { z } from "zod";
2
+ export declare const LoreConfig: z.ZodObject<{
3
+ model: z.ZodOptional<z.ZodObject<{
4
+ providerID: z.ZodString;
5
+ modelID: z.ZodString;
6
+ }, z.core.$strip>>;
7
+ budget: z.ZodDefault<z.ZodObject<{
8
+ distilled: z.ZodDefault<z.ZodNumber>;
9
+ raw: z.ZodDefault<z.ZodNumber>;
10
+ output: z.ZodDefault<z.ZodNumber>;
11
+ ltm: z.ZodDefault<z.ZodNumber>;
12
+ }, z.core.$strip>>;
13
+ distillation: z.ZodDefault<z.ZodObject<{
14
+ minMessages: z.ZodDefault<z.ZodNumber>;
15
+ maxSegment: z.ZodDefault<z.ZodNumber>;
16
+ metaThreshold: z.ZodDefault<z.ZodNumber>;
17
+ }, z.core.$strip>>;
18
+ knowledge: z.ZodDefault<z.ZodObject<{
19
+ enabled: z.ZodDefault<z.ZodBoolean>;
20
+ }, z.core.$strip>>;
21
+ curator: z.ZodDefault<z.ZodObject<{
22
+ enabled: z.ZodDefault<z.ZodBoolean>;
23
+ onIdle: z.ZodDefault<z.ZodBoolean>;
24
+ afterTurns: z.ZodDefault<z.ZodNumber>;
25
+ maxEntries: z.ZodDefault<z.ZodNumber>;
26
+ }, z.core.$strip>>;
27
+ pruning: z.ZodDefault<z.ZodObject<{
28
+ retention: z.ZodDefault<z.ZodNumber>;
29
+ maxStorage: z.ZodDefault<z.ZodNumber>;
30
+ }, z.core.$strip>>;
31
+ search: z.ZodDefault<z.ZodObject<{
32
+ ftsWeights: z.ZodDefault<z.ZodObject<{
33
+ title: z.ZodDefault<z.ZodNumber>;
34
+ content: z.ZodDefault<z.ZodNumber>;
35
+ category: z.ZodDefault<z.ZodNumber>;
36
+ }, z.core.$strip>>;
37
+ recallLimit: z.ZodDefault<z.ZodNumber>;
38
+ queryExpansion: z.ZodDefault<z.ZodBoolean>;
39
+ embeddings: z.ZodDefault<z.ZodObject<{
40
+ enabled: z.ZodDefault<z.ZodBoolean>;
41
+ provider: z.ZodDefault<z.ZodEnum<{
42
+ voyage: "voyage";
43
+ openai: "openai";
44
+ }>>;
45
+ model: z.ZodDefault<z.ZodString>;
46
+ dimensions: z.ZodDefault<z.ZodNumber>;
47
+ }, z.core.$strip>>;
48
+ }, z.core.$strip>>;
49
+ crossProject: z.ZodDefault<z.ZodBoolean>;
50
+ agentsFile: z.ZodDefault<z.ZodObject<{
51
+ enabled: z.ZodDefault<z.ZodBoolean>;
52
+ path: z.ZodDefault<z.ZodString>;
53
+ }, z.core.$strip>>;
54
+ }, z.core.$strip>;
55
+ export type LoreConfig = z.infer<typeof LoreConfig>;
56
+ export declare function config(): LoreConfig;
57
+ export declare function load(directory: string): Promise<LoreConfig>;
58
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4GrB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAIpD,wBAAgB,MAAM,IAAI,UAAU,CAEnC;AAED,wBAAsB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CASjE"}
@@ -0,0 +1,35 @@
1
+ import type { LLMClient } from "./types";
2
+ export declare function run(input: {
3
+ llm: LLMClient;
4
+ projectPath: string;
5
+ sessionID: string;
6
+ model?: {
7
+ providerID: string;
8
+ modelID: string;
9
+ };
10
+ }): Promise<{
11
+ created: number;
12
+ updated: number;
13
+ deleted: number;
14
+ }>;
15
+ export declare function resetCurationTracker(sessionID?: string): void;
16
+ /**
17
+ * Consolidation pass: reviews ALL project entries and merges/trims/deletes
18
+ * to reduce entry count to cfg.curator.maxEntries. Only runs when the current
19
+ * entry count exceeds the target. Uses the same worker session as curation.
20
+ *
21
+ * Only "update" and "delete" ops are applied — consolidation never creates entries.
22
+ */
23
+ export declare function consolidate(input: {
24
+ llm: LLMClient;
25
+ projectPath: string;
26
+ sessionID: string;
27
+ model?: {
28
+ providerID: string;
29
+ modelID: string;
30
+ };
31
+ }): Promise<{
32
+ updated: number;
33
+ deleted: number;
34
+ }>;
35
+ //# sourceMappingURL=curator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curator.d.ts","sourceRoot":"","sources":["../../src/curator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AA+CzC,wBAAsB,GAAG,CAAC,KAAK,EAAE;IAC/B,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAsFjE;AAED,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,MAAM,QAMtD;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE;IACvC,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAsDhD"}
@@ -0,0 +1,5 @@
1
+ import { Database } from "bun:sqlite";
2
+ export { Database };
3
+ /** Stable SHA-256 hex digest — replaces the Bun-only `Bun.CryptoHasher`. */
4
+ export declare function sha256(input: string): string;
5
+ //# sourceMappingURL=driver.bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.bun.d.ts","sourceRoot":"","sources":["../../../src/db/driver.bun.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,15 @@
1
+ import { DatabaseSync, type StatementSync } from "node:sqlite";
2
+ /**
3
+ * Drop-in replacement for `bun:sqlite`'s `Database`.
4
+ *
5
+ * Adds a `.query()` method that caches the underlying `StatementSync`
6
+ * per SQL string. All other methods (`.prepare()`, `.exec()`, `.run()`,
7
+ * `.close()`, PRAGMAs, transactions) come from `DatabaseSync` unchanged.
8
+ */
9
+ export declare class Database extends DatabaseSync {
10
+ /** Cached prepared statement for this SQL. Compiled on first call. */
11
+ query(sql: string): StatementSync;
12
+ }
13
+ /** Stable SHA-256 hex digest — replaces the Bun-only `Bun.CryptoHasher`. */
14
+ export declare function sha256(input: string): string;
15
+ //# sourceMappingURL=driver.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.node.d.ts","sourceRoot":"","sources":["../../../src/db/driver.node.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAgB/D;;;;;;GAMG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC,sEAAsE;IACtE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;CAalC;AAED,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,22 @@
1
+ import { Database } from "#db/driver";
2
+ export declare function db(): Database;
3
+ export declare function close(): void;
4
+ export declare function ensureProject(path: string, name?: string): string;
5
+ export declare function projectId(path: string): string | undefined;
6
+ /** Look up a project's display name by its internal ID. */
7
+ export declare function projectName(id: string): string | null;
8
+ /**
9
+ * Returns true if Lore has never been used before (no projects in the DB).
10
+ * Must be called before ensureProject() to get an accurate result.
11
+ */
12
+ export declare function isFirstRun(): boolean;
13
+ /**
14
+ * Load persisted forceMinLayer for a session. Returns 0 if none stored.
15
+ */
16
+ export declare function loadForceMinLayer(sessionID: string): number;
17
+ /**
18
+ * Persist forceMinLayer for a session. Deletes the row when layer is 0
19
+ * (consumed) to avoid unbounded growth.
20
+ */
21
+ export declare function saveForceMinLayer(sessionID: string, layer: number): void;
22
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqStC,wBAAgB,EAAE,IAAI,QAAQ,CAwB7B;AAqCD,wBAAgB,KAAK,SAKpB;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAYjE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK1D;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKrD;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAYxE"}
@@ -0,0 +1,32 @@
1
+ import { workerSessionIDs } from "./worker";
2
+ import type { LLMClient } from "./types";
3
+ export { workerSessionIDs };
4
+ /** Safely parse the source_ids JSON column. Defaults to [] on corrupt data. */
5
+ export declare function parseSourceIds(raw: string): string[];
6
+ export type Distillation = {
7
+ id: string;
8
+ project_id: string;
9
+ session_id: string;
10
+ observations: string;
11
+ source_ids: string[];
12
+ generation: number;
13
+ token_count: number;
14
+ created_at: number;
15
+ };
16
+ /** Load all distillations for a session, oldest first. */
17
+ export declare function loadForSession(projectPath: string, sessionID: string): Distillation[];
18
+ export declare function run(input: {
19
+ llm: LLMClient;
20
+ projectPath: string;
21
+ sessionID: string;
22
+ model?: {
23
+ providerID: string;
24
+ modelID: string;
25
+ };
26
+ /** Skip minMessages threshold check — distill whatever is pending */
27
+ force?: boolean;
28
+ }): Promise<{
29
+ rounds: number;
30
+ distilled: number;
31
+ }>;
32
+ //# sourceMappingURL=distillation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distillation.d.ts","sourceRoot":"","sources":["../../src/distillation.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAuE5B,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAQpD;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,YAAY,EAAE,CAoBhB;AAuID,wBAAsB,GAAG,CAAC,KAAK,EAAE;IAC/B,GAAG,EAAE,SAAS,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,qEAAqE;IACrE,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CA4DjD"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Embedding integration for vector search.
3
+ *
4
+ * Supports multiple embedding providers (Voyage AI, OpenAI) behind a common
5
+ * interface. Provides embedding generation, pure-JS cosine similarity, and
6
+ * vector search over the knowledge and distillation tables. All operations
7
+ * are gated behind `search.embeddings.enabled` config + the provider's API
8
+ * key env var — falls back silently to FTS-only when unavailable.
9
+ */
10
+ export interface EmbeddingProvider {
11
+ embed(texts: string[], inputType: "document" | "query"): Promise<Float32Array[]>;
12
+ readonly maxBatchSize: number;
13
+ }
14
+ /** Reset cached provider — called when config changes. */
15
+ export declare function resetProvider(): void;
16
+ /** Returns true if embedding is available.
17
+ * Active when the configured provider's API key is set, unless explicitly
18
+ * disabled via `search.embeddings.enabled: false` in .lore.json. */
19
+ export declare function isAvailable(): boolean;
20
+ /**
21
+ * Generate embeddings for the given texts using the configured provider.
22
+ *
23
+ * @param texts Array of texts to embed
24
+ * @param inputType "document" for storage, "query" for search
25
+ * @returns Float32Array per input text
26
+ * @throws On API errors or missing provider
27
+ */
28
+ export declare function embed(texts: string[], inputType: "document" | "query"): Promise<Float32Array[]>;
29
+ /**
30
+ * Cosine similarity between two Float32Array vectors.
31
+ * Returns -1.0 to 1.0 where 1.0 = identical direction.
32
+ * Returns 0 if either vector is zero-length.
33
+ */
34
+ export declare function cosineSimilarity(a: Float32Array, b: Float32Array): number;
35
+ /** Convert Float32Array to Buffer for SQLite BLOB storage. */
36
+ export declare function toBlob(arr: Float32Array): Buffer;
37
+ /** Convert SQLite BLOB (Buffer/Uint8Array) back to Float32Array. */
38
+ export declare function fromBlob(blob: Buffer | Uint8Array): Float32Array;
39
+ type VectorHit = {
40
+ id: string;
41
+ similarity: number;
42
+ };
43
+ /**
44
+ * Search all knowledge entries with embeddings by cosine similarity.
45
+ * Returns top-k entries sorted by similarity descending.
46
+ * Pure brute-force — fine for <100 entries (microseconds).
47
+ */
48
+ export declare function vectorSearch(queryEmbedding: Float32Array, limit?: number): VectorHit[];
49
+ /**
50
+ * Search non-archived distillations with embeddings by cosine similarity.
51
+ * Returns top-k entries sorted by similarity descending.
52
+ * Pure brute-force — fine for ~50 entries.
53
+ */
54
+ export declare function vectorSearchDistillations(queryEmbedding: Float32Array, limit?: number): VectorHit[];
55
+ /**
56
+ * Embed a knowledge entry and store the result in the DB.
57
+ * Fire-and-forget — errors are logged, never thrown.
58
+ * The entry remains usable via FTS even if embedding fails.
59
+ */
60
+ export declare function embedKnowledgeEntry(id: string, title: string, content: string): void;
61
+ /**
62
+ * Embed a distillation and store the result in the DB.
63
+ * Fire-and-forget — errors are logged, never thrown.
64
+ * The distillation remains searchable via FTS even if embedding fails.
65
+ */
66
+ export declare function embedDistillation(id: string, observations: string): void;
67
+ /**
68
+ * Check if embedding config has changed since the last backfill.
69
+ * If so, clear all existing embeddings (they're incompatible) and
70
+ * update the stored fingerprint.
71
+ *
72
+ * Returns true if embeddings were cleared (full re-embed needed).
73
+ */
74
+ export declare function checkConfigChange(): boolean;
75
+ /**
76
+ * Embed all knowledge entries that are missing embeddings.
77
+ * Called on startup when embeddings are first enabled.
78
+ * Also handles config changes: if provider/model/dimensions changed, clears
79
+ * stale embeddings first, then re-embeds all entries.
80
+ * Returns the number of entries embedded.
81
+ */
82
+ export declare function backfillEmbeddings(): Promise<number>;
83
+ /**
84
+ * Embed all non-archived distillations that are missing embeddings.
85
+ * Called on startup alongside knowledge backfill.
86
+ * Returns the number of distillations embedded.
87
+ */
88
+ export declare function backfillDistillationEmbeddings(): Promise<number>;
89
+ export {};
90
+ //# sourceMappingURL=embedding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../../src/embedding.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IACjF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAoKD,0DAA0D;AAC1D,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAMD;;qEAEqE;AACrE,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAMD;;;;;;;GAOG;AACH,wBAAsB,KAAK,CACzB,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,UAAU,GAAG,OAAO,GAC9B,OAAO,CAAC,YAAY,EAAE,CAAC,CAIzB;AAMD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,CAazE;AAMD,8DAA8D;AAC9D,wBAAgB,MAAM,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEhD;AAED,oEAAoE;AACpE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAGhE;AAMD,KAAK,SAAS,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,YAAY,EAC5B,KAAK,SAAK,GACT,SAAS,EAAE,CAcb;AAMD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,cAAc,EAAE,YAAY,EAC5B,KAAK,SAAK,GACT,SAAS,EAAE,CAgBb;AAMD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GACd,IAAI,CAWN;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,GACnB,IAAI,CAUN;AAkBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAoC3C;AAMD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,CAuC1D;AAMD;;;;GAIG;AACH,wBAAsB,8BAA8B,IAAI,OAAO,CAAC,MAAM,CAAC,CAsCtE"}
@@ -0,0 +1,73 @@
1
+ import type { LoreMessageWithParts } from "./types";
2
+ type MessageWithParts = LoreMessageWithParts;
3
+ export declare function setModelLimits(limits: {
4
+ context: number;
5
+ output: number;
6
+ }): void;
7
+ /** Called by the system transform hook after formatting LTM knowledge. */
8
+ export declare function setLtmTokens(tokens: number): void;
9
+ /** Returns the current LTM token count (for tests and diagnostics). */
10
+ export declare function getLtmTokens(): number;
11
+ /**
12
+ * Returns the token budget available for LTM system-prompt injection.
13
+ * This is the usable context (after output + overhead) multiplied by
14
+ * the configured ltm budget fraction. Call this from the system transform
15
+ * hook to cap how many tokens formatKnowledge may use.
16
+ */
17
+ export declare function getLtmBudget(ltmFraction: number): number;
18
+ export declare function calibrate(actualInput: number, sessionID?: string, messageCount?: number): void;
19
+ export declare function getOverhead(): number;
20
+ /**
21
+ * Returns the number of messages in the most recent transform() output for
22
+ * the given session. Used by calibrate() to track the compressed window size.
23
+ */
24
+ export declare function getLastTransformedCount(sessionID: string): number;
25
+ /** Returns the token estimate from the most recent transform() output. */
26
+ export declare function getLastTransformEstimate(sessionID: string): number;
27
+ /** Returns the layer used by the most recent transform() call. For testing. */
28
+ export declare function getLastLayer(sessionID?: string): SafetyLayer;
29
+ /**
30
+ * Force the next transform() call for this session to use at least the given layer.
31
+ * Called when the API returns "prompt is too long" so the next attempt
32
+ * trims the context enough to fit within the model's context window.
33
+ */
34
+ export declare function setForceMinLayer(layer: SafetyLayer, sessionID?: string): void;
35
+ export declare function resetCalibration(sessionID?: string): void;
36
+ /**
37
+ * Replace duplicate tool outputs with compact back-references, keeping only
38
+ * the latest occurrence of each unique output. Reduces context token usage
39
+ * without information loss — the model sees the most recent content intact.
40
+ *
41
+ * Deduplicates by:
42
+ * 1. Exact content hash: identical tool outputs (same file read twice, same command output)
43
+ * 2. Same-file reads: read_file outputs for the same path (content may differ due to edits)
44
+ *
45
+ * The current turn (from currentTurnIdx onward) is never touched — the model
46
+ * needs full context for its active work. Tool parts are never removed entirely;
47
+ * only state.output is replaced with a compact annotation.
48
+ *
49
+ * Returns the original array reference (not a copy) when no duplicates exist.
50
+ */
51
+ export declare function deduplicateToolOutputs(messages: MessageWithParts[], currentTurnIdx: number): MessageWithParts[];
52
+ export declare function resetPrefixCache(sessionID?: string): void;
53
+ export declare function resetRawWindowCache(sessionID?: string): void;
54
+ export type SafetyLayer = 0 | 1 | 2 | 3 | 4;
55
+ export type TransformResult = {
56
+ messages: MessageWithParts[];
57
+ layer: SafetyLayer;
58
+ distilledTokens: number;
59
+ rawTokens: number;
60
+ totalTokens: number;
61
+ usable: number;
62
+ distilledBudget: number;
63
+ rawBudget: number;
64
+ };
65
+ export declare function needsUrgentDistillation(): boolean;
66
+ export declare function transform(input: {
67
+ messages: MessageWithParts[];
68
+ projectPath: string;
69
+ sessionID?: string;
70
+ }): TransformResult;
71
+ export declare function estimateMessages(messages: MessageWithParts[]): number;
72
+ export {};
73
+ //# sourceMappingURL=gradient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gradient.d.ts","sourceRoot":"","sources":["../../src/gradient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,oBAAoB,EAAqE,MAAM,SAAS,CAAC;AAO9I,KAAK,gBAAgB,GAAG,oBAAoB,CAAC;AAmH7C,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,QASzE;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,QAE1C;AAED,uEAAuE;AACvE,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAIxD;AAWD,wBAAgB,SAAS,CACvB,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,QA2BtB;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAK5D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,QAWtE;AAGD,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,QAWlD;AA0ID;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,cAAc,EAAE,MAAM,GACrB,gBAAgB,EAAE,CA0EpB;AA4YD,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,QAOlD;AA0BD,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,QAOrD;AAuFD,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,wBAAgB,uBAAuB,IAAI,OAAO,CAIjD;AAiPD,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAC/B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,eAAe,CAiBlB;AAGD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAErE"}
@@ -0,0 +1,19 @@
1
+ export * as temporal from "./temporal";
2
+ export * as ltm from "./ltm";
3
+ export * as distillation from "./distillation";
4
+ export * as curator from "./curator";
5
+ export * as embedding from "./embedding";
6
+ export * as latReader from "./lat-reader";
7
+ export * as log from "./log";
8
+ export { runRecall, RECALL_TOOL_DESCRIPTION, RECALL_PARAM_DESCRIPTIONS, type RecallInput, type RecallResult, type RecallScope, type ScoredDistillation, } from "./recall";
9
+ export type { LoreMessage, LoreUserMessage, LoreAssistantMessage, LorePart, LoreTextPart, LoreReasoningPart, LoreToolPart, LoreGenericPart, LoreToolState, LoreToolStatePending, LoreToolStateRunning, LoreToolStateCompleted, LoreToolStateError, LoreMessageWithParts, LLMClient, } from "./types";
10
+ export { isTextPart, isReasoningPart, isToolPart } from "./types";
11
+ export { load, config, type LoreConfig } from "./config";
12
+ export { db, ensureProject, isFirstRun, projectId, projectName, loadForceMinLayer, saveForceMinLayer, close, } from "./db";
13
+ export { transform, setModelLimits, needsUrgentDistillation, calibrate, setLtmTokens, getLtmTokens, getLtmBudget, setForceMinLayer, getLastTransformedCount, getLastTransformEstimate, } from "./gradient";
14
+ export { formatKnowledge, formatDistillations, DISTILLATION_SYSTEM, distillationUser, RECURSIVE_SYSTEM, recursiveUser, CURATOR_SYSTEM, curatorUser, CONSOLIDATION_SYSTEM, consolidationUser, QUERY_EXPANSION_SYSTEM, } from "./prompt";
15
+ export { shouldImport, importFromFile, exportToFile } from "./agents-file";
16
+ export { workerSessionIDs, isWorkerSession } from "./worker";
17
+ export { ftsQuery, ftsQueryOr, EMPTY_QUERY, reciprocalRankFusion, expandQuery, extractTopTerms, } from "./search";
18
+ export { serialize, inline, h, p, ul, lip, liph, t, root, strong, normalize, sanitizeSurrogates, unescapeMarkdown, } from "./markdown";
19
+ //# sourceMappingURL=index.d.ts.map