@chude/memory 4.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 (184) hide show
  1. package/README.md +294 -0
  2. package/dist/application/index.d.ts +6 -0
  3. package/dist/application/services/ambient-context-service.d.ts +90 -0
  4. package/dist/application/services/backfill-service.d.ts +71 -0
  5. package/dist/application/services/budget-allocator.d.ts +57 -0
  6. package/dist/application/services/embedding-service.d.ts +131 -0
  7. package/dist/application/services/export-service.d.ts +225 -0
  8. package/dist/application/services/extraction-pipeline.d.ts +50 -0
  9. package/dist/application/services/friction-service.d.ts +148 -0
  10. package/dist/application/services/fts-sanitizer.d.ts +25 -0
  11. package/dist/application/services/index.d.ts +34 -0
  12. package/dist/application/services/llm-extractor.d.ts +96 -0
  13. package/dist/application/services/memory-file-sync-service.d.ts +58 -0
  14. package/dist/application/services/pattern-extractor.d.ts +95 -0
  15. package/dist/application/services/recovery-service.d.ts +81 -0
  16. package/dist/application/services/rrf-fusion.d.ts +53 -0
  17. package/dist/application/services/smart-context-service.d.ts +126 -0
  18. package/dist/application/services/sync-service.d.ts +157 -0
  19. package/dist/application/services/temporal-decay.d.ts +62 -0
  20. package/dist/domain/entities/backfill-state.d.ts +56 -0
  21. package/dist/domain/entities/entity.d.ts +131 -0
  22. package/dist/domain/entities/extraction-state.d.ts +128 -0
  23. package/dist/domain/entities/fact.d.ts +59 -0
  24. package/dist/domain/entities/friction-entry.d.ts +84 -0
  25. package/dist/domain/entities/index.d.ts +15 -0
  26. package/dist/domain/entities/link.d.ts +74 -0
  27. package/dist/domain/entities/memory-file.d.ts +78 -0
  28. package/dist/domain/entities/message.d.ts +70 -0
  29. package/dist/domain/entities/session.d.ts +93 -0
  30. package/dist/domain/entities/tool-use.d.ts +85 -0
  31. package/dist/domain/errors/error-codes.d.ts +37 -0
  32. package/dist/domain/errors/index.d.ts +8 -0
  33. package/dist/domain/errors/memory-error.d.ts +52 -0
  34. package/dist/domain/errors/unknown-error.d.ts +9 -0
  35. package/dist/domain/index.d.ts +11 -0
  36. package/dist/domain/ports/embedding.d.ts +96 -0
  37. package/dist/domain/ports/extraction.d.ts +13 -0
  38. package/dist/domain/ports/index.d.ts +14 -0
  39. package/dist/domain/ports/redactor.d.ts +17 -0
  40. package/dist/domain/ports/repositories.d.ts +658 -0
  41. package/dist/domain/ports/services.d.ts +180 -0
  42. package/dist/domain/ports/signals.d.ts +82 -0
  43. package/dist/domain/ports/sources.d.ts +122 -0
  44. package/dist/domain/ports/types.d.ts +150 -0
  45. package/dist/domain/services/content-extractor.d.ts +61 -0
  46. package/dist/domain/services/index.d.ts +8 -0
  47. package/dist/domain/services/path-decoder.d.ts +56 -0
  48. package/dist/domain/services/query-parser.d.ts +47 -0
  49. package/dist/domain/value-objects/embedding-config.d.ts +56 -0
  50. package/dist/domain/value-objects/embedding-result.d.ts +46 -0
  51. package/dist/domain/value-objects/index.d.ts +10 -0
  52. package/dist/domain/value-objects/project-path.d.ts +92 -0
  53. package/dist/domain/value-objects/search-query.d.ts +30 -0
  54. package/dist/domain/value-objects/search-result.d.ts +92 -0
  55. package/dist/index.d.ts +15 -0
  56. package/dist/index.js +1548 -0
  57. package/dist/infrastructure/database/connection.d.ts +161 -0
  58. package/dist/infrastructure/database/event-log.d.ts +22 -0
  59. package/dist/infrastructure/database/health-checker.d.ts +248 -0
  60. package/dist/infrastructure/database/index.d.ts +11 -0
  61. package/dist/infrastructure/database/repositories/backfill-state-repository.d.ts +19 -0
  62. package/dist/infrastructure/database/repositories/embedding-repository.d.ts +121 -0
  63. package/dist/infrastructure/database/repositories/entity-repository.d.ts +73 -0
  64. package/dist/infrastructure/database/repositories/extraction-log-repository.d.ts +17 -0
  65. package/dist/infrastructure/database/repositories/extraction-state-repository.d.ts +52 -0
  66. package/dist/infrastructure/database/repositories/fact-repository.d.ts +25 -0
  67. package/dist/infrastructure/database/repositories/friction-repository.d.ts +41 -0
  68. package/dist/infrastructure/database/repositories/index.d.ts +17 -0
  69. package/dist/infrastructure/database/repositories/link-repository.d.ts +64 -0
  70. package/dist/infrastructure/database/repositories/memory-file-repository.d.ts +28 -0
  71. package/dist/infrastructure/database/repositories/message-repository.d.ts +87 -0
  72. package/dist/infrastructure/database/repositories/session-repository.d.ts +125 -0
  73. package/dist/infrastructure/database/repositories/tool-use-repository.d.ts +72 -0
  74. package/dist/infrastructure/database/schema.d.ts +203 -0
  75. package/dist/infrastructure/database/services/context-service.d.ts +93 -0
  76. package/dist/infrastructure/database/services/hybrid-search-service.d.ts +156 -0
  77. package/dist/infrastructure/database/services/index.d.ts +10 -0
  78. package/dist/infrastructure/database/services/search-service.d.ts +57 -0
  79. package/dist/infrastructure/database/services/stats-service.d.ts +36 -0
  80. package/dist/infrastructure/embedding/background-embedder.d.ts +125 -0
  81. package/dist/infrastructure/embedding/embedding-provider-factory.d.ts +44 -0
  82. package/dist/infrastructure/embedding/index.d.ts +5 -0
  83. package/dist/infrastructure/embedding/ollama-provider.d.ts +41 -0
  84. package/dist/infrastructure/embedding/openai-provider.d.ts +38 -0
  85. package/dist/infrastructure/embedding/transformers-js-provider.d.ts +34 -0
  86. package/dist/infrastructure/external/index.d.ts +7 -0
  87. package/dist/infrastructure/external/qmd-runner.d.ts +36 -0
  88. package/dist/infrastructure/hooks/auto-memory-writer.d.ts +52 -0
  89. package/dist/infrastructure/hooks/config-manager.d.ts +237 -0
  90. package/dist/infrastructure/hooks/git-syncer.d.ts +44 -0
  91. package/dist/infrastructure/hooks/hook-runner.d.ts +126 -0
  92. package/dist/infrastructure/hooks/index.d.ts +12 -0
  93. package/dist/infrastructure/hooks/log-writer.d.ts +106 -0
  94. package/dist/infrastructure/hooks/settings-manager.d.ts +163 -0
  95. package/dist/infrastructure/hooks/sync-hook-script.d.ts +83 -0
  96. package/dist/infrastructure/hooks/sync-logger-adapter.d.ts +17 -0
  97. package/dist/infrastructure/index.d.ts +11 -0
  98. package/dist/infrastructure/llm/anthropic-extractor.d.ts +20 -0
  99. package/dist/infrastructure/llm/claude-cli-extractor.d.ts +14 -0
  100. package/dist/infrastructure/llm/claude-summary-generator.d.ts +14 -0
  101. package/dist/infrastructure/llm/extraction-helper.d.ts +16 -0
  102. package/dist/infrastructure/llm/ollama-extractor.d.ts +20 -0
  103. package/dist/infrastructure/llm/openai-extractor.d.ts +23 -0
  104. package/dist/infrastructure/migration.d.ts +103 -0
  105. package/dist/infrastructure/parsers/event-classifier.d.ts +111 -0
  106. package/dist/infrastructure/parsers/index.d.ts +8 -0
  107. package/dist/infrastructure/parsers/jsonl-parser.d.ts +25 -0
  108. package/dist/infrastructure/parsers/timestamp.d.ts +18 -0
  109. package/dist/infrastructure/paths.d.ts +129 -0
  110. package/dist/infrastructure/providers/provider-defaults.d.ts +11 -0
  111. package/dist/infrastructure/providers/provider-registry.d.ts +28 -0
  112. package/dist/infrastructure/security/pattern-redactor.d.ts +6 -0
  113. package/dist/infrastructure/signals/adapters.d.ts +27 -0
  114. package/dist/infrastructure/signals/checkpoint-manager.d.ts +83 -0
  115. package/dist/infrastructure/signals/index.d.ts +8 -0
  116. package/dist/infrastructure/signals/signal-handler.d.ts +113 -0
  117. package/dist/infrastructure/sources/index.d.ts +8 -0
  118. package/dist/infrastructure/sources/memory-file-scanner.d.ts +23 -0
  119. package/dist/infrastructure/sources/project-name-resolver.d.ts +67 -0
  120. package/dist/infrastructure/sources/session-source.d.ts +70 -0
  121. package/dist/presentation/cli/command-result.d.ts +10 -0
  122. package/dist/presentation/cli/commands/_helpers/capture-json.d.ts +36 -0
  123. package/dist/presentation/cli/commands/_helpers/deprecation-warning.d.ts +41 -0
  124. package/dist/presentation/cli/commands/backfill.d.ts +56 -0
  125. package/dist/presentation/cli/commands/browse.d.ts +55 -0
  126. package/dist/presentation/cli/commands/completion.d.ts +61 -0
  127. package/dist/presentation/cli/commands/context.d.ts +53 -0
  128. package/dist/presentation/cli/commands/doctor.d.ts +55 -0
  129. package/dist/presentation/cli/commands/export.d.ts +36 -0
  130. package/dist/presentation/cli/commands/extract.d.ts +40 -0
  131. package/dist/presentation/cli/commands/facts.d.ts +17 -0
  132. package/dist/presentation/cli/commands/friction/dashboard.d.ts +18 -0
  133. package/dist/presentation/cli/commands/friction/index.d.ts +12 -0
  134. package/dist/presentation/cli/commands/friction/list.d.ts +12 -0
  135. package/dist/presentation/cli/commands/friction/log.d.ts +12 -0
  136. package/dist/presentation/cli/commands/friction/purge.d.ts +12 -0
  137. package/dist/presentation/cli/commands/friction/resolve.d.ts +12 -0
  138. package/dist/presentation/cli/commands/friction/types.d.ts +86 -0
  139. package/dist/presentation/cli/commands/friction/wontfix.d.ts +12 -0
  140. package/dist/presentation/cli/commands/import.d.ts +38 -0
  141. package/dist/presentation/cli/commands/index.d.ts +51 -0
  142. package/dist/presentation/cli/commands/install.d.ts +67 -0
  143. package/dist/presentation/cli/commands/list.d.ts +61 -0
  144. package/dist/presentation/cli/commands/migrate.d.ts +36 -0
  145. package/dist/presentation/cli/commands/purge.d.ts +100 -0
  146. package/dist/presentation/cli/commands/query.d.ts +51 -0
  147. package/dist/presentation/cli/commands/related.d.ts +47 -0
  148. package/dist/presentation/cli/commands/remote.d.ts +36 -0
  149. package/dist/presentation/cli/commands/search.d.ts +100 -0
  150. package/dist/presentation/cli/commands/show.d.ts +51 -0
  151. package/dist/presentation/cli/commands/stats.d.ts +38 -0
  152. package/dist/presentation/cli/commands/status.d.ts +152 -0
  153. package/dist/presentation/cli/commands/sync/ambient.d.ts +22 -0
  154. package/dist/presentation/cli/commands/sync/background.d.ts +23 -0
  155. package/dist/presentation/cli/commands/sync/embedding-pass.d.ts +32 -0
  156. package/dist/presentation/cli/commands/sync/helpers.d.ts +25 -0
  157. package/dist/presentation/cli/commands/sync/index.d.ts +17 -0
  158. package/dist/presentation/cli/commands/sync/memory-files.d.ts +26 -0
  159. package/dist/presentation/cli/commands/sync/types.d.ts +163 -0
  160. package/dist/presentation/cli/commands/uninstall.d.ts +44 -0
  161. package/dist/presentation/cli/db-startup.d.ts +61 -0
  162. package/dist/presentation/cli/formatters/ai-formatter.d.ts +38 -0
  163. package/dist/presentation/cli/formatters/color.d.ts +82 -0
  164. package/dist/presentation/cli/formatters/context-formatter.d.ts +55 -0
  165. package/dist/presentation/cli/formatters/dto-helpers.d.ts +176 -0
  166. package/dist/presentation/cli/formatters/envelope.d.ts +136 -0
  167. package/dist/presentation/cli/formatters/error-formatter.d.ts +41 -0
  168. package/dist/presentation/cli/formatters/friction-dashboard.d.ts +46 -0
  169. package/dist/presentation/cli/formatters/index.d.ts +17 -0
  170. package/dist/presentation/cli/formatters/list-formatter.d.ts +48 -0
  171. package/dist/presentation/cli/formatters/output-formatter.d.ts +98 -0
  172. package/dist/presentation/cli/formatters/related-formatter.d.ts +57 -0
  173. package/dist/presentation/cli/formatters/show-formatter.d.ts +63 -0
  174. package/dist/presentation/cli/formatters/stats-formatter.d.ts +54 -0
  175. package/dist/presentation/cli/formatters/text-width.d.ts +37 -0
  176. package/dist/presentation/cli/formatters/timestamp-formatter.d.ts +38 -0
  177. package/dist/presentation/cli/index.d.ts +10 -0
  178. package/dist/presentation/cli/index.js +1664 -0
  179. package/dist/presentation/cli/parsers/date-parser.d.ts +28 -0
  180. package/dist/presentation/cli/parsers/index.d.ts +6 -0
  181. package/dist/presentation/cli/pickers/index.d.ts +6 -0
  182. package/dist/presentation/cli/pickers/session-picker.d.ts +59 -0
  183. package/dist/presentation/cli/progress-reporter.d.ts +199 -0
  184. package/package.json +94 -0
