@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.
- package/README.md +294 -0
- package/dist/application/index.d.ts +6 -0
- package/dist/application/services/ambient-context-service.d.ts +90 -0
- package/dist/application/services/backfill-service.d.ts +71 -0
- package/dist/application/services/budget-allocator.d.ts +57 -0
- package/dist/application/services/embedding-service.d.ts +131 -0
- package/dist/application/services/export-service.d.ts +225 -0
- package/dist/application/services/extraction-pipeline.d.ts +50 -0
- package/dist/application/services/friction-service.d.ts +148 -0
- package/dist/application/services/fts-sanitizer.d.ts +25 -0
- package/dist/application/services/index.d.ts +34 -0
- package/dist/application/services/llm-extractor.d.ts +96 -0
- package/dist/application/services/memory-file-sync-service.d.ts +58 -0
- package/dist/application/services/pattern-extractor.d.ts +95 -0
- package/dist/application/services/recovery-service.d.ts +81 -0
- package/dist/application/services/rrf-fusion.d.ts +53 -0
- package/dist/application/services/smart-context-service.d.ts +126 -0
- package/dist/application/services/sync-service.d.ts +157 -0
- package/dist/application/services/temporal-decay.d.ts +62 -0
- package/dist/domain/entities/backfill-state.d.ts +56 -0
- package/dist/domain/entities/entity.d.ts +131 -0
- package/dist/domain/entities/extraction-state.d.ts +128 -0
- package/dist/domain/entities/fact.d.ts +59 -0
- package/dist/domain/entities/friction-entry.d.ts +84 -0
- package/dist/domain/entities/index.d.ts +15 -0
- package/dist/domain/entities/link.d.ts +74 -0
- package/dist/domain/entities/memory-file.d.ts +78 -0
- package/dist/domain/entities/message.d.ts +70 -0
- package/dist/domain/entities/session.d.ts +93 -0
- package/dist/domain/entities/tool-use.d.ts +85 -0
- package/dist/domain/errors/error-codes.d.ts +37 -0
- package/dist/domain/errors/index.d.ts +8 -0
- package/dist/domain/errors/memory-error.d.ts +52 -0
- package/dist/domain/errors/unknown-error.d.ts +9 -0
- package/dist/domain/index.d.ts +11 -0
- package/dist/domain/ports/embedding.d.ts +96 -0
- package/dist/domain/ports/extraction.d.ts +13 -0
- package/dist/domain/ports/index.d.ts +14 -0
- package/dist/domain/ports/redactor.d.ts +17 -0
- package/dist/domain/ports/repositories.d.ts +658 -0
- package/dist/domain/ports/services.d.ts +180 -0
- package/dist/domain/ports/signals.d.ts +82 -0
- package/dist/domain/ports/sources.d.ts +122 -0
- package/dist/domain/ports/types.d.ts +150 -0
- package/dist/domain/services/content-extractor.d.ts +61 -0
- package/dist/domain/services/index.d.ts +8 -0
- package/dist/domain/services/path-decoder.d.ts +56 -0
- package/dist/domain/services/query-parser.d.ts +47 -0
- package/dist/domain/value-objects/embedding-config.d.ts +56 -0
- package/dist/domain/value-objects/embedding-result.d.ts +46 -0
- package/dist/domain/value-objects/index.d.ts +10 -0
- package/dist/domain/value-objects/project-path.d.ts +92 -0
- package/dist/domain/value-objects/search-query.d.ts +30 -0
- package/dist/domain/value-objects/search-result.d.ts +92 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1548 -0
- package/dist/infrastructure/database/connection.d.ts +161 -0
- package/dist/infrastructure/database/event-log.d.ts +22 -0
- package/dist/infrastructure/database/health-checker.d.ts +248 -0
- package/dist/infrastructure/database/index.d.ts +11 -0
- package/dist/infrastructure/database/repositories/backfill-state-repository.d.ts +19 -0
- package/dist/infrastructure/database/repositories/embedding-repository.d.ts +121 -0
- package/dist/infrastructure/database/repositories/entity-repository.d.ts +73 -0
- package/dist/infrastructure/database/repositories/extraction-log-repository.d.ts +17 -0
- package/dist/infrastructure/database/repositories/extraction-state-repository.d.ts +52 -0
- package/dist/infrastructure/database/repositories/fact-repository.d.ts +25 -0
- package/dist/infrastructure/database/repositories/friction-repository.d.ts +41 -0
- package/dist/infrastructure/database/repositories/index.d.ts +17 -0
- package/dist/infrastructure/database/repositories/link-repository.d.ts +64 -0
- package/dist/infrastructure/database/repositories/memory-file-repository.d.ts +28 -0
- package/dist/infrastructure/database/repositories/message-repository.d.ts +87 -0
- package/dist/infrastructure/database/repositories/session-repository.d.ts +125 -0
- package/dist/infrastructure/database/repositories/tool-use-repository.d.ts +72 -0
- package/dist/infrastructure/database/schema.d.ts +203 -0
- package/dist/infrastructure/database/services/context-service.d.ts +93 -0
- package/dist/infrastructure/database/services/hybrid-search-service.d.ts +156 -0
- package/dist/infrastructure/database/services/index.d.ts +10 -0
- package/dist/infrastructure/database/services/search-service.d.ts +57 -0
- package/dist/infrastructure/database/services/stats-service.d.ts +36 -0
- package/dist/infrastructure/embedding/background-embedder.d.ts +125 -0
- package/dist/infrastructure/embedding/embedding-provider-factory.d.ts +44 -0
- package/dist/infrastructure/embedding/index.d.ts +5 -0
- package/dist/infrastructure/embedding/ollama-provider.d.ts +41 -0
- package/dist/infrastructure/embedding/openai-provider.d.ts +38 -0
- package/dist/infrastructure/embedding/transformers-js-provider.d.ts +34 -0
- package/dist/infrastructure/external/index.d.ts +7 -0
- package/dist/infrastructure/external/qmd-runner.d.ts +36 -0
- package/dist/infrastructure/hooks/auto-memory-writer.d.ts +52 -0
- package/dist/infrastructure/hooks/config-manager.d.ts +237 -0
- package/dist/infrastructure/hooks/git-syncer.d.ts +44 -0
- package/dist/infrastructure/hooks/hook-runner.d.ts +126 -0
- package/dist/infrastructure/hooks/index.d.ts +12 -0
- package/dist/infrastructure/hooks/log-writer.d.ts +106 -0
- package/dist/infrastructure/hooks/settings-manager.d.ts +163 -0
- package/dist/infrastructure/hooks/sync-hook-script.d.ts +83 -0
- package/dist/infrastructure/hooks/sync-logger-adapter.d.ts +17 -0
- package/dist/infrastructure/index.d.ts +11 -0
- package/dist/infrastructure/llm/anthropic-extractor.d.ts +20 -0
- package/dist/infrastructure/llm/claude-cli-extractor.d.ts +14 -0
- package/dist/infrastructure/llm/claude-summary-generator.d.ts +14 -0
- package/dist/infrastructure/llm/extraction-helper.d.ts +16 -0
- package/dist/infrastructure/llm/ollama-extractor.d.ts +20 -0
- package/dist/infrastructure/llm/openai-extractor.d.ts +23 -0
- package/dist/infrastructure/migration.d.ts +103 -0
- package/dist/infrastructure/parsers/event-classifier.d.ts +111 -0
- package/dist/infrastructure/parsers/index.d.ts +8 -0
- package/dist/infrastructure/parsers/jsonl-parser.d.ts +25 -0
- package/dist/infrastructure/parsers/timestamp.d.ts +18 -0
- package/dist/infrastructure/paths.d.ts +129 -0
- package/dist/infrastructure/providers/provider-defaults.d.ts +11 -0
- package/dist/infrastructure/providers/provider-registry.d.ts +28 -0
- package/dist/infrastructure/security/pattern-redactor.d.ts +6 -0
- package/dist/infrastructure/signals/adapters.d.ts +27 -0
- package/dist/infrastructure/signals/checkpoint-manager.d.ts +83 -0
- package/dist/infrastructure/signals/index.d.ts +8 -0
- package/dist/infrastructure/signals/signal-handler.d.ts +113 -0
- package/dist/infrastructure/sources/index.d.ts +8 -0
- package/dist/infrastructure/sources/memory-file-scanner.d.ts +23 -0
- package/dist/infrastructure/sources/project-name-resolver.d.ts +67 -0
- package/dist/infrastructure/sources/session-source.d.ts +70 -0
- package/dist/presentation/cli/command-result.d.ts +10 -0
- package/dist/presentation/cli/commands/_helpers/capture-json.d.ts +36 -0
- package/dist/presentation/cli/commands/_helpers/deprecation-warning.d.ts +41 -0
- package/dist/presentation/cli/commands/backfill.d.ts +56 -0
- package/dist/presentation/cli/commands/browse.d.ts +55 -0
- package/dist/presentation/cli/commands/completion.d.ts +61 -0
- package/dist/presentation/cli/commands/context.d.ts +53 -0
- package/dist/presentation/cli/commands/doctor.d.ts +55 -0
- package/dist/presentation/cli/commands/export.d.ts +36 -0
- package/dist/presentation/cli/commands/extract.d.ts +40 -0
- package/dist/presentation/cli/commands/facts.d.ts +17 -0
- package/dist/presentation/cli/commands/friction/dashboard.d.ts +18 -0
- package/dist/presentation/cli/commands/friction/index.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/list.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/log.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/purge.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/resolve.d.ts +12 -0
- package/dist/presentation/cli/commands/friction/types.d.ts +86 -0
- package/dist/presentation/cli/commands/friction/wontfix.d.ts +12 -0
- package/dist/presentation/cli/commands/import.d.ts +38 -0
- package/dist/presentation/cli/commands/index.d.ts +51 -0
- package/dist/presentation/cli/commands/install.d.ts +67 -0
- package/dist/presentation/cli/commands/list.d.ts +61 -0
- package/dist/presentation/cli/commands/migrate.d.ts +36 -0
- package/dist/presentation/cli/commands/purge.d.ts +100 -0
- package/dist/presentation/cli/commands/query.d.ts +51 -0
- package/dist/presentation/cli/commands/related.d.ts +47 -0
- package/dist/presentation/cli/commands/remote.d.ts +36 -0
- package/dist/presentation/cli/commands/search.d.ts +100 -0
- package/dist/presentation/cli/commands/show.d.ts +51 -0
- package/dist/presentation/cli/commands/stats.d.ts +38 -0
- package/dist/presentation/cli/commands/status.d.ts +152 -0
- package/dist/presentation/cli/commands/sync/ambient.d.ts +22 -0
- package/dist/presentation/cli/commands/sync/background.d.ts +23 -0
- package/dist/presentation/cli/commands/sync/embedding-pass.d.ts +32 -0
- package/dist/presentation/cli/commands/sync/helpers.d.ts +25 -0
- package/dist/presentation/cli/commands/sync/index.d.ts +17 -0
- package/dist/presentation/cli/commands/sync/memory-files.d.ts +26 -0
- package/dist/presentation/cli/commands/sync/types.d.ts +163 -0
- package/dist/presentation/cli/commands/uninstall.d.ts +44 -0
- package/dist/presentation/cli/db-startup.d.ts +61 -0
- package/dist/presentation/cli/formatters/ai-formatter.d.ts +38 -0
- package/dist/presentation/cli/formatters/color.d.ts +82 -0
- package/dist/presentation/cli/formatters/context-formatter.d.ts +55 -0
- package/dist/presentation/cli/formatters/dto-helpers.d.ts +176 -0
- package/dist/presentation/cli/formatters/envelope.d.ts +136 -0
- package/dist/presentation/cli/formatters/error-formatter.d.ts +41 -0
- package/dist/presentation/cli/formatters/friction-dashboard.d.ts +46 -0
- package/dist/presentation/cli/formatters/index.d.ts +17 -0
- package/dist/presentation/cli/formatters/list-formatter.d.ts +48 -0
- package/dist/presentation/cli/formatters/output-formatter.d.ts +98 -0
- package/dist/presentation/cli/formatters/related-formatter.d.ts +57 -0
- package/dist/presentation/cli/formatters/show-formatter.d.ts +63 -0
- package/dist/presentation/cli/formatters/stats-formatter.d.ts +54 -0
- package/dist/presentation/cli/formatters/text-width.d.ts +37 -0
- package/dist/presentation/cli/formatters/timestamp-formatter.d.ts +38 -0
- package/dist/presentation/cli/index.d.ts +10 -0
- package/dist/presentation/cli/index.js +1664 -0
- package/dist/presentation/cli/parsers/date-parser.d.ts +28 -0
- package/dist/presentation/cli/parsers/index.d.ts +6 -0
- package/dist/presentation/cli/pickers/index.d.ts +6 -0
- package/dist/presentation/cli/pickers/session-picker.d.ts +59 -0
- package/dist/presentation/cli/progress-reporter.d.ts +199 -0
- package/package.json +94 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Export/Import Service
|
|
3
|
+
*
|
|
4
|
+
* Provides database backup and restore functionality through JSON serialization.
|
|
5
|
+
* Supports full database export, validation, and import with round-trip integrity.
|
|
6
|
+
*/
|
|
7
|
+
import type { Database } from "bun:sqlite";
|
|
8
|
+
import type { IRedactor } from "../../domain/ports/redactor.js";
|
|
9
|
+
/**
|
|
10
|
+
* Exported session data structure.
|
|
11
|
+
*/
|
|
12
|
+
export interface SessionExport {
|
|
13
|
+
id: string;
|
|
14
|
+
projectPathEncoded: string;
|
|
15
|
+
projectPathDecoded: string;
|
|
16
|
+
projectName: string;
|
|
17
|
+
startTime: string;
|
|
18
|
+
endTime: string | null;
|
|
19
|
+
messageCount: number;
|
|
20
|
+
summary: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Exported message data structure.
|
|
24
|
+
*/
|
|
25
|
+
export interface MessageExport {
|
|
26
|
+
id: string;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
role: "user" | "assistant";
|
|
29
|
+
content: string;
|
|
30
|
+
timestamp: string;
|
|
31
|
+
toolUseIds: string | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Exported tool use data structure.
|
|
35
|
+
*/
|
|
36
|
+
export interface ToolUseExport {
|
|
37
|
+
id: string;
|
|
38
|
+
sessionId: string;
|
|
39
|
+
name: string;
|
|
40
|
+
input: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
status: string;
|
|
43
|
+
result: string | null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Exported entity data structure.
|
|
47
|
+
*/
|
|
48
|
+
export interface EntityExport {
|
|
49
|
+
id: number;
|
|
50
|
+
type: string;
|
|
51
|
+
name: string;
|
|
52
|
+
metadata: string | null;
|
|
53
|
+
confidence: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Exported link data structure.
|
|
57
|
+
*/
|
|
58
|
+
export interface LinkExport {
|
|
59
|
+
sourceType: string;
|
|
60
|
+
sourceId: string;
|
|
61
|
+
targetType: string;
|
|
62
|
+
targetId: string;
|
|
63
|
+
relationship: string;
|
|
64
|
+
weight: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Exported session-entity relationship.
|
|
68
|
+
*/
|
|
69
|
+
export interface SessionEntityExport {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
entityId: number;
|
|
72
|
+
frequency: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Exported entity-entity relationship.
|
|
76
|
+
*/
|
|
77
|
+
export interface EntityLinkExport {
|
|
78
|
+
sourceId: number;
|
|
79
|
+
targetId: number;
|
|
80
|
+
relationship: string;
|
|
81
|
+
weight: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Exported extraction state.
|
|
85
|
+
*/
|
|
86
|
+
export interface ExtractionStateExport {
|
|
87
|
+
id: string;
|
|
88
|
+
sessionPath: string;
|
|
89
|
+
startedAt: string;
|
|
90
|
+
status: string;
|
|
91
|
+
completedAt: string | null;
|
|
92
|
+
messagesExtracted: number;
|
|
93
|
+
errorMessage: string | null;
|
|
94
|
+
fileMtime: string | null;
|
|
95
|
+
fileSize: number | null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Exported fact data structure.
|
|
99
|
+
*/
|
|
100
|
+
export interface FactExport {
|
|
101
|
+
uuid: string;
|
|
102
|
+
type: string;
|
|
103
|
+
project: string;
|
|
104
|
+
content: string;
|
|
105
|
+
metadata: string | null;
|
|
106
|
+
observedAt: string;
|
|
107
|
+
supersededAt: string | null;
|
|
108
|
+
supersededBy: string | null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Complete export data structure with version and statistics.
|
|
112
|
+
*/
|
|
113
|
+
export interface ExportData {
|
|
114
|
+
version: string;
|
|
115
|
+
exportedAt: string;
|
|
116
|
+
stats: {
|
|
117
|
+
sessions: number;
|
|
118
|
+
messages: number;
|
|
119
|
+
toolUses: number;
|
|
120
|
+
entities: number;
|
|
121
|
+
links: number;
|
|
122
|
+
sessionEntities: number;
|
|
123
|
+
entityLinks: number;
|
|
124
|
+
extractionStates: number;
|
|
125
|
+
facts?: number;
|
|
126
|
+
};
|
|
127
|
+
sessions: SessionExport[];
|
|
128
|
+
messages: MessageExport[];
|
|
129
|
+
toolUses: ToolUseExport[];
|
|
130
|
+
entities: EntityExport[];
|
|
131
|
+
links: LinkExport[];
|
|
132
|
+
sessionEntities: SessionEntityExport[];
|
|
133
|
+
entityLinks: EntityLinkExport[];
|
|
134
|
+
extractionStates: ExtractionStateExport[];
|
|
135
|
+
facts?: FactExport[];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Export operation result statistics.
|
|
139
|
+
*/
|
|
140
|
+
export interface ExportStats {
|
|
141
|
+
sessions: number;
|
|
142
|
+
messages: number;
|
|
143
|
+
toolUses: number;
|
|
144
|
+
entities: number;
|
|
145
|
+
links: number;
|
|
146
|
+
bytes: number;
|
|
147
|
+
facts?: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Import operation result statistics.
|
|
151
|
+
*/
|
|
152
|
+
export interface ImportStats {
|
|
153
|
+
sessions: number;
|
|
154
|
+
messages: number;
|
|
155
|
+
toolUses: number;
|
|
156
|
+
entities: number;
|
|
157
|
+
links: number;
|
|
158
|
+
facts?: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validation result for export files.
|
|
162
|
+
*/
|
|
163
|
+
export interface ValidationResult {
|
|
164
|
+
valid: boolean;
|
|
165
|
+
version?: string;
|
|
166
|
+
error?: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Options for import operations.
|
|
170
|
+
*/
|
|
171
|
+
export interface ImportOptions {
|
|
172
|
+
/** Clear existing data before import. Default: false */
|
|
173
|
+
clearExisting?: boolean | undefined;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Options for export operations.
|
|
177
|
+
*/
|
|
178
|
+
export interface ExportToJsonOptions {
|
|
179
|
+
/** Redactor to apply before writing exported content. */
|
|
180
|
+
redactor?: IRedactor | undefined;
|
|
181
|
+
/** Write raw sensitive values. Requires explicit opt-in at the CLI boundary. */
|
|
182
|
+
includeSensitive?: boolean | undefined;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Export database contents to a JSON file.
|
|
186
|
+
*
|
|
187
|
+
* Queries all data tables and writes a complete backup to the specified path.
|
|
188
|
+
* The export includes a version field for future compatibility checks.
|
|
189
|
+
*
|
|
190
|
+
* @param db - Database connection
|
|
191
|
+
* @param outputPath - Path to write the JSON file
|
|
192
|
+
* @returns Statistics about the exported data
|
|
193
|
+
*/
|
|
194
|
+
export declare function exportToJson(db: Database, outputPath: string, options?: ExportToJsonOptions): Promise<ExportStats>;
|
|
195
|
+
/**
|
|
196
|
+
* Validate an export file before importing.
|
|
197
|
+
*
|
|
198
|
+
* Checks that the file exists, contains valid JSON, and has the required
|
|
199
|
+
* fields and version information.
|
|
200
|
+
*
|
|
201
|
+
* @param path - Path to the export file
|
|
202
|
+
* @returns Validation result with version if valid
|
|
203
|
+
*/
|
|
204
|
+
export declare function validateExportFile(path: string): Promise<ValidationResult>;
|
|
205
|
+
/**
|
|
206
|
+
* Import data from a JSON export file.
|
|
207
|
+
*
|
|
208
|
+
* Validates the file, optionally clears existing data, and inserts all
|
|
209
|
+
* records from the export. Uses batched inserts within transactions for
|
|
210
|
+
* performance.
|
|
211
|
+
*
|
|
212
|
+
* @param db - Database connection
|
|
213
|
+
* @param inputPath - Path to the export file
|
|
214
|
+
* @param options - Import options (clearExisting)
|
|
215
|
+
* @returns Statistics about the imported data
|
|
216
|
+
* @throws Error if validation fails
|
|
217
|
+
*/
|
|
218
|
+
export declare function importFromJson(db: Database, inputPath: string, options?: ImportOptions): Promise<ImportStats>;
|
|
219
|
+
/**
|
|
220
|
+
* Check if database has existing data.
|
|
221
|
+
*
|
|
222
|
+
* @param db - Database connection
|
|
223
|
+
* @returns true if any tables have data
|
|
224
|
+
*/
|
|
225
|
+
export declare function hasExistingData(db: Database): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extraction Pipeline Application Service
|
|
3
|
+
*
|
|
4
|
+
* Coordinates the full comparative knowledge extraction workflow:
|
|
5
|
+
* 1. Validates session extraction idempotency.
|
|
6
|
+
* 2. Fetches session message history.
|
|
7
|
+
* 3. Invokes LLM extraction providers to generate candidate facts.
|
|
8
|
+
* 4. Compares candidate facts to existing active facts using semantic vector cosine
|
|
9
|
+
* similarity or a fallback word-level Jaccard similarity.
|
|
10
|
+
* 5. Appends new fact events and event-sourced supersedence markers to the SSOT.
|
|
11
|
+
* 6. Dynamic database projection replay to keep SQLite derived projections aligned.
|
|
12
|
+
* 7. Records the extraction audit log.
|
|
13
|
+
*/
|
|
14
|
+
import type { Database } from "bun:sqlite";
|
|
15
|
+
import type { IExtractionProvider } from "../../domain/ports/extraction.js";
|
|
16
|
+
import type { IEmbeddingProvider } from "../../domain/ports/embedding.js";
|
|
17
|
+
import type { IRedactor } from "../../domain/ports/redactor.js";
|
|
18
|
+
import type { IFactRepository, IExtractionLogRepository, IMessageRepository } from "../../domain/ports/repositories.js";
|
|
19
|
+
export interface ExtractionPipelineResult {
|
|
20
|
+
skippedSession: boolean;
|
|
21
|
+
added: number;
|
|
22
|
+
updated: number;
|
|
23
|
+
superseded: number;
|
|
24
|
+
skipped: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class ExtractionPipeline {
|
|
27
|
+
private readonly db;
|
|
28
|
+
private readonly factRepo;
|
|
29
|
+
private readonly logRepo;
|
|
30
|
+
private readonly messageRepo;
|
|
31
|
+
private readonly extractionProvider;
|
|
32
|
+
private readonly embeddingProvider?;
|
|
33
|
+
private readonly eventLogPath?;
|
|
34
|
+
private readonly redactor;
|
|
35
|
+
constructor(db: Database, factRepo: IFactRepository, logRepo: IExtractionLogRepository, messageRepo: IMessageRepository, extractionProvider: IExtractionProvider, embeddingProvider?: IEmbeddingProvider | undefined, eventLogPath?: string | undefined, redactor?: IRedactor);
|
|
36
|
+
/**
|
|
37
|
+
* Run extraction workflow on a specific session.
|
|
38
|
+
*/
|
|
39
|
+
extractFromSession(sessionId: string, projectName: string, options?: {
|
|
40
|
+
force?: boolean;
|
|
41
|
+
}): Promise<ExtractionPipelineResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Computes Cosine Similarity between two Float32Array vectors.
|
|
44
|
+
*/
|
|
45
|
+
private cosineSimilarity;
|
|
46
|
+
/**
|
|
47
|
+
* Fallback word-level Jaccard similarity.
|
|
48
|
+
*/
|
|
49
|
+
private jaccardWordSimilarity;
|
|
50
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FrictionService
|
|
3
|
+
*
|
|
4
|
+
* Application service for friction logging operations.
|
|
5
|
+
* Orchestrates business rules around friction entries using
|
|
6
|
+
* constructor-injected IFrictionRepository.
|
|
7
|
+
*
|
|
8
|
+
* Business rules enforced here (not in entity or repository):
|
|
9
|
+
* - Default severity/category/tool when logging
|
|
10
|
+
* - Entry existence validation before resolve/wontFix
|
|
11
|
+
* - Status guard: cannot resolve/wontFix already-closed entries
|
|
12
|
+
* - wontFix flow: resolve() then updateStatus() for correct final state
|
|
13
|
+
* - Auto-ingest: reads friction.jsonl fallback file, saves entries, deletes file
|
|
14
|
+
*/
|
|
15
|
+
import type { IFrictionRepository, FrictionStats, FrictionPattern } from "../../domain/ports/repositories.js";
|
|
16
|
+
import { FrictionEntry, type FrictionSeverity, type FrictionCategory } from "../../domain/entities/friction-entry.js";
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for logging a new friction entry.
|
|
19
|
+
*/
|
|
20
|
+
export interface LogFrictionParams {
|
|
21
|
+
description: string;
|
|
22
|
+
severity?: FrictionSeverity | undefined;
|
|
23
|
+
category?: FrictionCategory | undefined;
|
|
24
|
+
tool?: string | undefined;
|
|
25
|
+
context?: string | undefined;
|
|
26
|
+
sourceProject?: string | undefined;
|
|
27
|
+
loggedAt?: Date | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Options for listing friction entries.
|
|
31
|
+
*/
|
|
32
|
+
export interface ListFrictionOptions {
|
|
33
|
+
all?: boolean | undefined;
|
|
34
|
+
status?: string | undefined;
|
|
35
|
+
category?: string | undefined;
|
|
36
|
+
tool?: string | undefined;
|
|
37
|
+
sourceProject?: string | undefined;
|
|
38
|
+
limit?: number | undefined;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Application service for friction logging operations.
|
|
42
|
+
*
|
|
43
|
+
* Constructor-injected IFrictionRepository for hexagonal architecture.
|
|
44
|
+
* Enforces business rules: defaults, validation, state transitions.
|
|
45
|
+
*/
|
|
46
|
+
export declare class FrictionService {
|
|
47
|
+
private readonly repository;
|
|
48
|
+
constructor(repository: IFrictionRepository);
|
|
49
|
+
/**
|
|
50
|
+
* Log a new friction entry.
|
|
51
|
+
*
|
|
52
|
+
* Creates a FrictionEntry with status "open", loggedAt = now (or provided),
|
|
53
|
+
* severity defaults to "medium", category defaults to "cli", tool defaults to "memory".
|
|
54
|
+
*
|
|
55
|
+
* @param params Friction entry parameters
|
|
56
|
+
* @returns The saved entry with database id
|
|
57
|
+
*/
|
|
58
|
+
log(params: LogFrictionParams): Promise<FrictionEntry>;
|
|
59
|
+
/**
|
|
60
|
+
* List friction entries.
|
|
61
|
+
*
|
|
62
|
+
* By default returns only open entries. Pass `all: true` to include
|
|
63
|
+
* resolved and wont-fix entries. Optional status/category/tool/sourceProject/limit filters.
|
|
64
|
+
*
|
|
65
|
+
* @param options Listing options
|
|
66
|
+
* @returns Array of matching friction entries
|
|
67
|
+
*/
|
|
68
|
+
list(options?: ListFrictionOptions): Promise<FrictionEntry[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a friction entry.
|
|
71
|
+
*
|
|
72
|
+
* Validates:
|
|
73
|
+
* 1. Entry exists (throws NOT_FOUND if missing)
|
|
74
|
+
* 2. Entry is open (throws INVALID_STATE if already resolved/wont-fix)
|
|
75
|
+
*
|
|
76
|
+
* @param id Friction entry database ID
|
|
77
|
+
* @param resolution How the friction was resolved
|
|
78
|
+
* @throws MemoryError with NOT_FOUND if entry doesn't exist
|
|
79
|
+
* @throws MemoryError with INVALID_STATE if entry already closed
|
|
80
|
+
*/
|
|
81
|
+
resolve(id: number, resolution: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Mark a friction entry as won't fix.
|
|
84
|
+
*
|
|
85
|
+
* Same validation as resolve(). Implements the wont-fix flow:
|
|
86
|
+
* 1. Call resolve() to set resolution text and resolved_at timestamp
|
|
87
|
+
* 2. Call updateStatus() to overwrite status from "resolved" to "wont-fix"
|
|
88
|
+
*
|
|
89
|
+
* @param id Friction entry database ID
|
|
90
|
+
* @param resolution Why it won't be fixed
|
|
91
|
+
* @throws MemoryError with NOT_FOUND if entry doesn't exist
|
|
92
|
+
* @throws MemoryError with INVALID_STATE if entry already closed
|
|
93
|
+
*/
|
|
94
|
+
wontFix(id: number, resolution: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Get friction statistics.
|
|
97
|
+
*
|
|
98
|
+
* @returns Aggregated friction stats
|
|
99
|
+
*/
|
|
100
|
+
getStats(): Promise<FrictionStats>;
|
|
101
|
+
/**
|
|
102
|
+
* Get weekly trends for friction entries.
|
|
103
|
+
*
|
|
104
|
+
* @param weeks Number of weeks to include (default 4)
|
|
105
|
+
* @returns Array of weekly new/resolved counts
|
|
106
|
+
*/
|
|
107
|
+
getWeeklyTrends(weeks?: number): Promise<Array<{
|
|
108
|
+
week: string;
|
|
109
|
+
newCount: number;
|
|
110
|
+
resolvedCount: number;
|
|
111
|
+
}>>;
|
|
112
|
+
/**
|
|
113
|
+
* Ingest friction entries from a fallback JSONL file.
|
|
114
|
+
*
|
|
115
|
+
* Reads each line as JSON, maps fields to LogFrictionParams, saves via log(),
|
|
116
|
+
* then deletes the file. Malformed lines are skipped with a warning to stderr.
|
|
117
|
+
*
|
|
118
|
+
* Field mapping from fallback format:
|
|
119
|
+
* - project -> sourceProject
|
|
120
|
+
* - date -> loggedAt (as Date)
|
|
121
|
+
* - tool defaults to "unknown" if missing
|
|
122
|
+
* - category defaults to "cli" if missing
|
|
123
|
+
*
|
|
124
|
+
* @param fallbackPath Path to the friction.jsonl file
|
|
125
|
+
* @returns Number of entries successfully ingested
|
|
126
|
+
*/
|
|
127
|
+
ingestFallbackFile(fallbackPath: string): Promise<number>;
|
|
128
|
+
/**
|
|
129
|
+
* Detect recurring friction patterns above a threshold count.
|
|
130
|
+
*
|
|
131
|
+
* @param threshold Minimum entry count to qualify as a pattern (default 3)
|
|
132
|
+
* @returns Array of patterns grouped by tool and category
|
|
133
|
+
*/
|
|
134
|
+
detectPatterns(threshold?: number): Promise<FrictionPattern[]>;
|
|
135
|
+
/**
|
|
136
|
+
* Mark all entries for a tool as reviewed at the current time.
|
|
137
|
+
*
|
|
138
|
+
* @param tool The tool name to mark as reviewed
|
|
139
|
+
*/
|
|
140
|
+
markReviewed(tool: string): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Delete friction entries whose description matches a pattern.
|
|
143
|
+
* Uses SQL LIKE matching (% for wildcard).
|
|
144
|
+
* @param pattern Description pattern to match
|
|
145
|
+
* @returns Number of entries deleted
|
|
146
|
+
*/
|
|
147
|
+
purge(pattern: string): Promise<number>;
|
|
148
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FTS5 Query Sanitizer
|
|
3
|
+
*
|
|
4
|
+
* Strips characters that FTS5 treats as syntax operators from user queries
|
|
5
|
+
* before passing to MATCH. The porter unicode61 tokenizer strips these during
|
|
6
|
+
* indexing, so queries need the same treatment for consistent matching.
|
|
7
|
+
*
|
|
8
|
+
* Preserves:
|
|
9
|
+
* - FTS5 keyword operators (AND, OR, NOT, NEAR) -- uppercase words, not special chars
|
|
10
|
+
* - Asterisks (*) -- valid FTS5 prefix search operator (e.g., auth*)
|
|
11
|
+
* - Balanced double quotes ("phrase") -- valid FTS5 phrase search syntax
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Sanitize a user query for safe use in FTS5 MATCH expressions.
|
|
15
|
+
*
|
|
16
|
+
* Replaces FTS5 operator characters with spaces and collapses whitespace.
|
|
17
|
+
* Preserves asterisks for prefix search and balanced double quotes for phrase search.
|
|
18
|
+
* Strips unmatched quotes to prevent "unterminated string" FTS5 errors.
|
|
19
|
+
* If the result is empty after sanitization, falls back to extracting
|
|
20
|
+
* alphanumeric parts from the original query.
|
|
21
|
+
*
|
|
22
|
+
* @param query Raw user query string
|
|
23
|
+
* @returns Sanitized query safe for FTS5 MATCH
|
|
24
|
+
*/
|
|
25
|
+
export declare function sanitizeFtsQuery(query: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application Services
|
|
3
|
+
*
|
|
4
|
+
* Services that orchestrate domain logic and infrastructure.
|
|
5
|
+
*/
|
|
6
|
+
export { SyncService } from "./sync-service.js";
|
|
7
|
+
export type { SyncOptions, SyncProgress, SyncResult, } from "./sync-service.js";
|
|
8
|
+
export { RecoveryService, extractSessionId } from "./recovery-service.js";
|
|
9
|
+
export type { RecoveryResult, RecoveryOptions, } from "./recovery-service.js";
|
|
10
|
+
export { PatternExtractor } from "./pattern-extractor.js";
|
|
11
|
+
export type { FileModification, ToolStats, } from "./pattern-extractor.js";
|
|
12
|
+
export { LlmExtractor } from "./llm-extractor.js";
|
|
13
|
+
export type { ExtractionResult, LlmExtractorOptions, } from "./llm-extractor.js";
|
|
14
|
+
export { EmbeddingService, computeModelHash } from "./embedding-service.js";
|
|
15
|
+
export type { EmbedOptions, EmbedProgress, EmbedResult, ModelState, } from "./embedding-service.js";
|
|
16
|
+
export { exportToJson, validateExportFile, importFromJson, hasExistingData, } from "./export-service.js";
|
|
17
|
+
export type { ExportData, ExportStats, ImportStats, ValidationResult, ImportOptions, SessionExport, MessageExport, ToolUseExport, EntityExport, LinkExport, } from "./export-service.js";
|
|
18
|
+
export { reciprocalRankFusion } from "./rrf-fusion.js";
|
|
19
|
+
export type { RankedCandidate, FusedResult, } from "./rrf-fusion.js";
|
|
20
|
+
export { applyTemporalDecay, applyTemporalDecayWithExemptions, CURATED_FILE_TYPES, } from "./temporal-decay.js";
|
|
21
|
+
export type { DecayableResult, DecayedResult, } from "./temporal-decay.js";
|
|
22
|
+
export { sanitizeFtsQuery } from "./fts-sanitizer.js";
|
|
23
|
+
export { MemoryFileSyncService } from "./memory-file-sync-service.js";
|
|
24
|
+
export type { MemoryFileSyncResult, MemoryFileSyncProgress, MemoryFileSyncOptions, } from "./memory-file-sync-service.js";
|
|
25
|
+
export { FrictionService } from "./friction-service.js";
|
|
26
|
+
export type { LogFrictionParams, ListFrictionOptions, } from "./friction-service.js";
|
|
27
|
+
export { BackfillService } from "./backfill-service.js";
|
|
28
|
+
export type { BackfillResult, BackfillProgress, DryRunResult, BackfillOptions, IDailyLogWriter, } from "./backfill-service.js";
|
|
29
|
+
export { allocateBudget } from "./budget-allocator.js";
|
|
30
|
+
export type { BudgetSection, AllocatedSection, BudgetAllocationResult, } from "./budget-allocator.js";
|
|
31
|
+
export { SmartContextService } from "./smart-context-service.js";
|
|
32
|
+
export type { SmartContextOptions, SmartContextResult, ContextSection, IProjectResolver, SmartContextDeps, } from "./smart-context-service.js";
|
|
33
|
+
export { AmbientContextService } from "./ambient-context-service.js";
|
|
34
|
+
export type { AmbientContextOptions, AmbientContextResult, } from "./ambient-context-service.js";
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Extractor Service
|
|
3
|
+
*
|
|
4
|
+
* Claude-powered entity extraction from session content.
|
|
5
|
+
* Designed to run during SessionStop hook when Claude's session is still active.
|
|
6
|
+
*
|
|
7
|
+
* The extractor:
|
|
8
|
+
* 1. Receives session messages
|
|
9
|
+
* 2. Uses structured prompts to extract topics and summary
|
|
10
|
+
* 3. Returns Entity objects for persistence
|
|
11
|
+
*/
|
|
12
|
+
import { Entity } from "../../domain/entities/entity.js";
|
|
13
|
+
import type { Message } from "../../domain/entities/message.js";
|
|
14
|
+
/**
|
|
15
|
+
* Result of LLM-based entity extraction.
|
|
16
|
+
*/
|
|
17
|
+
export interface ExtractionResult {
|
|
18
|
+
/** Concept entities extracted from session */
|
|
19
|
+
topics: Entity[];
|
|
20
|
+
/** Term entities with definitions */
|
|
21
|
+
terms: Entity[];
|
|
22
|
+
/** Decision entities with structured metadata */
|
|
23
|
+
decisions: Entity[];
|
|
24
|
+
/** Session summary text */
|
|
25
|
+
summary: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for LLM extraction.
|
|
29
|
+
*/
|
|
30
|
+
export interface LlmExtractorOptions {
|
|
31
|
+
/** Session identifier for linking entities */
|
|
32
|
+
sessionId: string;
|
|
33
|
+
/** Messages to extract entities from */
|
|
34
|
+
messages: Message[];
|
|
35
|
+
/** Maximum tokens for extraction (default: 1000) */
|
|
36
|
+
maxTokens?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* LLM-based entity extraction service.
|
|
40
|
+
*
|
|
41
|
+
* Extracts topics, terms, decisions, and summaries from session content
|
|
42
|
+
* using Claude's language understanding.
|
|
43
|
+
*
|
|
44
|
+
* IMPORTANT: This is designed to run during SessionStop hook when Claude's
|
|
45
|
+
* session is still active. The extraction uses the existing session context.
|
|
46
|
+
*/
|
|
47
|
+
export declare class LlmExtractor {
|
|
48
|
+
/**
|
|
49
|
+
* Extract entities from session content using LLM.
|
|
50
|
+
*
|
|
51
|
+
* For unit tests and when no LLM context is available, returns empty result.
|
|
52
|
+
* In production (during hook execution), this would use Claude's session.
|
|
53
|
+
*
|
|
54
|
+
* @param options Extraction options including session ID and messages
|
|
55
|
+
* @returns Extraction result with entities and summary
|
|
56
|
+
*/
|
|
57
|
+
static extract(options: LlmExtractorOptions): Promise<ExtractionResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Create extraction prompt for Claude.
|
|
60
|
+
*
|
|
61
|
+
* Formats session messages and requests structured JSON output
|
|
62
|
+
* containing topics, terms, decisions, and summary.
|
|
63
|
+
*
|
|
64
|
+
* @param messages Session messages to include in prompt
|
|
65
|
+
* @returns Structured prompt requesting JSON output
|
|
66
|
+
*/
|
|
67
|
+
static createExtractionPrompt(messages: Message[]): string;
|
|
68
|
+
/**
|
|
69
|
+
* Parse LLM response into Entity objects.
|
|
70
|
+
*
|
|
71
|
+
* Handles malformed JSON gracefully by returning empty result.
|
|
72
|
+
* Validates and clamps confidence scores to 0-1 range.
|
|
73
|
+
*
|
|
74
|
+
* @param response Raw LLM response text
|
|
75
|
+
* @param _sessionId Session ID for context (not used in entity creation)
|
|
76
|
+
* @returns Extraction result with parsed entities
|
|
77
|
+
*/
|
|
78
|
+
static parseExtractionResponse(response: string, _sessionId: string): ExtractionResult;
|
|
79
|
+
/**
|
|
80
|
+
* Parse raw topics into concept entities.
|
|
81
|
+
*/
|
|
82
|
+
private static parseTopics;
|
|
83
|
+
/**
|
|
84
|
+
* Parse raw terms into term entities.
|
|
85
|
+
*/
|
|
86
|
+
private static parseTerms;
|
|
87
|
+
/**
|
|
88
|
+
* Parse raw decisions into decision entities.
|
|
89
|
+
*/
|
|
90
|
+
private static parseDecisions;
|
|
91
|
+
/**
|
|
92
|
+
* Normalize confidence score to 0-1 range.
|
|
93
|
+
* Defaults to 0.5 if not provided.
|
|
94
|
+
*/
|
|
95
|
+
private static normalizeConfidence;
|
|
96
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryFileSyncService
|
|
3
|
+
*
|
|
4
|
+
* Application service for syncing legacy markdown memory files to the database.
|
|
5
|
+
*
|
|
6
|
+
* Separate from SyncService to avoid constructor inflation.
|
|
7
|
+
* The CLI sync command orchestrates both services sequentially.
|
|
8
|
+
*
|
|
9
|
+
* Uses IMemoryFileScanner (domain port) to discover files and
|
|
10
|
+
* IMemoryFileRepository (domain port) to persist them, maintaining
|
|
11
|
+
* proper hexagonal architecture boundaries.
|
|
12
|
+
*/
|
|
13
|
+
import type { IMemoryFileRepository } from "../../domain/ports/repositories.js";
|
|
14
|
+
import type { IMemoryFileScanner } from "../../domain/ports/sources.js";
|
|
15
|
+
/**
|
|
16
|
+
* Progress callback for memory file sync.
|
|
17
|
+
*/
|
|
18
|
+
export interface MemoryFileSyncProgress {
|
|
19
|
+
current: number;
|
|
20
|
+
total: number;
|
|
21
|
+
filePath: string;
|
|
22
|
+
action: "indexing" | "skipped";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Result of memory file sync operation.
|
|
26
|
+
*/
|
|
27
|
+
export interface MemoryFileSyncResult {
|
|
28
|
+
filesIndexed: number;
|
|
29
|
+
filesSkipped: number;
|
|
30
|
+
errors: Array<{
|
|
31
|
+
filePath: string;
|
|
32
|
+
error: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for memory file sync.
|
|
37
|
+
*/
|
|
38
|
+
export interface MemoryFileSyncOptions {
|
|
39
|
+
onProgress?: (progress: MemoryFileSyncProgress) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Application service for syncing legacy markdown memory files to the database.
|
|
43
|
+
*
|
|
44
|
+
* Separate from SyncService to avoid constructor inflation.
|
|
45
|
+
* The CLI sync command orchestrates both services sequentially.
|
|
46
|
+
*/
|
|
47
|
+
export declare class MemoryFileSyncService {
|
|
48
|
+
private readonly repository;
|
|
49
|
+
private readonly scanner;
|
|
50
|
+
constructor(repository: IMemoryFileRepository, scanner: IMemoryFileScanner);
|
|
51
|
+
/**
|
|
52
|
+
* Discover and index memory files.
|
|
53
|
+
*
|
|
54
|
+
* Performs incremental indexing: files where content hash matches
|
|
55
|
+
* the stored hash are skipped. New and changed files are upserted.
|
|
56
|
+
*/
|
|
57
|
+
syncMemoryFiles(options?: MemoryFileSyncOptions): Promise<MemoryFileSyncResult>;
|
|
58
|
+
}
|