@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
package/src/types.ts ADDED
@@ -0,0 +1,199 @@
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
+
14
+ // ---------------------------------------------------------------------------
15
+ // Messages
16
+ // ---------------------------------------------------------------------------
17
+
18
+ export type LoreUserMessage = {
19
+ id: string;
20
+ sessionID: string;
21
+ role: "user";
22
+ time: { created: number };
23
+ /** Agent name (e.g. "build", "plan"). Host-specific; stored as metadata. */
24
+ agent: string;
25
+ /** Model used for this turn. Stored as metadata. */
26
+ model: { providerID: string; modelID: string };
27
+ };
28
+
29
+ export type LoreAssistantMessage = {
30
+ id: string;
31
+ sessionID: string;
32
+ role: "assistant";
33
+ time: { created: number };
34
+ parentID: string;
35
+ modelID: string;
36
+ providerID: string;
37
+ mode: string;
38
+ path: { cwd: string; root: string };
39
+ cost: number;
40
+ tokens: {
41
+ input: number;
42
+ output: number;
43
+ reasoning: number;
44
+ cache: { read: number; write: number };
45
+ };
46
+ };
47
+
48
+ /** Discriminated union on `.role`. */
49
+ export type LoreMessage = LoreUserMessage | LoreAssistantMessage;
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Parts
53
+ // ---------------------------------------------------------------------------
54
+
55
+ export type LoreTextPart = {
56
+ id: string;
57
+ sessionID: string;
58
+ messageID: string;
59
+ type: "text";
60
+ text: string;
61
+ /** Marks Lore-injected synthetic messages (e.g. distilled prefix). */
62
+ synthetic?: boolean;
63
+ /** Optional timing info — present on real messages, faked on synthetics. */
64
+ time?: { start: number; end?: number };
65
+ };
66
+
67
+ export type LoreReasoningPart = {
68
+ id: string;
69
+ sessionID: string;
70
+ messageID: string;
71
+ type: "reasoning";
72
+ text: string;
73
+ };
74
+
75
+ export type LoreToolStatePending = {
76
+ status: "pending";
77
+ input: unknown;
78
+ };
79
+
80
+ export type LoreToolStateRunning = {
81
+ status: "running";
82
+ input: unknown;
83
+ metadata?: unknown;
84
+ time: { start: number };
85
+ };
86
+
87
+ export type LoreToolStateCompleted = {
88
+ status: "completed";
89
+ input: unknown;
90
+ output: string;
91
+ metadata?: unknown;
92
+ time: { start: number; end: number };
93
+ };
94
+
95
+ export type LoreToolStateError = {
96
+ status: "error";
97
+ input: unknown;
98
+ error: string;
99
+ metadata?: unknown;
100
+ time: { start: number; end: number };
101
+ };
102
+
103
+ export type LoreToolState =
104
+ | LoreToolStatePending
105
+ | LoreToolStateRunning
106
+ | LoreToolStateCompleted
107
+ | LoreToolStateError;
108
+
109
+ export type LoreToolPart = {
110
+ id: string;
111
+ sessionID: string;
112
+ messageID: string;
113
+ type: "tool";
114
+ tool: string;
115
+ callID: string;
116
+ state: LoreToolState;
117
+ };
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
+ /**
132
+ * Passthrough for host-specific part types that Lore doesn't process.
133
+ * The `type` field is typed as `string` since Lore only cares that it's not
134
+ * one of the three known types.
135
+ */
136
+ export type LoreGenericPart = {
137
+ type: string;
138
+ [key: string]: unknown;
139
+ };
140
+
141
+ // Type guard helpers for narrowing LorePart in core logic.
142
+ export function isTextPart(p: LorePart): p is LoreTextPart {
143
+ return p.type === "text";
144
+ }
145
+ export function isReasoningPart(p: LorePart): p is LoreReasoningPart {
146
+ return p.type === "reasoning";
147
+ }
148
+ export function isToolPart(p: LorePart): p is LoreToolPart {
149
+ return p.type === "tool";
150
+ }
151
+
152
+ // ---------------------------------------------------------------------------
153
+ // Message with parts (the unit that hooks operate on)
154
+ // ---------------------------------------------------------------------------
155
+
156
+ export type LoreMessageWithParts = {
157
+ info: LoreMessage;
158
+ parts: LorePart[];
159
+ };
160
+
161
+ // ---------------------------------------------------------------------------
162
+ // LLM Client — the only host API Lore's background tasks need
163
+ // ---------------------------------------------------------------------------
164
+
165
+ /**
166
+ * Abstract interface for single-turn LLM prompt→response.
167
+ *
168
+ * All of Lore's background LLM work (distillation, curation, query expansion)
169
+ * is single-turn: one system+user message in, one text response out. No tool
170
+ * calling, no multi-turn. This interface captures that minimal surface.
171
+ *
172
+ * Host adapters implement this:
173
+ * - OpenCode: wraps `client.session.create()` + `client.session.prompt()`
174
+ * - Pi: wraps `complete()` from `@mariozechner/pi-ai`
175
+ * - Standalone: direct `fetch()` to provider APIs
176
+ */
177
+ export interface LLMClient {
178
+ /**
179
+ * Send a single prompt and return the text response.
180
+ *
181
+ * @param system System prompt text
182
+ * @param user User message text
183
+ * @param opts Optional model selection and worker identification
184
+ * @returns The assistant's text response, or null on failure
185
+ */
186
+ prompt(
187
+ system: string,
188
+ user: string,
189
+ opts?: {
190
+ /** Override model for this call. */
191
+ model?: { providerID: string; modelID: string };
192
+ /**
193
+ * Opaque worker identifier used by the host to route the request
194
+ * (e.g. OpenCode uses this as the session agent name).
195
+ */
196
+ workerID?: string;
197
+ },
198
+ ): Promise<string | null>;
199
+ }
package/src/worker.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Worker session tracking and the LLMClient contract.
3
+ *
4
+ * All lore background tasks (distillation, curation, query expansion) use
5
+ * the LLMClient interface for single-turn LLM calls. The actual prompting
6
+ * is implemented by the host adapter (OpenCode, Pi, etc.).
7
+ *
8
+ * This module owns the shared workerSessionIDs set — used by host adapters
9
+ * to skip storing/distilling worker session messages.
10
+ */
11
+ import type { LLMClient } from "./types";
12
+
13
+ // Re-export for convenience
14
+ export type { LLMClient } from "./types";
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Shared worker session tracking
18
+ // ---------------------------------------------------------------------------
19
+
20
+ /** Set of ALL worker session IDs across distillation, curator, and query expansion.
21
+ * Used by shouldSkip() in host adapters to avoid storing/distilling worker messages. */
22
+ export const workerSessionIDs = new Set<string>();
23
+
24
+ export function isWorkerSession(sessionID: string): boolean {
25
+ return workerSessionIDs.has(sessionID);
26
+ }