compound-agent 1.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/CHANGELOG.md +412 -0
- package/LICENSE +21 -0
- package/README.md +331 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +5600 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +971 -0
- package/dist/index.js +1576 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +77 -0
- package/dist/mcp.js +1025 -0
- package/dist/mcp.js.map +1 -0
- package/dist/types--TsW4ZqX.d.ts +2601 -0
- package/package.json +80 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,971 @@
|
|
|
1
|
+
import { L as Lesson, M as MemoryItem, a as MemoryItemType, C as Context, S as Severity } from './types--TsW4ZqX.js';
|
|
2
|
+
export { b as LegacyLessonSchema, c as LegacyTombstoneSchema, d as LessonItemSchema, e as LessonRecord, f as LessonRecordSchema, g as LessonSchema, h as LessonType, i as LessonTypeSchema, j as MemoryItemRecord, k as MemoryItemRecordSchema, l as MemoryItemSchema, m as MemoryItemTypeSchema, P as PatternItem, n as PatternItemSchema, o as Preference, p as PreferenceItemSchema, q as Solution, r as SolutionItemSchema, s as Source, t as generateId } from './types--TsW4ZqX.js';
|
|
3
|
+
import { LlamaEmbeddingContext } from 'node-llama-cpp';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* JSONL storage layer for memory items
|
|
8
|
+
*
|
|
9
|
+
* Append-only storage with last-write-wins deduplication.
|
|
10
|
+
* Source of truth - git trackable.
|
|
11
|
+
*
|
|
12
|
+
* Primary API:
|
|
13
|
+
* appendMemoryItem() - Append any memory item type
|
|
14
|
+
* readMemoryItems() - Read all non-deleted memory items
|
|
15
|
+
*
|
|
16
|
+
* Backward-compatible API:
|
|
17
|
+
* appendLesson() - Append a lesson (delegates to appendMemoryItem)
|
|
18
|
+
* readLessons() - Read lesson-type items only
|
|
19
|
+
*
|
|
20
|
+
* Deletion: append the item with `deleted: true` and `deletedAt`.
|
|
21
|
+
* Read path also accepts old minimal tombstone records for backward compat.
|
|
22
|
+
* Legacy type:'quick'/'full' records are converted to type:'lesson' on read.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Relative path to lessons file from repo root */
|
|
26
|
+
declare const LESSONS_PATH = ".claude/lessons/index.jsonl";
|
|
27
|
+
/** Options for reading memory items */
|
|
28
|
+
interface ReadLessonsOptions {
|
|
29
|
+
/** If true, throw on first parse error. Default: false (skip errors) */
|
|
30
|
+
strict?: boolean;
|
|
31
|
+
/** Callback for each parse error in non-strict mode */
|
|
32
|
+
onParseError?: (error: ParseError) => void;
|
|
33
|
+
}
|
|
34
|
+
/** Parse error details */
|
|
35
|
+
interface ParseError {
|
|
36
|
+
/** 1-based line number */
|
|
37
|
+
line: number;
|
|
38
|
+
/** Error message */
|
|
39
|
+
message: string;
|
|
40
|
+
/** Original error */
|
|
41
|
+
cause: unknown;
|
|
42
|
+
}
|
|
43
|
+
/** Result of reading lessons (backward-compat) */
|
|
44
|
+
interface ReadLessonsResult {
|
|
45
|
+
/** Successfully parsed lessons */
|
|
46
|
+
lessons: Lesson[];
|
|
47
|
+
/** Number of lines skipped due to errors */
|
|
48
|
+
skippedCount: number;
|
|
49
|
+
}
|
|
50
|
+
/** Result of reading memory items */
|
|
51
|
+
interface ReadMemoryItemsResult {
|
|
52
|
+
/** Successfully parsed memory items */
|
|
53
|
+
items: MemoryItem[];
|
|
54
|
+
/** Number of lines skipped due to errors */
|
|
55
|
+
skippedCount: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Append a memory item to the JSONL file.
|
|
59
|
+
* Creates directory structure if missing.
|
|
60
|
+
* Primary write function for all memory item types.
|
|
61
|
+
*
|
|
62
|
+
* @param repoRoot - Repository root directory
|
|
63
|
+
* @param item - Memory item to append (any type: lesson, solution, pattern, preference)
|
|
64
|
+
*/
|
|
65
|
+
declare function appendMemoryItem(repoRoot: string, item: MemoryItem): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Append a lesson to the JSONL file.
|
|
68
|
+
* Backward-compatible wrapper around appendMemoryItem.
|
|
69
|
+
*
|
|
70
|
+
* @param repoRoot - Repository root directory
|
|
71
|
+
* @param lesson - Lesson to append
|
|
72
|
+
*/
|
|
73
|
+
declare function appendLesson(repoRoot: string, lesson: Lesson): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Read all non-deleted memory items from the JSONL file.
|
|
76
|
+
* Primary read function for the unified memory API.
|
|
77
|
+
*
|
|
78
|
+
* Applies last-write-wins deduplication by ID.
|
|
79
|
+
* Converts legacy type:'quick'/'full' to type:'lesson'.
|
|
80
|
+
*
|
|
81
|
+
* Handles tombstone formats:
|
|
82
|
+
* - Canonical: { id, deleted: true, deletedAt }
|
|
83
|
+
* - Legacy: Full record with deleted:true field
|
|
84
|
+
*
|
|
85
|
+
* @param repoRoot - Repository root directory
|
|
86
|
+
* @param options - Optional settings for error handling
|
|
87
|
+
* @returns Result with items array and count of skipped lines
|
|
88
|
+
*/
|
|
89
|
+
declare function readMemoryItems(repoRoot: string, options?: ReadLessonsOptions): Promise<ReadMemoryItemsResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Read all non-deleted lessons from the JSONL file.
|
|
92
|
+
* Backward-compatible wrapper that filters to lesson-type items only.
|
|
93
|
+
*
|
|
94
|
+
* @param repoRoot - Repository root directory
|
|
95
|
+
* @param options - Optional settings for error handling
|
|
96
|
+
* @returns Result with lessons array and count of skipped lines
|
|
97
|
+
*/
|
|
98
|
+
declare function readLessons(repoRoot: string, options?: ReadLessonsOptions): Promise<ReadLessonsResult>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* SQLite database connection management.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/** Relative path to database file from repo root */
|
|
105
|
+
declare const DB_PATH = ".claude/.cache/lessons.sqlite";
|
|
106
|
+
/**
|
|
107
|
+
* Close the SQLite database connection.
|
|
108
|
+
*/
|
|
109
|
+
declare function closeDb(): void;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* SQLite index synchronization with JSONL source of truth.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Rebuild the SQLite index from JSONL source of truth.
|
|
117
|
+
* Preserves cached embeddings when item content hasn't changed.
|
|
118
|
+
* @param repoRoot - Absolute path to repository root
|
|
119
|
+
*/
|
|
120
|
+
declare function rebuildIndex(repoRoot: string): Promise<void>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* SQLite search operations using FTS5 full-text search.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Search lessons using FTS5 full-text search.
|
|
128
|
+
* @param repoRoot - Absolute path to repository root
|
|
129
|
+
* @param query - FTS5 query string
|
|
130
|
+
* @param limit - Maximum number of results
|
|
131
|
+
* @param typeFilter - Optional memory item type to filter by
|
|
132
|
+
* @returns Matching lessons
|
|
133
|
+
*/
|
|
134
|
+
declare function searchKeyword(repoRoot: string, query: string, limit: number, typeFilter?: MemoryItemType): Promise<MemoryItem[]>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Embedding model resolution using node-llama-cpp's built-in resolver.
|
|
138
|
+
*
|
|
139
|
+
* Uses resolveModelFile for automatic download and caching.
|
|
140
|
+
* Model is stored in ~/.node-llama-cpp/models/ by default.
|
|
141
|
+
*/
|
|
142
|
+
/**
|
|
143
|
+
* HuggingFace URI for EmbeddingGemma-300M (Q4_0 quantization).
|
|
144
|
+
*
|
|
145
|
+
* - Size: ~278MB
|
|
146
|
+
* - Dimensions: 768 (default), supports MRL truncation to 512/256/128
|
|
147
|
+
* - Context: 2048 tokens
|
|
148
|
+
*/
|
|
149
|
+
declare const MODEL_URI = "hf:ggml-org/embeddinggemma-300M-qat-q4_0-GGUF/embeddinggemma-300M-qat-Q4_0.gguf";
|
|
150
|
+
/**
|
|
151
|
+
* Expected model filename after download.
|
|
152
|
+
* node-llama-cpp uses format: hf_{org}_{filename}
|
|
153
|
+
*/
|
|
154
|
+
declare const MODEL_FILENAME = "hf_ggml-org_embeddinggemma-300M-qat-Q4_0.gguf";
|
|
155
|
+
/**
|
|
156
|
+
* Check if the embedding model is available locally.
|
|
157
|
+
*
|
|
158
|
+
* @returns true if model file exists
|
|
159
|
+
*/
|
|
160
|
+
declare function isModelAvailable(): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Result of checking if the model is usable at runtime.
|
|
163
|
+
*
|
|
164
|
+
* A discriminated union where `usable` determines which fields are present:
|
|
165
|
+
* - usable=true: Model can initialize and create embedding context
|
|
166
|
+
* - usable=false: Model cannot be used, with reason and actionable fix
|
|
167
|
+
*/
|
|
168
|
+
type UsabilityResult = {
|
|
169
|
+
usable: true;
|
|
170
|
+
reason?: undefined;
|
|
171
|
+
action?: undefined;
|
|
172
|
+
} | {
|
|
173
|
+
usable: false;
|
|
174
|
+
reason: string;
|
|
175
|
+
action: string;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Check if the embedding model is usable at runtime.
|
|
179
|
+
*
|
|
180
|
+
* Goes beyond file existence to verify the model can actually initialize:
|
|
181
|
+
* 1. Checks if model file exists (fast fail)
|
|
182
|
+
* 2. Attempts to load llama runtime
|
|
183
|
+
* 3. Attempts to load model
|
|
184
|
+
* 4. Attempts to create embedding context
|
|
185
|
+
* 5. Cleans up all resources after check
|
|
186
|
+
*
|
|
187
|
+
* @returns UsabilityResult with usable status and actionable error if failed
|
|
188
|
+
*/
|
|
189
|
+
declare function isModelUsable(): Promise<UsabilityResult>;
|
|
190
|
+
/**
|
|
191
|
+
* Resolve the embedding model path, downloading if necessary.
|
|
192
|
+
*
|
|
193
|
+
* Uses node-llama-cpp's resolveModelFile for automatic download with progress.
|
|
194
|
+
*
|
|
195
|
+
* @param options - Optional configuration
|
|
196
|
+
* @param options.cli - Show download progress in console (default: true)
|
|
197
|
+
* @returns Path to the resolved model file
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const modelPath = await resolveModel();
|
|
202
|
+
* const llama = await getLlama();
|
|
203
|
+
* const model = await llama.loadModel({ modelPath });
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare function resolveModel(options?: {
|
|
207
|
+
cli?: boolean;
|
|
208
|
+
}): Promise<string>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Text embedding via node-llama-cpp with EmbeddingGemma model
|
|
212
|
+
*
|
|
213
|
+
* **Resource lifecycle:**
|
|
214
|
+
* - Model is loaded lazily on first embedding call (~150MB in memory)
|
|
215
|
+
* - Once loaded, the model remains in memory until `unloadEmbedding()` is called
|
|
216
|
+
* - Loading is slow (~1-3s); keeping loaded improves subsequent call performance
|
|
217
|
+
*
|
|
218
|
+
* **Memory usage:**
|
|
219
|
+
* - Embedding model: ~150MB RAM when loaded
|
|
220
|
+
* - Embeddings themselves: ~3KB per embedding (768 dimensions x 4 bytes)
|
|
221
|
+
*
|
|
222
|
+
* @see {@link unloadEmbedding} for releasing memory
|
|
223
|
+
* @see {@link getEmbedding} for the lazy-loading mechanism
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Get the LlamaEmbeddingContext instance for generating embeddings.
|
|
228
|
+
*
|
|
229
|
+
* **Lazy loading behavior:**
|
|
230
|
+
* - First call loads the embedding model (~150MB) into memory
|
|
231
|
+
* - Loading takes ~1-3 seconds depending on hardware
|
|
232
|
+
* - Subsequent calls return the cached instance immediately
|
|
233
|
+
* - Downloads model automatically if not present
|
|
234
|
+
*
|
|
235
|
+
* **Resource lifecycle:**
|
|
236
|
+
* - Once loaded, model stays in memory until `unloadEmbedding()` is called
|
|
237
|
+
* - For CLI commands: typically load once, use, then unload on exit
|
|
238
|
+
* - For long-running processes: keep loaded for performance
|
|
239
|
+
*
|
|
240
|
+
* @returns The singleton embedding context
|
|
241
|
+
* @throws Error if model download fails
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* // Direct usage (prefer embedText for simple cases)
|
|
246
|
+
* const ctx = await getEmbedding();
|
|
247
|
+
* const result = await ctx.getEmbeddingFor('some text');
|
|
248
|
+
*
|
|
249
|
+
* // Ensure cleanup
|
|
250
|
+
* process.on('exit', () => unloadEmbedding());
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @see {@link embedText} for simpler text-to-vector conversion
|
|
254
|
+
* @see {@link unloadEmbedding} for releasing memory
|
|
255
|
+
*/
|
|
256
|
+
declare function getEmbedding(): Promise<LlamaEmbeddingContext>;
|
|
257
|
+
/**
|
|
258
|
+
* Unload the embedding context to free memory (~150MB).
|
|
259
|
+
*
|
|
260
|
+
* **Resource lifecycle:**
|
|
261
|
+
* - Disposes the underlying LlamaEmbeddingContext
|
|
262
|
+
* - Releases ~150MB of RAM used by the model
|
|
263
|
+
* - After unloading, subsequent embedding calls will reload the model
|
|
264
|
+
*
|
|
265
|
+
* **When to call:**
|
|
266
|
+
* - At the end of CLI commands to ensure clean process exit
|
|
267
|
+
* - In memory-constrained environments after batch processing
|
|
268
|
+
* - Before process exit in graceful shutdown handlers
|
|
269
|
+
* - When switching to a different model (if supported in future)
|
|
270
|
+
*
|
|
271
|
+
* **Best practices:**
|
|
272
|
+
* - For single-operation scripts: call before exit
|
|
273
|
+
* - For daemon/server processes: call in shutdown handler
|
|
274
|
+
* - Not needed between embedding calls in the same process
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* // CLI command pattern
|
|
279
|
+
* try {
|
|
280
|
+
* const embedding = await embedText('some text');
|
|
281
|
+
* // ... use embedding
|
|
282
|
+
* } finally {
|
|
283
|
+
* unloadEmbedding();
|
|
284
|
+
* closeDb();
|
|
285
|
+
* }
|
|
286
|
+
*
|
|
287
|
+
* // Graceful shutdown pattern
|
|
288
|
+
* process.on('SIGTERM', () => {
|
|
289
|
+
* unloadEmbedding();
|
|
290
|
+
* closeDb();
|
|
291
|
+
* process.exit(0);
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @see {@link getEmbedding} for loading the model
|
|
296
|
+
* @see {@link closeDb} for database cleanup (often used together)
|
|
297
|
+
*/
|
|
298
|
+
declare function unloadEmbedding(): void;
|
|
299
|
+
/**
|
|
300
|
+
* Embed a single text string into a vector.
|
|
301
|
+
*
|
|
302
|
+
* **Lazy loading:** First call loads the embedding model (~150MB, ~1-3s).
|
|
303
|
+
* Subsequent calls use the cached model and complete in milliseconds.
|
|
304
|
+
*
|
|
305
|
+
* @param text - The text to embed
|
|
306
|
+
* @returns A 768-dimensional vector (number[])
|
|
307
|
+
* @throws Error if model download fails
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const vector = await embedText('TypeScript error handling');
|
|
312
|
+
* console.log(vector.length); // 768
|
|
313
|
+
*
|
|
314
|
+
* // Remember to clean up when done
|
|
315
|
+
* unloadEmbedding();
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @see {@link embedTexts} for batch embedding
|
|
319
|
+
* @see {@link unloadEmbedding} for releasing memory
|
|
320
|
+
*/
|
|
321
|
+
declare function embedText(text: string): Promise<number[]>;
|
|
322
|
+
/**
|
|
323
|
+
* Embed multiple texts into vectors.
|
|
324
|
+
*
|
|
325
|
+
* **Lazy loading:** First call loads the embedding model (~150MB, ~1-3s).
|
|
326
|
+
* Subsequent calls use the cached model.
|
|
327
|
+
*
|
|
328
|
+
* **Performance:** More efficient than calling `embedText` in a loop
|
|
329
|
+
* when processing multiple texts, as model loading happens only once.
|
|
330
|
+
*
|
|
331
|
+
* @param texts - Array of texts to embed
|
|
332
|
+
* @returns Array of 768-dimensional vectors, same order as input
|
|
333
|
+
* @throws Error if model download fails
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* const texts = ['first text', 'second text'];
|
|
338
|
+
* const vectors = await embedTexts(texts);
|
|
339
|
+
* console.log(vectors.length); // 2
|
|
340
|
+
* console.log(vectors[0].length); // 768
|
|
341
|
+
*
|
|
342
|
+
* // Remember to clean up when done
|
|
343
|
+
* unloadEmbedding();
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* @see {@link embedText} for single text embedding
|
|
347
|
+
* @see {@link unloadEmbedding} for releasing memory
|
|
348
|
+
*/
|
|
349
|
+
declare function embedTexts(texts: string[]): Promise<number[][]>;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Vector search with cosine similarity
|
|
353
|
+
*
|
|
354
|
+
* Embeds query text and ranks lessons by semantic similarity.
|
|
355
|
+
* Uses SQLite cache to avoid recomputing embeddings.
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Calculate cosine similarity between two vectors.
|
|
360
|
+
* Returns value between -1 (opposite) and 1 (identical).
|
|
361
|
+
*/
|
|
362
|
+
declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
363
|
+
/**
|
|
364
|
+
* Memory item with similarity score.
|
|
365
|
+
* The `lesson` field holds any MemoryItem type (not just Lesson).
|
|
366
|
+
* Field name kept for backward compatibility.
|
|
367
|
+
*/
|
|
368
|
+
interface ScoredLesson {
|
|
369
|
+
lesson: MemoryItem;
|
|
370
|
+
score: number;
|
|
371
|
+
}
|
|
372
|
+
/** Alias for ScoredLesson for unified memory API consumers. */
|
|
373
|
+
type ScoredMemoryItem = ScoredLesson;
|
|
374
|
+
/** Options for vector search */
|
|
375
|
+
interface SearchVectorOptions {
|
|
376
|
+
/** Maximum number of results to return (default: 10) */
|
|
377
|
+
limit?: number;
|
|
378
|
+
}
|
|
379
|
+
declare function searchVector(repoRoot: string, query: string, options?: SearchVectorOptions): Promise<ScoredLesson[]>;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Multi-factor memory item ranking system
|
|
383
|
+
*
|
|
384
|
+
* Combines vector similarity with semantic boosts:
|
|
385
|
+
* - Severity: high=1.5, medium=1.0, low=0.8
|
|
386
|
+
* - Recency: 1.2 for items ≤30 days old
|
|
387
|
+
* - Confirmation: 1.3 for confirmed items
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
/** Lesson/memory item with final ranked score */
|
|
391
|
+
interface RankedLesson extends ScoredLesson {
|
|
392
|
+
finalScore?: number;
|
|
393
|
+
}
|
|
394
|
+
/** Alias for RankedLesson for unified memory API consumers. */
|
|
395
|
+
type RankedMemoryItem = RankedLesson;
|
|
396
|
+
/**
|
|
397
|
+
* Calculate severity boost based on item severity.
|
|
398
|
+
* Items without severity get 1.0 (medium boost).
|
|
399
|
+
*/
|
|
400
|
+
declare function severityBoost(item: MemoryItem): number;
|
|
401
|
+
/**
|
|
402
|
+
* Calculate recency boost based on item age.
|
|
403
|
+
* Items ≤30 days old get 1.2, older get 1.0.
|
|
404
|
+
*/
|
|
405
|
+
declare function recencyBoost(item: MemoryItem): number;
|
|
406
|
+
/**
|
|
407
|
+
* Calculate confirmation boost.
|
|
408
|
+
* Confirmed items get 1.3, unconfirmed get 1.0.
|
|
409
|
+
*/
|
|
410
|
+
declare function confirmationBoost(item: MemoryItem): number;
|
|
411
|
+
/**
|
|
412
|
+
* Calculate combined score for a memory item.
|
|
413
|
+
* score = vectorSimilarity * min(severity * recency * confirmation, MAX_COMBINED_BOOST)
|
|
414
|
+
*/
|
|
415
|
+
declare function calculateScore(item: MemoryItem, vectorSimilarity: number): number;
|
|
416
|
+
/**
|
|
417
|
+
* Rank lessons by combined score.
|
|
418
|
+
* Returns new array sorted by finalScore descending.
|
|
419
|
+
*
|
|
420
|
+
* Works with ScoredLesson[] (backward compat, uses .lesson field).
|
|
421
|
+
* For ScoredMemoryItem[], use the .item field — same underlying data.
|
|
422
|
+
*/
|
|
423
|
+
declare function rankLessons(lessons: ScoredLesson[]): RankedLesson[];
|
|
424
|
+
/**
|
|
425
|
+
* Rank memory items by combined score.
|
|
426
|
+
* Primary API for unified memory types. Uses .item field.
|
|
427
|
+
* Returns new array sorted by finalScore descending.
|
|
428
|
+
*/
|
|
429
|
+
declare const rankMemoryItems: typeof rankLessons;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Quality filters for lesson capture
|
|
433
|
+
*
|
|
434
|
+
* Filters to ensure lessons are:
|
|
435
|
+
* - Novel (not duplicate)
|
|
436
|
+
* - Specific (not vague)
|
|
437
|
+
*
|
|
438
|
+
* Actionability check is available but not part of the capture gate.
|
|
439
|
+
* Strategy: capture aggressively, prune later.
|
|
440
|
+
*/
|
|
441
|
+
/** Result of novelty check */
|
|
442
|
+
interface NoveltyResult {
|
|
443
|
+
novel: boolean;
|
|
444
|
+
reason?: string;
|
|
445
|
+
existingId?: string;
|
|
446
|
+
}
|
|
447
|
+
/** Options for novelty check */
|
|
448
|
+
interface NoveltyOptions {
|
|
449
|
+
threshold?: number;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Check if an insight is novel (not a duplicate of existing lessons).
|
|
453
|
+
* Uses keyword search to find potentially similar lessons.
|
|
454
|
+
*/
|
|
455
|
+
declare function isNovel(repoRoot: string, insight: string, options?: NoveltyOptions): Promise<NoveltyResult>;
|
|
456
|
+
/** Result of specificity check */
|
|
457
|
+
interface SpecificityResult {
|
|
458
|
+
specific: boolean;
|
|
459
|
+
reason?: string;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Check if an insight is specific enough to be useful.
|
|
463
|
+
* Rejects vague, generic advice that doesn't provide actionable guidance.
|
|
464
|
+
*/
|
|
465
|
+
declare function isSpecific(insight: string): SpecificityResult;
|
|
466
|
+
/** Result of actionability check */
|
|
467
|
+
interface ActionabilityResult {
|
|
468
|
+
actionable: boolean;
|
|
469
|
+
reason?: string;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Check if an insight contains actionable guidance.
|
|
473
|
+
* Returns false for pure observations or questions.
|
|
474
|
+
*/
|
|
475
|
+
declare function isActionable(insight: string): ActionabilityResult;
|
|
476
|
+
/** Result of combined quality check */
|
|
477
|
+
interface ProposeResult {
|
|
478
|
+
shouldPropose: boolean;
|
|
479
|
+
reason?: string;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Combined quality check for lesson proposals.
|
|
483
|
+
* Returns true only if insight is novel AND specific.
|
|
484
|
+
* Actionability gate removed: capture aggressively, prune later.
|
|
485
|
+
*/
|
|
486
|
+
declare function shouldPropose(repoRoot: string, insight: string): Promise<ProposeResult>;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Trigger detection for automatic memory capture
|
|
490
|
+
*
|
|
491
|
+
* Detects patterns that indicate potential learning opportunities:
|
|
492
|
+
* - User corrections
|
|
493
|
+
* - Self-corrections
|
|
494
|
+
* - Test failures
|
|
495
|
+
*
|
|
496
|
+
* Also infers memory item type from insight text:
|
|
497
|
+
* - pattern: "use X instead of Y", "prefer X over Y"
|
|
498
|
+
* - solution: "when X, do Y", "if X then Y", "to fix X"
|
|
499
|
+
* - preference: "always X", "never X"
|
|
500
|
+
* - lesson: default for unclassified insights
|
|
501
|
+
*/
|
|
502
|
+
|
|
503
|
+
/** Signal data for correction detection */
|
|
504
|
+
interface CorrectionSignal {
|
|
505
|
+
messages: string[];
|
|
506
|
+
context: Context;
|
|
507
|
+
}
|
|
508
|
+
/** Detected correction result */
|
|
509
|
+
interface DetectedCorrection {
|
|
510
|
+
trigger: string;
|
|
511
|
+
correctionMessage: string;
|
|
512
|
+
context: Context;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Detect user correction signals in conversation.
|
|
516
|
+
*
|
|
517
|
+
* Looks for patterns that indicate the user is correcting Claude's
|
|
518
|
+
* understanding or actions.
|
|
519
|
+
*
|
|
520
|
+
* @param signals - Messages and context to analyze
|
|
521
|
+
* @returns Detected correction or null if none found
|
|
522
|
+
*/
|
|
523
|
+
declare function detectUserCorrection(signals: CorrectionSignal): DetectedCorrection | null;
|
|
524
|
+
/** Edit history entry */
|
|
525
|
+
interface EditEntry {
|
|
526
|
+
file: string;
|
|
527
|
+
success: boolean;
|
|
528
|
+
timestamp: number;
|
|
529
|
+
}
|
|
530
|
+
/** Edit history for self-correction detection */
|
|
531
|
+
interface EditHistory {
|
|
532
|
+
edits: EditEntry[];
|
|
533
|
+
}
|
|
534
|
+
/** Detected self-correction */
|
|
535
|
+
interface DetectedSelfCorrection {
|
|
536
|
+
file: string;
|
|
537
|
+
trigger: string;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Detect self-correction patterns in edit history.
|
|
541
|
+
*
|
|
542
|
+
* Looks for edit→fail→re-edit patterns on the same file,
|
|
543
|
+
* which indicate Claude had to correct its own work.
|
|
544
|
+
*
|
|
545
|
+
* @param history - Edit history to analyze
|
|
546
|
+
* @returns Detected self-correction or null if none found
|
|
547
|
+
*/
|
|
548
|
+
declare function detectSelfCorrection(history: EditHistory): DetectedSelfCorrection | null;
|
|
549
|
+
/** Test result for failure detection */
|
|
550
|
+
interface TestResult {
|
|
551
|
+
passed: boolean;
|
|
552
|
+
output: string;
|
|
553
|
+
testFile: string;
|
|
554
|
+
}
|
|
555
|
+
/** Detected test failure */
|
|
556
|
+
interface DetectedTestFailure {
|
|
557
|
+
testFile: string;
|
|
558
|
+
errorOutput: string;
|
|
559
|
+
trigger: string;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Detect test failure patterns.
|
|
563
|
+
*
|
|
564
|
+
* When tests fail, this creates a potential learning opportunity
|
|
565
|
+
* if the failure is later fixed.
|
|
566
|
+
*
|
|
567
|
+
* @param testResult - Test result to analyze
|
|
568
|
+
* @returns Detected test failure or null if tests passed
|
|
569
|
+
*/
|
|
570
|
+
declare function detectTestFailure(testResult: TestResult): DetectedTestFailure | null;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Session-start lesson retrieval
|
|
574
|
+
*
|
|
575
|
+
* Loads high-severity lessons at the start of a session.
|
|
576
|
+
* No vector search - just filter by severity and recency.
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/** A memory item with severity field present */
|
|
580
|
+
type LessonWithSeverity = MemoryItem & {
|
|
581
|
+
severity: Severity;
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* Load high-severity lessons for session start.
|
|
585
|
+
*
|
|
586
|
+
* Returns confirmed, high-severity lessons sorted by recency.
|
|
587
|
+
* These are the most important lessons to surface at the start
|
|
588
|
+
* of a coding session.
|
|
589
|
+
*
|
|
590
|
+
* @param repoRoot - Repository root directory
|
|
591
|
+
* @param limit - Maximum number of lessons to return (default: 5)
|
|
592
|
+
* @returns Array of high-severity lessons, most recent first
|
|
593
|
+
*/
|
|
594
|
+
declare function loadSessionLessons(repoRoot: string, limit?: number): Promise<LessonWithSeverity[]>;
|
|
595
|
+
/**
|
|
596
|
+
* @deprecated Use loadSessionMemory. Backward-compat alias.
|
|
597
|
+
*/
|
|
598
|
+
declare const loadSessionMemory: typeof loadSessionLessons;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Plan-time lesson retrieval
|
|
602
|
+
*
|
|
603
|
+
* Retrieves relevant lessons when planning an implementation.
|
|
604
|
+
* Uses vector search to find semantically similar lessons.
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
/** Result of plan-time retrieval */
|
|
608
|
+
interface PlanRetrievalResult {
|
|
609
|
+
lessons: RankedLesson[];
|
|
610
|
+
message: string;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Retrieve relevant lessons for a plan.
|
|
614
|
+
*
|
|
615
|
+
* Uses vector search to find semantically similar lessons,
|
|
616
|
+
* then applies ranking boosts for severity, recency, and confirmation.
|
|
617
|
+
*
|
|
618
|
+
* Hard-fails if embeddings are unavailable (propagates error from embedText).
|
|
619
|
+
*
|
|
620
|
+
* @param repoRoot - Repository root directory
|
|
621
|
+
* @param planText - The plan text to search against
|
|
622
|
+
* @param limit - Maximum number of lessons to return (default: 5)
|
|
623
|
+
* @returns Ranked lessons and formatted message
|
|
624
|
+
*/
|
|
625
|
+
declare function retrieveForPlan(repoRoot: string, planText: string, limit?: number): Promise<PlanRetrievalResult>;
|
|
626
|
+
/**
|
|
627
|
+
* Format a "Lessons Check" message for display.
|
|
628
|
+
*
|
|
629
|
+
* This message is intended to be shown at plan-time to remind
|
|
630
|
+
* the developer of relevant lessons before implementation.
|
|
631
|
+
*
|
|
632
|
+
* @param lessons - Ranked lessons to include in the message
|
|
633
|
+
* @returns Formatted message string
|
|
634
|
+
*/
|
|
635
|
+
declare function formatLessonsCheck(lessons: ScoredLesson[]): string;
|
|
636
|
+
/**
|
|
637
|
+
* @deprecated Use formatMemoryCheck. Backward-compat alias.
|
|
638
|
+
*/
|
|
639
|
+
declare const formatMemoryCheck: typeof formatLessonsCheck;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Prime command - Context recovery for Claude Code with Beads-style trust language.
|
|
643
|
+
*
|
|
644
|
+
* Generates trust language guidelines combined with high-severity lessons
|
|
645
|
+
* for context recovery after compaction or session restart.
|
|
646
|
+
*/
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Generate prime context output for Claude Code.
|
|
650
|
+
*
|
|
651
|
+
* Combines Beads-style trust language guidelines with high-severity lessons
|
|
652
|
+
* for context recovery after compaction or session restart.
|
|
653
|
+
*
|
|
654
|
+
* @param repoRoot - Repository root directory (defaults to getRepoRoot())
|
|
655
|
+
* @returns Formatted markdown string (< 2K tokens)
|
|
656
|
+
*/
|
|
657
|
+
declare function getPrimeContext(repoRoot?: string): Promise<string>;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Audit module types and Zod schemas.
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
/** Schema for a single audit finding. */
|
|
664
|
+
declare const AuditFindingSchema: z.ZodObject<{
|
|
665
|
+
file: z.ZodString;
|
|
666
|
+
issue: z.ZodString;
|
|
667
|
+
severity: z.ZodEnum<["error", "warning", "info"]>;
|
|
668
|
+
relatedLessonId: z.ZodOptional<z.ZodString>;
|
|
669
|
+
suggestedFix: z.ZodOptional<z.ZodString>;
|
|
670
|
+
source: z.ZodEnum<["rule", "pattern", "lesson"]>;
|
|
671
|
+
}, "strip", z.ZodTypeAny, {
|
|
672
|
+
file: string;
|
|
673
|
+
source: "lesson" | "pattern" | "rule";
|
|
674
|
+
severity: "error" | "warning" | "info";
|
|
675
|
+
issue: string;
|
|
676
|
+
relatedLessonId?: string | undefined;
|
|
677
|
+
suggestedFix?: string | undefined;
|
|
678
|
+
}, {
|
|
679
|
+
file: string;
|
|
680
|
+
source: "lesson" | "pattern" | "rule";
|
|
681
|
+
severity: "error" | "warning" | "info";
|
|
682
|
+
issue: string;
|
|
683
|
+
relatedLessonId?: string | undefined;
|
|
684
|
+
suggestedFix?: string | undefined;
|
|
685
|
+
}>;
|
|
686
|
+
/** Schema for a complete audit report. */
|
|
687
|
+
declare const AuditReportSchema: z.ZodObject<{
|
|
688
|
+
findings: z.ZodArray<z.ZodObject<{
|
|
689
|
+
file: z.ZodString;
|
|
690
|
+
issue: z.ZodString;
|
|
691
|
+
severity: z.ZodEnum<["error", "warning", "info"]>;
|
|
692
|
+
relatedLessonId: z.ZodOptional<z.ZodString>;
|
|
693
|
+
suggestedFix: z.ZodOptional<z.ZodString>;
|
|
694
|
+
source: z.ZodEnum<["rule", "pattern", "lesson"]>;
|
|
695
|
+
}, "strip", z.ZodTypeAny, {
|
|
696
|
+
file: string;
|
|
697
|
+
source: "lesson" | "pattern" | "rule";
|
|
698
|
+
severity: "error" | "warning" | "info";
|
|
699
|
+
issue: string;
|
|
700
|
+
relatedLessonId?: string | undefined;
|
|
701
|
+
suggestedFix?: string | undefined;
|
|
702
|
+
}, {
|
|
703
|
+
file: string;
|
|
704
|
+
source: "lesson" | "pattern" | "rule";
|
|
705
|
+
severity: "error" | "warning" | "info";
|
|
706
|
+
issue: string;
|
|
707
|
+
relatedLessonId?: string | undefined;
|
|
708
|
+
suggestedFix?: string | undefined;
|
|
709
|
+
}>, "many">;
|
|
710
|
+
summary: z.ZodObject<{
|
|
711
|
+
errors: z.ZodNumber;
|
|
712
|
+
warnings: z.ZodNumber;
|
|
713
|
+
infos: z.ZodNumber;
|
|
714
|
+
filesChecked: z.ZodNumber;
|
|
715
|
+
}, "strip", z.ZodTypeAny, {
|
|
716
|
+
errors: number;
|
|
717
|
+
warnings: number;
|
|
718
|
+
infos: number;
|
|
719
|
+
filesChecked: number;
|
|
720
|
+
}, {
|
|
721
|
+
errors: number;
|
|
722
|
+
warnings: number;
|
|
723
|
+
infos: number;
|
|
724
|
+
filesChecked: number;
|
|
725
|
+
}>;
|
|
726
|
+
timestamp: z.ZodString;
|
|
727
|
+
}, "strip", z.ZodTypeAny, {
|
|
728
|
+
timestamp: string;
|
|
729
|
+
findings: {
|
|
730
|
+
file: string;
|
|
731
|
+
source: "lesson" | "pattern" | "rule";
|
|
732
|
+
severity: "error" | "warning" | "info";
|
|
733
|
+
issue: string;
|
|
734
|
+
relatedLessonId?: string | undefined;
|
|
735
|
+
suggestedFix?: string | undefined;
|
|
736
|
+
}[];
|
|
737
|
+
summary: {
|
|
738
|
+
errors: number;
|
|
739
|
+
warnings: number;
|
|
740
|
+
infos: number;
|
|
741
|
+
filesChecked: number;
|
|
742
|
+
};
|
|
743
|
+
}, {
|
|
744
|
+
timestamp: string;
|
|
745
|
+
findings: {
|
|
746
|
+
file: string;
|
|
747
|
+
source: "lesson" | "pattern" | "rule";
|
|
748
|
+
severity: "error" | "warning" | "info";
|
|
749
|
+
issue: string;
|
|
750
|
+
relatedLessonId?: string | undefined;
|
|
751
|
+
suggestedFix?: string | undefined;
|
|
752
|
+
}[];
|
|
753
|
+
summary: {
|
|
754
|
+
errors: number;
|
|
755
|
+
warnings: number;
|
|
756
|
+
infos: number;
|
|
757
|
+
filesChecked: number;
|
|
758
|
+
};
|
|
759
|
+
}>;
|
|
760
|
+
type AuditFinding = z.infer<typeof AuditFindingSchema>;
|
|
761
|
+
type AuditReport = z.infer<typeof AuditReportSchema>;
|
|
762
|
+
/** Options to toggle individual audit checks. */
|
|
763
|
+
interface AuditOptions {
|
|
764
|
+
includeRules?: boolean;
|
|
765
|
+
includePatterns?: boolean;
|
|
766
|
+
includeLessons?: boolean;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Audit engine: orchestrates checks and builds report.
|
|
771
|
+
*/
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Run audit checks and build a report.
|
|
775
|
+
*
|
|
776
|
+
* @param repoRoot - Repository root directory
|
|
777
|
+
* @param options - Toggle individual checks (all enabled by default)
|
|
778
|
+
* @returns Complete audit report with findings and summary
|
|
779
|
+
*/
|
|
780
|
+
declare function runAudit(repoRoot: string, options?: AuditOptions): Promise<AuditReport>;
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Types for the compounding module.
|
|
784
|
+
*
|
|
785
|
+
* CctPattern represents a cross-cutting pattern synthesized
|
|
786
|
+
* from multiple similar lessons.
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
/** Relative path to CCT patterns file from repo root */
|
|
790
|
+
declare const CCT_PATTERNS_PATH = ".claude/lessons/cct-patterns.jsonl";
|
|
791
|
+
/** Schema for a cross-cutting pattern */
|
|
792
|
+
declare const CctPatternSchema: z.ZodObject<{
|
|
793
|
+
id: z.ZodString;
|
|
794
|
+
name: z.ZodString;
|
|
795
|
+
description: z.ZodString;
|
|
796
|
+
frequency: z.ZodNumber;
|
|
797
|
+
testable: z.ZodBoolean;
|
|
798
|
+
testApproach: z.ZodOptional<z.ZodString>;
|
|
799
|
+
sourceIds: z.ZodArray<z.ZodString, "many">;
|
|
800
|
+
created: z.ZodString;
|
|
801
|
+
}, "strip", z.ZodTypeAny, {
|
|
802
|
+
id: string;
|
|
803
|
+
created: string;
|
|
804
|
+
name: string;
|
|
805
|
+
description: string;
|
|
806
|
+
frequency: number;
|
|
807
|
+
testable: boolean;
|
|
808
|
+
sourceIds: string[];
|
|
809
|
+
testApproach?: string | undefined;
|
|
810
|
+
}, {
|
|
811
|
+
id: string;
|
|
812
|
+
created: string;
|
|
813
|
+
name: string;
|
|
814
|
+
description: string;
|
|
815
|
+
frequency: number;
|
|
816
|
+
testable: boolean;
|
|
817
|
+
sourceIds: string[];
|
|
818
|
+
testApproach?: string | undefined;
|
|
819
|
+
}>;
|
|
820
|
+
/** Inferred type from CctPatternSchema */
|
|
821
|
+
type CctPattern = z.infer<typeof CctPatternSchema>;
|
|
822
|
+
/** Result from clustering operation */
|
|
823
|
+
interface ClusterResult {
|
|
824
|
+
/** Groups of similar items */
|
|
825
|
+
clusters: MemoryItem[][];
|
|
826
|
+
/** Items that didn't fit any cluster */
|
|
827
|
+
noise: MemoryItem[];
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Clustering module for grouping similar memory items.
|
|
832
|
+
*
|
|
833
|
+
* Uses single-linkage agglomerative clustering with cosine similarity.
|
|
834
|
+
*/
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Build a pairwise cosine similarity matrix from embedding vectors.
|
|
838
|
+
*
|
|
839
|
+
* @param embeddings - Array of embedding vectors
|
|
840
|
+
* @returns NxN similarity matrix
|
|
841
|
+
*/
|
|
842
|
+
declare function buildSimilarityMatrix(embeddings: number[][]): number[][];
|
|
843
|
+
/**
|
|
844
|
+
* Cluster memory items by embedding similarity using single-linkage
|
|
845
|
+
* agglomerative clustering.
|
|
846
|
+
*
|
|
847
|
+
* @param items - Memory items to cluster
|
|
848
|
+
* @param embeddings - Embedding vectors (same order as items)
|
|
849
|
+
* @param threshold - Minimum similarity to merge clusters (default: 0.75)
|
|
850
|
+
* @returns Clusters of similar items and noise (unclustered items)
|
|
851
|
+
*/
|
|
852
|
+
declare function clusterBySimilarity(items: MemoryItem[], embeddings: number[][], threshold?: number): ClusterResult;
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* I/O module for CctPattern persistence.
|
|
856
|
+
*
|
|
857
|
+
* Append-only JSONL storage, following the same pattern as
|
|
858
|
+
* src/memory/storage/jsonl.ts.
|
|
859
|
+
*/
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Read all CCT patterns from the JSONL file.
|
|
863
|
+
*
|
|
864
|
+
* @param repoRoot - Repository root directory
|
|
865
|
+
* @returns Array of CctPattern objects
|
|
866
|
+
*/
|
|
867
|
+
declare function readCctPatterns(repoRoot: string): Promise<CctPattern[]>;
|
|
868
|
+
/**
|
|
869
|
+
* Append CCT patterns to the JSONL file (append-only).
|
|
870
|
+
*
|
|
871
|
+
* @param repoRoot - Repository root directory
|
|
872
|
+
* @param patterns - Patterns to append
|
|
873
|
+
*/
|
|
874
|
+
declare function writeCctPatterns(repoRoot: string, patterns: CctPattern[]): Promise<void>;
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Synthesis module for extracting cross-cutting patterns from clusters.
|
|
878
|
+
*
|
|
879
|
+
* Takes a cluster of similar memory items and produces a CctPattern
|
|
880
|
+
* summarizing the common theme.
|
|
881
|
+
*/
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Synthesize a CctPattern from a cluster of similar memory items.
|
|
885
|
+
*
|
|
886
|
+
* @param cluster - Group of similar memory items
|
|
887
|
+
* @param clusterId - Identifier for this cluster (used for ID generation)
|
|
888
|
+
* @returns A CctPattern summarizing the cluster
|
|
889
|
+
*/
|
|
890
|
+
declare function synthesizePattern(cluster: MemoryItem[], clusterId: string): CctPattern;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Compound Agent - Repository-scoped learning system for Claude Code
|
|
894
|
+
*
|
|
895
|
+
* This package helps Claude Code learn from mistakes and avoid repeating them.
|
|
896
|
+
* It captures lessons during coding sessions and retrieves relevant lessons
|
|
897
|
+
* when planning new work.
|
|
898
|
+
*
|
|
899
|
+
* ## Quick Start
|
|
900
|
+
*
|
|
901
|
+
* ```typescript
|
|
902
|
+
* import { appendLesson, retrieveForPlan, loadSessionLessons } from 'compound-agent';
|
|
903
|
+
*
|
|
904
|
+
* // At session start, load high-severity lessons
|
|
905
|
+
* const criticalLessons = await loadSessionLessons(repoRoot);
|
|
906
|
+
*
|
|
907
|
+
* // When planning, retrieve relevant lessons
|
|
908
|
+
* const { lessons, message } = await retrieveForPlan(repoRoot, planText);
|
|
909
|
+
*
|
|
910
|
+
* // When capturing a lesson
|
|
911
|
+
* await appendLesson(repoRoot, lesson);
|
|
912
|
+
* ```
|
|
913
|
+
*
|
|
914
|
+
* ## Setup
|
|
915
|
+
*
|
|
916
|
+
* Run `npx ca init` in your project root to configure hooks and AGENTS.md.
|
|
917
|
+
*
|
|
918
|
+
* ## Resource Management
|
|
919
|
+
*
|
|
920
|
+
* This library manages two heavyweight resources that require cleanup:
|
|
921
|
+
*
|
|
922
|
+
* ### SQLite Database
|
|
923
|
+
* - **Acquired:** Lazily on first database operation (search, rebuild, etc.)
|
|
924
|
+
* - **Memory:** Minimal (~few KB for connection, index cached by OS)
|
|
925
|
+
* - **Cleanup:** Call `closeDb()` before process exit
|
|
926
|
+
*
|
|
927
|
+
* ### Embedding Model
|
|
928
|
+
* - **Acquired:** Lazily on first embedding call (embedText, embedTexts, searchVector)
|
|
929
|
+
* - **Memory:** ~150MB RAM for the EmbeddingGemma model
|
|
930
|
+
* - **Cleanup:** Call `unloadEmbedding()` before process exit
|
|
931
|
+
*
|
|
932
|
+
* ### Recommended Cleanup Pattern
|
|
933
|
+
*
|
|
934
|
+
* ```typescript
|
|
935
|
+
* import { closeDb, unloadEmbedding } from 'compound-agent';
|
|
936
|
+
*
|
|
937
|
+
* // For CLI commands - use try/finally
|
|
938
|
+
* async function main() {
|
|
939
|
+
* try {
|
|
940
|
+
* // ... your code that uses compound-agent
|
|
941
|
+
* } finally {
|
|
942
|
+
* unloadEmbedding();
|
|
943
|
+
* closeDb();
|
|
944
|
+
* }
|
|
945
|
+
* }
|
|
946
|
+
*
|
|
947
|
+
* // For long-running processes - use shutdown handlers
|
|
948
|
+
* process.on('SIGTERM', () => {
|
|
949
|
+
* unloadEmbedding();
|
|
950
|
+
* closeDb();
|
|
951
|
+
* process.exit(0);
|
|
952
|
+
* });
|
|
953
|
+
* process.on('SIGINT', () => {
|
|
954
|
+
* unloadEmbedding();
|
|
955
|
+
* closeDb();
|
|
956
|
+
* process.exit(0);
|
|
957
|
+
* });
|
|
958
|
+
* ```
|
|
959
|
+
*
|
|
960
|
+
* **Note:** Failing to clean up will not corrupt data, but may cause:
|
|
961
|
+
* - Memory leaks in long-running processes
|
|
962
|
+
* - Unclean process exits (warnings in some environments)
|
|
963
|
+
*
|
|
964
|
+
* @see {@link closeDb} for database cleanup
|
|
965
|
+
* @see {@link unloadEmbedding} for embedding model cleanup
|
|
966
|
+
* @module compound-agent
|
|
967
|
+
*/
|
|
968
|
+
/** Package version, read from package.json. */
|
|
969
|
+
declare const VERSION: string;
|
|
970
|
+
|
|
971
|
+
export { type ActionabilityResult, type AuditFinding, AuditFindingSchema, type AuditOptions, type AuditReport, AuditReportSchema, CCT_PATTERNS_PATH, type CctPattern, CctPatternSchema, type ClusterResult, Context, type CorrectionSignal, DB_PATH, type DetectedCorrection, type DetectedSelfCorrection, type DetectedTestFailure, type EditEntry, type EditHistory, LESSONS_PATH, Lesson, MODEL_FILENAME, MODEL_URI, MemoryItem, MemoryItemType, type NoveltyOptions, type NoveltyResult, type ParseError, type PlanRetrievalResult, type ProposeResult, type RankedLesson, type RankedMemoryItem, type ReadLessonsOptions, type ReadLessonsResult, type ReadMemoryItemsResult, type ScoredLesson, type ScoredMemoryItem, type SearchVectorOptions, Severity, type SpecificityResult, type TestResult, type UsabilityResult, VERSION, appendLesson, appendMemoryItem, buildSimilarityMatrix, calculateScore, closeDb, clusterBySimilarity, confirmationBoost, cosineSimilarity, detectSelfCorrection, detectTestFailure, detectUserCorrection, embedText, embedTexts, formatLessonsCheck, formatMemoryCheck, getEmbedding, getPrimeContext, isActionable, isModelAvailable, isModelUsable, isNovel, isSpecific, loadSessionLessons, loadSessionMemory, rankLessons, rankMemoryItems, readCctPatterns, readLessons, readMemoryItems, rebuildIndex, recencyBoost, resolveModel, retrieveForPlan, runAudit, searchKeyword, searchVector, severityBoost, shouldPropose, synthesizePattern, unloadEmbedding, writeCctPatterns };
|