@@ -0,0 +1,658 @@
1
+ /**
2
+ * Repository Port Interfaces
3
+ *
4
+ * Defines contracts for persistence operations. These interfaces are
5
+ * implemented by infrastructure adapters (e.g., SQLite repositories).
6
+ *
7
+ * Design principles:
8
+ * - All methods return Promises for async compatibility
9
+ * - Use domain entities exclusively (no SQL or infrastructure types)
10
+ * - Methods are minimal and focused on specific use cases
11
+ */
12
+ import type { Session } from "../entities/session.js";
13
+ import type { Message } from "../entities/message.js";
14
+ import type { ToolUse } from "../entities/tool-use.js";
15
+ import type { Link, EntityType } from "../entities/link.js";
16
+ import type { ExtractionState } from "../entities/extraction-state.js";
17
+ import type { Entity, ExtractedEntityType } from "../entities/entity.js";
18
+ import type { MemoryFile, MemoryFileType } from "../entities/memory-file.js";
19
+ import type { FrictionEntry, FrictionSeverity, FrictionStatus } from "../entities/friction-entry.js";
20
+ import type { BackfillState } from "../entities/backfill-state.js";
21
+ import type { ProjectPath } from "../value-objects/project-path.js";
22
+ import type { Fact } from "../entities/fact.js";
23
+ /**
24
+ * Options for filtering session list.
25
+ */
26
+ export interface SessionListOptions {
27
+ /** Maximum sessions to return */
28
+ limit?: number | undefined;
29
+ /** Filter by project name (substring match) */
30
+ projectFilter?: string | undefined;
31
+ /** Only sessions after this date */
32
+ sinceDate?: Date | undefined;
33
+ /** Only sessions before this date */
34
+ beforeDate?: Date | undefined;
35
+ }
36
+ /**
37
+ * Repository for Session entities.
38
+ *
39
+ * Handles persistence of Claude Code sessions and their metadata.
40
+ * Sessions are identified by their unique session ID.
41
+ */
42
+ export interface ISessionRepository {
43
+ /**
44
+ * Find a session by its unique identifier.
45
+ * @param id The session UUID
46
+ * @returns The session if found, null otherwise
47
+ */
48
+ findById(id: string): Promise<Session | null>;
49
+ /**
50
+ * Find all sessions belonging to a project.
51
+ * @param projectPath The project path to filter by
52
+ * @returns Array of sessions for the project
53
+ */
54
+ findByProject(projectPath: ProjectPath): Promise<Session[]>;
55
+ /**
56
+ * Find the most recent sessions across all projects.
57
+ * @param limit Maximum number of sessions to return
58
+ * @returns Array of sessions, ordered by start time descending
59
+ */
60
+ findRecent(limit: number): Promise<Session[]>;
61
+ /**
62
+ * Save a session to the repository.
63
+ * Creates or updates based on session ID.
64
+ * @param session The session to save
65
+ */
66
+ save(session: Session): Promise<void>;
67
+ /**
68
+ * Save multiple sessions in a single transaction.
69
+ * More efficient than individual saves for bulk operations.
70
+ * @param sessions Array of sessions to save
71
+ */
72
+ saveMany(sessions: Session[]): Promise<void>;
73
+ /**
74
+ * Delete a session by its identifier.
75
+ * Also removes associated messages (cascade).
76
+ * @param id The session UUID to delete
77
+ */
78
+ delete(id: string): Promise<void>;
79
+ /**
80
+ * Find sessions with filtering options.
81
+ * Builds dynamic WHERE clause based on provided filters.
82
+ * @param options Filtering options (limit, project, date range)
83
+ * @returns Array of sessions matching filters, ordered by start time descending
84
+ */
85
+ findFiltered(options: SessionListOptions): Promise<Session[]>;
86
+ /**
87
+ * Update the project name for all sessions with a matching encoded path.
88
+ * Used to fix lossy project names resolved via filesystem lookup.
89
+ * @param encodedPath The encoded project path to match
90
+ * @param projectName The correct project name
91
+ * @returns Number of rows updated
92
+ */
93
+ updateProjectName(encodedPath: string, projectName: string): Promise<number>;
94
+ /**
95
+ * Find all distinct encoded project paths stored in sessions.
96
+ * Used by fixProjectNames to enumerate paths needing resolution.
97
+ * @returns Array of distinct encoded path strings
98
+ */
99
+ findDistinctEncodedPaths(): Promise<string[]>;
100
+ }
101
+ /**
102
+ * Repository for Message entities.
103
+ *
104
+ * Handles persistence of individual messages within sessions.
105
+ * Messages are always associated with a parent session.
106
+ */
107
+ export interface IMessageRepository {
108
+ /**
109
+ * Find a message by its unique identifier.
110
+ * @param id The message UUID
111
+ * @returns The message if found, null otherwise
112
+ */
113
+ findById(id: string): Promise<Message | null>;
114
+ /**
115
+ * Find all messages belonging to a session.
116
+ * @param sessionId The parent session UUID
117
+ * @returns Array of messages, ordered by timestamp ascending
118
+ */
119
+ findBySession(sessionId: string): Promise<Message[]>;
120
+ /**
121
+ * Save a message associated with a session.
122
+ * @param message The message to save
123
+ * @param sessionId The parent session UUID
124
+ */
125
+ save(message: Message, sessionId: string): Promise<void>;
126
+ /**
127
+ * Save multiple messages in a single transaction.
128
+ * More efficient than individual saves for bulk operations.
129
+ * @param messages Array of message/sessionId pairs to save
130
+ */
131
+ saveMany(messages: Array<{
132
+ message: Message;
133
+ sessionId: string;
134
+ }>): Promise<any>;
135
+ }
136
+ /**
137
+ * Repository for ToolUse entities.
138
+ *
139
+ * Handles persistence of tool invocations within sessions.
140
+ * Tool uses track what tools were called and their results.
141
+ */
142
+ export interface IToolUseRepository {
143
+ /**
144
+ * Find a tool use by its unique identifier.
145
+ * @param id The tool use UUID
146
+ * @returns The tool use if found, null otherwise
147
+ */
148
+ findById(id: string): Promise<ToolUse | null>;
149
+ /**
150
+ * Find all tool uses belonging to a session.
151
+ * @param sessionId The parent session UUID
152
+ * @returns Array of tool uses, ordered by timestamp ascending
153
+ */
154
+ findBySession(sessionId: string): Promise<ToolUse[]>;
155
+ /**
156
+ * Save a tool use associated with a session.
157
+ * @param toolUse The tool use to save
158
+ * @param sessionId The parent session UUID
159
+ */
160
+ save(toolUse: ToolUse, sessionId: string): Promise<void>;
161
+ /**
162
+ * Save multiple tool uses in a single transaction.
163
+ * More efficient than individual saves for bulk operations.
164
+ * @param toolUses Array of toolUse/sessionId pairs to save
165
+ */
166
+ saveMany(toolUses: Array<{
167
+ toolUse: ToolUse;
168
+ sessionId: string;
169
+ }>): Promise<any>;
170
+ }
171
+ /**
172
+ * Repository for Link entities.
173
+ *
174
+ * Handles persistence of relationships between entities for
175
+ * graph-like traversal. Enables cross-session navigation.
176
+ */
177
+ export interface ILinkRepository {
178
+ /**
179
+ * Find all links originating from a specific entity.
180
+ * @param sourceType The type of the source entity
181
+ * @param sourceId The ID of the source entity
182
+ * @returns Array of links from this source
183
+ */
184
+ findBySource(sourceType: EntityType, sourceId: string): Promise<Link[]>;
185
+ /**
186
+ * Find all links pointing to a specific entity.
187
+ * @param targetType The type of the target entity
188
+ * @param targetId The ID of the target entity
189
+ * @returns Array of links to this target
190
+ */
191
+ findByTarget(targetType: EntityType, targetId: string): Promise<Link[]>;
192
+ /**
193
+ * Find all entities related to a given entity within N hops.
194
+ * Enables graph traversal for discovering related content.
195
+ * @param entityType The type of the starting entity
196
+ * @param entityId The ID of the starting entity
197
+ * @param maxHops Maximum depth to traverse (default: 2)
198
+ * @returns Array of links representing the relationship graph
199
+ */
200
+ findRelated(entityType: EntityType, entityId: string, maxHops?: number): Promise<Link[]>;
201
+ /**
202
+ * Save a link to the repository.
203
+ * @param link The link to save
204
+ */
205
+ save(link: Link): Promise<void>;
206
+ /**
207
+ * Save multiple links in a single transaction.
208
+ * More efficient than individual saves for bulk operations.
209
+ * @param links Array of links to save
210
+ */
211
+ saveMany(links: Link[]): Promise<void>;
212
+ }
213
+ /**
214
+ * Repository for ExtractionState entities.
215
+ *
216
+ * Tracks the state of extracting sessions from JSONL files.
217
+ * Enables incremental sync and progress tracking.
218
+ */
219
+ export interface IExtractionStateRepository {
220
+ /**
221
+ * Find an extraction state by its unique identifier.
222
+ * @param id The extraction state UUID
223
+ * @returns The state if found, null otherwise
224
+ */
225
+ findById(id: string): Promise<ExtractionState | null>;
226
+ /**
227
+ * Find extraction state by session path.
228
+ * Used to check if a session has already been extracted.
229
+ * @param sessionPath The path to the session JSONL file
230
+ * @returns The state if found, null otherwise
231
+ */
232
+ findBySessionPath(sessionPath: string): Promise<ExtractionState | null>;
233
+ /**
234
+ * Find all extractions that are pending or in progress.
235
+ * Used to resume interrupted extractions.
236
+ * @returns Array of pending/in-progress extraction states
237
+ */
238
+ findPending(): Promise<ExtractionState[]>;
239
+ /**
240
+ * Save an extraction state to the repository.
241
+ * @param state The extraction state to save
242
+ */
243
+ save(state: ExtractionState): Promise<void>;
244
+ }
245
+ /**
246
+ * Options for filtering entity list.
247
+ */
248
+ export interface EntityListOptions {
249
+ /** Maximum entities to return */
250
+ limit?: number;
251
+ /** Minimum confidence threshold (0-1) */
252
+ minConfidence?: number;
253
+ }
254
+ /**
255
+ * Repository for Entity domain objects.
256
+ *
257
+ * Handles persistence of extracted concepts, files, decisions, and terms.
258
+ * Entities are linked to sessions and can have relationships with other entities.
259
+ */
260
+ export interface IEntityRepository {
261
+ /**
262
+ * Find an entity by its unique database identifier.
263
+ * @param id The entity database ID
264
+ * @returns The entity if found, null otherwise
265
+ */
266
+ findById(id: number): Promise<Entity | null>;
267
+ /**
268
+ * Find an entity by its type and name (unique constraint).
269
+ * @param type The entity type (concept, file, decision, term)
270
+ * @param name The entity name
271
+ * @returns The entity if found, null otherwise
272
+ */
273
+ findByName(type: ExtractedEntityType, name: string): Promise<Entity | null>;
274
+ /**
275
+ * Find all entities linked to a specific session.
276
+ * @param sessionId The session UUID
277
+ * @returns Array of entities for the session
278
+ */
279
+ findBySession(sessionId: string): Promise<Entity[]>;
280
+ /**
281
+ * Find entities of a specific type with optional filtering.
282
+ * @param type The entity type to filter by
283
+ * @param options Optional filtering (limit, minConfidence)
284
+ * @returns Array of entities matching the criteria
285
+ */
286
+ findByType(type: ExtractedEntityType, options?: EntityListOptions): Promise<Entity[]>;
287
+ /**
288
+ * Save an entity to the repository.
289
+ * Creates or updates based on type+name uniqueness.
290
+ * @param entity The entity to save
291
+ * @returns The entity with id assigned
292
+ */
293
+ save(entity: Entity): Promise<Entity>;
294
+ /**
295
+ * Save multiple entities in a single transaction.
296
+ * More efficient than individual saves for bulk operations.
297
+ * @param entities Array of entities to save
298
+ * @returns Array of entities with ids assigned
299
+ */
300
+ saveMany(entities: Entity[]): Promise<Entity[]>;
301
+ /**
302
+ * Create a link between an entity and a session.
303
+ * Tracks how often an entity appears in a session.
304
+ * @param entityId The entity database ID
305
+ * @param sessionId The session UUID
306
+ * @param frequency Optional occurrence count (default: 1)
307
+ */
308
+ linkToSession(entityId: number, sessionId: string, frequency?: number): Promise<void>;
309
+ /**
310
+ * Create a relationship link between two entities.
311
+ * Enables graph traversal for related concepts.
312
+ * @param sourceId The source entity database ID
313
+ * @param targetId The target entity database ID
314
+ * @param relationship The relationship type (related, implies, contradicts)
315
+ * @param weight Optional relationship strength (0-1, default: 1.0)
316
+ */
317
+ linkEntities(sourceId: number, targetId: number, relationship: "related" | "implies" | "contradicts", weight?: number): Promise<void>;
318
+ }
319
+ /**
320
+ * A message that has not yet been embedded.
321
+ *
322
+ * Represents a row from messages_meta that has no corresponding
323
+ * entry in embedding_state. Used by the embedding pipeline to
324
+ * identify messages needing vector generation.
325
+ */
326
+ export interface UnembeddedMessage {
327
+ /** The integer rowid from messages_meta (NOT the UUID id) */
328
+ rowid: number;
329
+ /** The message content text to embed */
330
+ content: string;
331
+ }
332
+ /**
333
+ * A single item in an embedding batch for storage.
334
+ *
335
+ * Pairs a message rowid with its computed embedding vector.
336
+ * Used by storeBatch to write both the vec0 table and
337
+ * the embedding_state tracking table atomically.
338
+ */
339
+ export interface EmbeddingBatchItem {
340
+ /** The integer rowid matching messages_meta.rowid */
341
+ rowid: number;
342
+ /** The embedding vector */
343
+ embedding: Float32Array;
344
+ }
345
+ /**
346
+ * Domain-layer configuration contract for the embedding service.
347
+ *
348
+ * Contains only the fields that EmbeddingService needs to operate.
349
+ * Infrastructure's EmbeddingConfigData structurally satisfies this
350
+ * interface (it has all 4 fields plus additional ones like enabled,
351
+ * apiKey, baseUrl that the application layer does not need).
352
+ */
353
+ export interface EmbeddingServiceConfig {
354
+ /** Embedding provider name (e.g., "local", "openai", "ollama") */
355
+ provider: string;
356
+ /** Model identifier (e.g., "Xenova/all-MiniLM-L6-v2") */
357
+ model: string;
358
+ /** Vector dimensions produced by the model */
359
+ dimensions: number;
360
+ /** Number of messages to process per batch */
361
+ batchSize: number;
362
+ }
363
+ /**
364
+ * Repository port for embedding data access.
365
+ *
366
+ * Defines the contract for querying unembedded messages, storing
367
+ * embedding results, tracking model hashes for change detection,
368
+ * and managing the embedding lifecycle (clear and re-embed).
369
+ *
370
+ * All methods are synchronous, matching bun:sqlite's synchronous API.
371
+ * Implemented by infrastructure's EmbeddingRepository.
372
+ *
373
+ * Note: Infrastructure-only methods (vectorKnnSearch, getStoredEmbeddingDimensions,
374
+ * recreateVecTable) are intentionally excluded per ISP -- they are used by
375
+ * HybridSearchService and sync commands, not by the application-layer
376
+ * EmbeddingService.
377
+ */
378
+ export interface IEmbeddingRepository {
379
+ /**
380
+ * Find messages that have not yet been embedded.
381
+ * @param limit Maximum number of messages to return
382
+ * @returns Array of unembedded messages ordered by rowid ASC
383
+ */
384
+ findUnembedded(limit: number): UnembeddedMessage[];
385
+ /**
386
+ * Store a batch of embeddings in a single transaction.
387
+ * @param items Array of embedding batch items (rowid + vector)
388
+ * @param modelHash Hash identifying the model configuration
389
+ * @param modelName Human-readable model name
390
+ */
391
+ storeBatch(items: EmbeddingBatchItem[], modelHash: string, modelName: string): void;
392
+ /**
393
+ * Get the model hash currently stored in embedding_state.
394
+ * @returns The model hash string, or null if no embeddings exist
395
+ */
396
+ getStoredModelHash(): string | null;
397
+ /**
398
+ * Get the human-readable model name stored in embedding_state.
399
+ * @returns The model name string, or null if unavailable
400
+ */
401
+ getStoredModelName(): string | null;
402
+ /**
403
+ * Delete all embeddings and embedding state.
404
+ * Used before re-embedding when the model has changed.
405
+ */
406
+ clearAllEmbeddings(): void;
407
+ /**
408
+ * Count the number of embedded messages.
409
+ * @returns The number of rows in embedding_state
410
+ */
411
+ getEmbeddedCount(): number;
412
+ /**
413
+ * Count the total number of messages in the database.
414
+ * @returns The number of rows in messages_meta
415
+ */
416
+ getTotalMessageCount(): number;
417
+ }
418
+ /**
419
+ * Repository for MemoryFile entities.
420
+ *
421
+ * Handles persistence of indexed legacy memory files.
422
+ * Files are identified by their path relative to the memory directory.
423
+ */
424
+ export interface IMemoryFileRepository {
425
+ /**
426
+ * Find a memory file by its relative path.
427
+ * @param filePath Path relative to the legacy memory-file root
428
+ * @returns The memory file if found, null otherwise
429
+ */
430
+ findByPath(filePath: string): Promise<MemoryFile | null>;
431
+ /**
432
+ * Find all memory files of a specific type.
433
+ * @param fileType The type to filter by
434
+ * @returns Array of matching memory files
435
+ */
436
+ findByType(fileType: MemoryFileType): Promise<MemoryFile[]>;
437
+ /**
438
+ * Find all memory files belonging to a specific project.
439
+ * @param projectEncoded The encoded project path
440
+ * @returns Array of memory files for the project
441
+ */
442
+ findByProject(projectEncoded: string): Promise<MemoryFile[]>;
443
+ /**
444
+ * Save a memory file (insert or update by file_path).
445
+ * @param file The memory file to save
446
+ */
447
+ save(file: MemoryFile): Promise<void>;
448
+ /**
449
+ * Save multiple memory files in a single transaction.
450
+ * @param files Array of memory files to save
451
+ */
452
+ saveMany(files: MemoryFile[]): Promise<void>;
453
+ /**
454
+ * Full-text search across memory file content.
455
+ * @param query The search query (already sanitized for FTS5)
456
+ * @param limit Maximum results (default: 20)
457
+ * @returns Array of matching memory files
458
+ */
459
+ searchContent(query: string, limit?: number): Promise<MemoryFile[]>;
460
+ /**
461
+ * Find learnings files tagged for cross-project sharing.
462
+ * Searches for content containing "Applies to: cross-project".
463
+ * @param excludeProject Optional encoded project path to exclude from results
464
+ * @param limit Maximum results (default: 20)
465
+ * @returns Array of matching learnings memory files
466
+ */
467
+ findCrossProjectLearnings(excludeProject?: string, limit?: number): Promise<MemoryFile[]>;
468
+ }
469
+ /**
470
+ * Aggregated statistics for friction entries.
471
+ */
472
+ export interface FrictionStats {
473
+ total: number;
474
+ open: number;
475
+ resolved: number;
476
+ wontFix: number;
477
+ bySeverity: Record<FrictionSeverity, number>;
478
+ byCategory: Record<string, number>;
479
+ byTool: Record<string, number>;
480
+ meanTimeToResolve: number | null;
481
+ oldestOpen: {
482
+ id: number;
483
+ description: string;
484
+ daysOpen: number;
485
+ } | null;
486
+ }
487
+ /**
488
+ * A recurring friction pattern grouped by tool and category.
489
+ */
490
+ export interface FrictionPattern {
491
+ tool: string;
492
+ category: string;
493
+ count: number;
494
+ entries: FrictionEntry[];
495
+ }
496
+ /**
497
+ * Repository for FrictionEntry entities.
498
+ *
499
+ * Handles persistence of friction log entries and provides
500
+ * aggregation queries for stats and trend analysis.
501
+ */
502
+ export interface IFrictionRepository {
503
+ /**
504
+ * Save a friction entry to the repository.
505
+ * @param entry The entry to save
506
+ * @returns The entry with id assigned
507
+ */
508
+ save(entry: FrictionEntry): Promise<FrictionEntry>;
509
+ /**
510
+ * Find a friction entry by its database ID.
511
+ * @param id The entry database ID
512
+ * @returns The entry if found, null otherwise
513
+ */
514
+ findById(id: number): Promise<FrictionEntry | null>;
515
+ /**
516
+ * Find all open friction entries.
517
+ * @returns Array of open entries, ordered by logged_at descending
518
+ */
519
+ findOpen(): Promise<FrictionEntry[]>;
520
+ /**
521
+ * Find friction entries with optional filtering.
522
+ * @param options Filtering options (status, category, limit)
523
+ * @returns Array of matching entries, ordered by logged_at descending
524
+ */
525
+ findAll(options?: {
526
+ status?: FrictionStatus;
527
+ category?: string;
528
+ tool?: string;
529
+ sourceProject?: string;
530
+ limit?: number;
531
+ }): Promise<FrictionEntry[]>;
532
+ /**
533
+ * Resolve a friction entry with a resolution description.
534
+ * @param id The entry database ID
535
+ * @param resolution How the friction was resolved
536
+ * @throws Error if entry not found
537
+ */
538
+ resolve(id: number, resolution: string): Promise<void>;
539
+ /**
540
+ * Update the status of a friction entry.
541
+ * @param id The entry database ID
542
+ * @param status The new status
543
+ * @throws Error if entry not found
544
+ */
545
+ updateStatus(id: number, status: FrictionStatus): Promise<void>;
546
+ /**
547
+ * Get aggregated statistics for all friction entries.
548
+ * @returns FrictionStats with counts, breakdowns, MTTR, oldest open
549
+ */
550
+ getStats(): Promise<FrictionStats>;
551
+ /**
552
+ * Get weekly trend data for friction entries.
553
+ * @param weeks Number of weeks to include
554
+ * @returns Array of weekly counts, zero-filled for inactive weeks
555
+ */
556
+ getWeeklyTrends(weeks: number): Promise<Array<{
557
+ week: string;
558
+ newCount: number;
559
+ resolvedCount: number;
560
+ }>>;
561
+ /**
562
+ * Mark all entries for a tool as reviewed at a given date.
563
+ * @param tool The tool name
564
+ * @param reviewedAt The review date
565
+ */
566
+ markReviewed(tool: string, reviewedAt: Date): Promise<void>;
567
+ /**
568
+ * Find recurring friction patterns above a threshold count.
569
+ * @param threshold Minimum entry count to qualify as a pattern
570
+ * @returns Array of patterns grouped by tool and category
571
+ */
572
+ findPatterns(threshold: number): Promise<FrictionPattern[]>;
573
+ /**
574
+ * Delete friction entries whose description matches a pattern.
575
+ * Uses SQL LIKE matching (% for wildcard).
576
+ * @param pattern Description pattern to match
577
+ * @returns Number of entries deleted
578
+ */
579
+ deleteByPattern(pattern: string): Promise<number>;
580
+ }
581
+ /**
582
+ * Count of backfill states by success/failure status.
583
+ */
584
+ export interface BackfillStatusCounts {
585
+ total: number;
586
+ succeeded: number;
587
+ failed: number;
588
+ }
589
+ /**
590
+ * Repository for BackfillState entities.
591
+ *
592
+ * Tracks which sessions have been backfilled (daily log generated).
593
+ * Enables idempotent backfill: processed sessions are skipped on re-run.
594
+ */
595
+ export interface IBackfillStateRepository {
596
+ /**
597
+ * Find backfill state for a specific session.
598
+ * @param sessionId The session UUID
599
+ * @returns The backfill state if found, null otherwise
600
+ */
601
+ findBySessionId(sessionId: string): Promise<BackfillState | null>;
602
+ /**
603
+ * Find all backfill states.
604
+ * @returns Array of all backfill state records
605
+ */
606
+ findAll(): Promise<BackfillState[]>;
607
+ /**
608
+ * Save a backfill state record (insert or update by session_id).
609
+ * @param state The backfill state to save
610
+ */
611
+ save(state: BackfillState): Promise<void>;
612
+ /**
613
+ * Count backfill states by success/failure status.
614
+ * @returns Counts of total, succeeded, and failed backfills
615
+ */
616
+ countByStatus(): Promise<BackfillStatusCounts>;
617
+ }
618
+ /**
619
+ * Extraction log entry representing metadata of an LLM extraction session.
620
+ */
621
+ export interface ExtractionLogEntry {
622
+ sessionId: string;
623
+ mode: string;
624
+ factsAdded: number;
625
+ factsUpdated: number;
626
+ factsSuperseded: number;
627
+ factsSkipped: number;
628
+ provider: string;
629
+ model: string;
630
+ tokensConsumed: number;
631
+ extractedAt: Date;
632
+ }
633
+ /**
634
+ * Repository for Fact entities.
635
+ *
636
+ * Handles persistence of derived Fact projections.
637
+ */
638
+ export interface IFactRepository {
639
+ findById(id: number): Promise<Fact | null>;
640
+ findByUuid(uuid: string): Promise<Fact | null>;
641
+ findByProject(project: string): Promise<Fact[]>;
642
+ findRecent(limit: number): Promise<Fact[]>;
643
+ save(fact: Fact): Promise<Fact>;
644
+ saveMany(facts: Fact[]): Promise<Fact[]>;
645
+ search(query: string, limit?: number): Promise<Fact[]>;
646
+ supersede(uuid: string, supersededAt: Date, supersededByUuid: string): Promise<void>;
647
+ findAll(): Promise<Fact[]>;
648
+ clearAll(): Promise<void>;
649
+ }
650
+ /**
651
+ * Repository for tracking run logs of LLM fact extraction.
652
+ */
653
+ export interface IExtractionLogRepository {
654
+ findById(sessionId: string): Promise<ExtractionLogEntry | null>;
655
+ save(entry: ExtractionLogEntry): Promise<void>;
656
+ findAll(): Promise<ExtractionLogEntry[]>;
657
+ clearAll(): Promise<void>;
658
+ }