@membank/core 0.9.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +33 -820
- package/dist/index.d.cts +255 -58
- package/dist/index.d.mts +255 -58
- package/dist/index.mjs +33 -764
- package/package.json +4 -2
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
import BetterSqlite3 from "better-sqlite3";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import BetterSqlite3 from "better-sqlite3";
|
|
3
|
+
import { EventEmitter } from "node:events";
|
|
3
4
|
|
|
4
5
|
//#region src/config/loader.d.ts
|
|
5
6
|
declare function isSynthesisEnabled(): boolean;
|
|
6
7
|
//#endregion
|
|
7
|
-
//#region src/db/errors.d.ts
|
|
8
|
-
declare class MembankError extends Error {
|
|
9
|
-
constructor(message: string, options?: ErrorOptions);
|
|
10
|
-
}
|
|
11
|
-
declare class DatabaseError extends MembankError {
|
|
12
|
-
constructor(message: string, options?: ErrorOptions);
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/db/manager.d.ts
|
|
16
|
-
type VecLoader = (db: BetterSqlite3.Database) => void;
|
|
17
|
-
declare class DatabaseManager {
|
|
18
|
-
#private;
|
|
19
|
-
private constructor();
|
|
20
|
-
static open(dbPath?: string): DatabaseManager;
|
|
21
|
-
static openInMemory(): DatabaseManager;
|
|
22
|
-
/** For testing: inject a custom vec loader (e.g. a throwing stub). */
|
|
23
|
-
static _openInMemoryWithLoader(loader: VecLoader): DatabaseManager;
|
|
24
|
-
get db(): BetterSqlite3.Database;
|
|
25
|
-
close(): void;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
8
|
//#region src/schemas.d.ts
|
|
29
9
|
declare const MEMORY_TYPE_VALUES: readonly ["correction", "preference", "decision", "learning", "fact"];
|
|
30
10
|
declare const MemoryTypeSchema: z.ZodEnum<{
|
|
@@ -270,16 +250,133 @@ declare const ProjectRowSchema: z.ZodObject<{
|
|
|
270
250
|
}, z.core.$strip>;
|
|
271
251
|
type ProjectRow = z.infer<typeof ProjectRowSchema>;
|
|
272
252
|
//#endregion
|
|
273
|
-
//#region src/
|
|
253
|
+
//#region src/persistence/infrastructure/row-types.d.ts
|
|
274
254
|
declare function rowToMemory(row: MemoryRow, projects: Project[], reviewEvents?: ReviewEvent[]): Memory;
|
|
275
255
|
declare function rowToProject(row: ProjectRow): Project;
|
|
276
256
|
//#endregion
|
|
277
|
-
//#region src/
|
|
257
|
+
//#region src/db/errors.d.ts
|
|
258
|
+
declare class MembankError extends Error {
|
|
259
|
+
constructor(message: string, options?: ErrorOptions);
|
|
260
|
+
}
|
|
261
|
+
declare class DatabaseError extends MembankError {
|
|
262
|
+
constructor(message: string, options?: ErrorOptions);
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/db/manager.d.ts
|
|
266
|
+
type VecLoader = (db: BetterSqlite3.Database) => void;
|
|
267
|
+
declare class DatabaseManager {
|
|
268
|
+
#private;
|
|
269
|
+
private constructor();
|
|
270
|
+
static open(dbPath?: string): DatabaseManager;
|
|
271
|
+
static openInMemory(): DatabaseManager;
|
|
272
|
+
/** For testing: inject a custom vec loader (e.g. a throwing stub). */
|
|
273
|
+
static _openInMemoryWithLoader(loader: VecLoader): DatabaseManager;
|
|
274
|
+
get db(): BetterSqlite3.Database;
|
|
275
|
+
close(): void;
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/embedding/infrastructure/model-downloader.d.ts
|
|
279
|
+
declare const MODEL_NAME = "Xenova/bge-small-en-v1.5";
|
|
280
|
+
interface DownloadProgress {
|
|
281
|
+
totalBytes: number;
|
|
282
|
+
downloadedBytes: number;
|
|
283
|
+
percentage: number;
|
|
284
|
+
estimatedSecondsRemaining: number;
|
|
285
|
+
}
|
|
286
|
+
interface DownloadResult {
|
|
287
|
+
skipped: boolean;
|
|
288
|
+
}
|
|
289
|
+
declare class ModelDownloadError extends Error {
|
|
290
|
+
constructor(message: string, options?: ErrorOptions);
|
|
291
|
+
}
|
|
292
|
+
declare class ModelDownloader extends EventEmitter {
|
|
293
|
+
private readonly modelPath;
|
|
294
|
+
constructor(modelPath?: string);
|
|
295
|
+
isAlreadyCached(): boolean;
|
|
296
|
+
get cachePath(): string;
|
|
297
|
+
download(): Promise<DownloadResult>;
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region src/memory/ports.d.ts
|
|
301
|
+
interface SimilarMemoryResult {
|
|
302
|
+
id: string;
|
|
303
|
+
similarity: number;
|
|
304
|
+
}
|
|
305
|
+
interface StatsResult {
|
|
306
|
+
byType: Record<MemoryType, number>;
|
|
307
|
+
total: number;
|
|
308
|
+
pinned: number;
|
|
309
|
+
needsReview: number;
|
|
310
|
+
pinBudgetChars: number;
|
|
311
|
+
}
|
|
312
|
+
interface MemoryExportRecord {
|
|
313
|
+
id: string;
|
|
314
|
+
content: string;
|
|
315
|
+
type: MemoryType;
|
|
316
|
+
tags: string[];
|
|
317
|
+
sourceHarness: string | null;
|
|
318
|
+
accessCount: number;
|
|
319
|
+
pinned: boolean;
|
|
320
|
+
createdAt: string;
|
|
321
|
+
updatedAt: string;
|
|
322
|
+
embedding: Float32Array | null;
|
|
323
|
+
}
|
|
324
|
+
interface CreateMemoryOpts {
|
|
325
|
+
id: string;
|
|
326
|
+
content: string;
|
|
327
|
+
type: MemoryType;
|
|
328
|
+
tags: string[];
|
|
329
|
+
sourceHarness: string | null;
|
|
330
|
+
embedding: Float32Array;
|
|
331
|
+
projectScope?: {
|
|
332
|
+
hash: string;
|
|
333
|
+
name: string;
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
interface CreateReviewEventOpts {
|
|
337
|
+
memoryId: string;
|
|
338
|
+
conflictingMemoryId: string;
|
|
339
|
+
similarity: number;
|
|
340
|
+
conflictContentSnapshot: string;
|
|
341
|
+
}
|
|
342
|
+
interface MemoryRepository {
|
|
343
|
+
findById(id: string): Memory | undefined;
|
|
344
|
+
findSimilar(embedding: Float32Array, type: MemoryType, projectHash?: string): SimilarMemoryResult[];
|
|
345
|
+
list(opts?: {
|
|
346
|
+
type?: MemoryType;
|
|
347
|
+
pinned?: boolean;
|
|
348
|
+
needsReview?: boolean;
|
|
349
|
+
projectId?: string;
|
|
350
|
+
}): Memory[];
|
|
351
|
+
listPinnedGlobal(): Memory[];
|
|
352
|
+
listPinnedForProject(projectHash: string): Memory[];
|
|
353
|
+
listFlagged(): Memory[];
|
|
354
|
+
listReviewEvents(memoryId: string, opts?: {
|
|
355
|
+
unresolvedOnly?: boolean;
|
|
356
|
+
}): ReviewEvent[];
|
|
357
|
+
getPinnedCharCount(): number;
|
|
358
|
+
stats(): StatsResult;
|
|
359
|
+
create(opts: CreateMemoryOpts): Memory;
|
|
360
|
+
overwrite(id: string, content: string, embedding: Float32Array): Memory;
|
|
361
|
+
update(id: string, patch: MemoryPatch, embedding?: Float32Array): Memory;
|
|
362
|
+
delete(id: string): void;
|
|
363
|
+
createReviewEvent(opts: CreateReviewEventOpts): void;
|
|
364
|
+
resolveReviewEvents(memoryId: string): void;
|
|
365
|
+
setPin(id: string, pinned: boolean): Memory;
|
|
366
|
+
incrementAccessCount(id: string): void;
|
|
367
|
+
exportAll(): MemoryExportRecord[];
|
|
368
|
+
importAll(records: MemoryExportRecord[]): void;
|
|
369
|
+
}
|
|
370
|
+
interface Embedder {
|
|
371
|
+
embed(text: string): Promise<Float32Array>;
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/embedding/infrastructure/huggingface-embedding-service.d.ts
|
|
278
375
|
type ProgressCallback = (progress: {
|
|
279
376
|
status: string;
|
|
280
377
|
progress?: number;
|
|
281
378
|
}) => void;
|
|
282
|
-
declare class EmbeddingService {
|
|
379
|
+
declare class EmbeddingService implements Embedder {
|
|
283
380
|
private readonly modelCachePath;
|
|
284
381
|
private readonly onProgress;
|
|
285
382
|
private pipelineInstance;
|
|
@@ -288,10 +385,30 @@ declare class EmbeddingService {
|
|
|
288
385
|
embed(text: string): Promise<Float32Array>;
|
|
289
386
|
}
|
|
290
387
|
//#endregion
|
|
291
|
-
//#region src/
|
|
292
|
-
declare
|
|
293
|
-
|
|
294
|
-
|
|
388
|
+
//#region src/memory/application/delete-memory.d.ts
|
|
389
|
+
declare function deleteMemory(id: string, repo: MemoryRepository): Promise<void>;
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/memory/application/resolve-review.d.ts
|
|
392
|
+
declare function resolveReview(memoryId: string, repo: MemoryRepository): void;
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/memory/application/save-memory.d.ts
|
|
395
|
+
declare function saveMemory(opts: SaveOptions, deps: {
|
|
396
|
+
repo: MemoryRepository;
|
|
397
|
+
embedder: Embedder;
|
|
398
|
+
}): Promise<Memory>;
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/memory/application/update-memory.d.ts
|
|
401
|
+
declare function updateMemory(id: string, patch: MemoryPatch, deps: {
|
|
402
|
+
repo: MemoryRepository;
|
|
403
|
+
embedder: Embedder;
|
|
404
|
+
}): Promise<Memory>;
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/memory/domain/pin-budget.d.ts
|
|
407
|
+
declare const PIN_BUDGET_THRESHOLD = 8000;
|
|
408
|
+
declare function isOverBudget(pinnedCharCount: number): boolean;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/project/ports.d.ts
|
|
411
|
+
interface ProjectRepository {
|
|
295
412
|
upsertByHash(hash: string, name: string): Project;
|
|
296
413
|
rename(id: string, name: string): Project;
|
|
297
414
|
list(): Project[];
|
|
@@ -303,34 +420,41 @@ declare class ProjectRepository {
|
|
|
303
420
|
getProjectsForMemories(memoryIds: string[]): Map<string, Project[]>;
|
|
304
421
|
}
|
|
305
422
|
//#endregion
|
|
306
|
-
//#region src/memory/repository.d.ts
|
|
307
|
-
declare
|
|
308
|
-
declare class MemoryRepository {
|
|
423
|
+
//#region src/memory/infrastructure/sqlite-memory-repository.d.ts
|
|
424
|
+
declare class SqliteMemoryRepository implements MemoryRepository {
|
|
309
425
|
#private;
|
|
310
|
-
constructor(db: DatabaseManager,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
426
|
+
constructor(db: DatabaseManager, projects: ProjectRepository);
|
|
427
|
+
findSimilar(embedding: Float32Array, type: MemoryType, projectHash?: string): SimilarMemoryResult[];
|
|
428
|
+
create(opts: CreateMemoryOpts): Memory;
|
|
429
|
+
overwrite(id: string, content: string, embedding: Float32Array): Memory;
|
|
430
|
+
findById(id: string): Memory | undefined;
|
|
431
|
+
update(id: string, patch: MemoryPatch, embedding?: Float32Array): Memory;
|
|
432
|
+
delete(id: string): void;
|
|
314
433
|
list(opts?: {
|
|
315
434
|
type?: MemoryType;
|
|
316
435
|
pinned?: boolean;
|
|
436
|
+
needsReview?: boolean;
|
|
437
|
+
projectId?: string;
|
|
317
438
|
}): Memory[];
|
|
439
|
+
listPinnedGlobal(): Memory[];
|
|
440
|
+
listPinnedForProject(projectHash: string): Memory[];
|
|
318
441
|
listFlagged(): Memory[];
|
|
319
442
|
listReviewEvents(memoryId: string, opts?: {
|
|
320
443
|
unresolvedOnly?: boolean;
|
|
321
444
|
}): ReviewEvent[];
|
|
445
|
+
createReviewEvent(opts: CreateReviewEventOpts): void;
|
|
322
446
|
resolveReviewEvents(memoryId: string): void;
|
|
323
447
|
getPinnedCharCount(): number;
|
|
324
|
-
stats():
|
|
325
|
-
byType: Record<MemoryType, number>;
|
|
326
|
-
total: number;
|
|
327
|
-
pinned: number;
|
|
328
|
-
needsReview: number;
|
|
329
|
-
pinBudgetChars: number;
|
|
330
|
-
};
|
|
448
|
+
stats(): StatsResult;
|
|
331
449
|
setPin(id: string, pinned: boolean): Memory;
|
|
332
450
|
incrementAccessCount(id: string): void;
|
|
451
|
+
exportAll(): MemoryExportRecord[];
|
|
452
|
+
importAll(records: MemoryExportRecord[]): void;
|
|
333
453
|
}
|
|
454
|
+
declare function createMemoryRepository(db: DatabaseManager, projects: ProjectRepository): MemoryRepository;
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/project/infrastructure/sqlite-project-repository.d.ts
|
|
457
|
+
declare function createProjectRepository(db: DatabaseManager): ProjectRepository;
|
|
334
458
|
//#endregion
|
|
335
459
|
//#region src/migrations/index.d.ts
|
|
336
460
|
interface MigrationMeta {
|
|
@@ -346,13 +470,35 @@ interface ScopeToProjectsResult {
|
|
|
346
470
|
declare const MIGRATIONS: MigrationMeta[];
|
|
347
471
|
declare function runScopeToProjectsMigration(projects: ProjectRepository): Promise<ScopeToProjectsResult | null>;
|
|
348
472
|
//#endregion
|
|
473
|
+
//#region src/query/ports.d.ts
|
|
474
|
+
interface ScoredMemory extends Memory {
|
|
475
|
+
score: number;
|
|
476
|
+
}
|
|
477
|
+
interface QueryAdapter {
|
|
478
|
+
findByEmbedding(embedding: Buffer, opts: {
|
|
479
|
+
type?: MemoryType;
|
|
480
|
+
projectHash?: string;
|
|
481
|
+
includePinned?: boolean;
|
|
482
|
+
}): Array<Memory & {
|
|
483
|
+
cosineSim: number;
|
|
484
|
+
}>;
|
|
485
|
+
}
|
|
486
|
+
interface Querier {
|
|
487
|
+
query(opts: QueryOptions): Promise<ScoredMemory[]>;
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/query/application/query-memories.d.ts
|
|
491
|
+
declare function queryMemories(options: QueryOptions, deps: {
|
|
492
|
+
adapter: QueryAdapter;
|
|
493
|
+
repo: Pick<MemoryRepository, "incrementAccessCount">;
|
|
494
|
+
embedder: Embedder;
|
|
495
|
+
}): Promise<ScoredMemory[]>;
|
|
496
|
+
//#endregion
|
|
349
497
|
//#region src/query/engine.d.ts
|
|
350
|
-
declare class QueryEngine {
|
|
498
|
+
declare class QueryEngine implements Querier {
|
|
351
499
|
#private;
|
|
352
|
-
constructor(db: DatabaseManager, embeddingService:
|
|
353
|
-
query(options: QueryOptions): Promise<
|
|
354
|
-
score: number;
|
|
355
|
-
}>>;
|
|
500
|
+
constructor(db: DatabaseManager, embeddingService: Embedder, repo: MemoryRepository);
|
|
501
|
+
query(options: QueryOptions): Promise<ScoredMemory[]>;
|
|
356
502
|
}
|
|
357
503
|
//#endregion
|
|
358
504
|
//#region src/scope/resolver.d.ts
|
|
@@ -362,31 +508,82 @@ declare function resolveProject(): Promise<{
|
|
|
362
508
|
}>;
|
|
363
509
|
declare function resolveScope(): Promise<string>;
|
|
364
510
|
//#endregion
|
|
511
|
+
//#region src/session/application/get-session-context.d.ts
|
|
512
|
+
declare function getSessionContext(opts: {
|
|
513
|
+
projectHash: string;
|
|
514
|
+
synthesis?: string;
|
|
515
|
+
}, deps: {
|
|
516
|
+
repo: MemoryRepository;
|
|
517
|
+
}): SessionContext;
|
|
518
|
+
//#endregion
|
|
365
519
|
//#region src/session/builder.d.ts
|
|
366
520
|
declare function listMemoryTypes(): MemoryType[];
|
|
367
521
|
declare class SessionContextBuilder {
|
|
368
522
|
#private;
|
|
369
|
-
constructor(
|
|
523
|
+
constructor(repo: MemoryRepository);
|
|
370
524
|
getSessionContext(projectHash: string, synthesis?: string): SessionContext;
|
|
371
525
|
}
|
|
372
526
|
//#endregion
|
|
373
|
-
//#region src/synthesis/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
527
|
+
//#region src/synthesis/domain/synthesis-job.d.ts
|
|
528
|
+
type ScopeStatus = "expired" | "dirty" | "missing";
|
|
529
|
+
interface DirtyScope {
|
|
530
|
+
scope: string;
|
|
531
|
+
reason: ScopeStatus;
|
|
532
|
+
}
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/synthesis/ports.d.ts
|
|
535
|
+
interface SynthesisConfig {
|
|
536
|
+
enabled: boolean;
|
|
537
|
+
maxTokensPerRun?: number;
|
|
538
|
+
debounceMs?: number;
|
|
539
|
+
stalenessDays?: number;
|
|
540
|
+
inFlightTimeoutMs?: number;
|
|
541
|
+
}
|
|
542
|
+
interface SynthesisTools {
|
|
543
|
+
queryMemory: (args: {
|
|
544
|
+
query: string;
|
|
545
|
+
limit?: number;
|
|
546
|
+
global?: boolean;
|
|
547
|
+
projectHash?: string;
|
|
548
|
+
}) => Promise<string>;
|
|
549
|
+
getMemorySummary: () => Promise<string>;
|
|
550
|
+
}
|
|
551
|
+
interface AgentRunner {
|
|
552
|
+
run(scope: string, projectHash?: string): Promise<string>;
|
|
553
|
+
}
|
|
554
|
+
interface SynthesisRepository {
|
|
377
555
|
saveSynthesis(scope: string, content: string, sourceHash: string): Synthesis;
|
|
378
556
|
getSynthesis(scope: string): Synthesis | undefined;
|
|
557
|
+
listAll(): Synthesis[];
|
|
379
558
|
markInFlight(scope: string): void;
|
|
380
559
|
clearInFlight(scope: string): void;
|
|
381
560
|
clearStaleInFlight(thresholdMs: number): void;
|
|
382
561
|
computeSourceMemoryHash(scope: string): string;
|
|
383
|
-
getExpiredOrDirtyScopes():
|
|
384
|
-
scope: string;
|
|
385
|
-
reason: "expired" | "dirty" | "missing";
|
|
386
|
-
}[];
|
|
562
|
+
getExpiredOrDirtyScopes(): DirtyScope[];
|
|
387
563
|
getAllActiveScopes(): string[];
|
|
388
564
|
expireStale(): void;
|
|
389
565
|
}
|
|
390
566
|
//#endregion
|
|
391
|
-
|
|
567
|
+
//#region src/synthesis/application/engine.d.ts
|
|
568
|
+
declare class SynthesisEngine {
|
|
569
|
+
#private;
|
|
570
|
+
constructor(synthRepo: SynthesisRepository, config: SynthesisConfig, agentRunner: AgentRunner);
|
|
571
|
+
init(): Promise<void>;
|
|
572
|
+
shutdown(): Promise<void>;
|
|
573
|
+
markDirty(scope: string): void;
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/synthesis/application/run-synthesis.d.ts
|
|
577
|
+
declare function runSynthesis(scope: string, deps: {
|
|
578
|
+
synthRepo: SynthesisRepository;
|
|
579
|
+
agentRunner: AgentRunner;
|
|
580
|
+
}): Promise<string>;
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region src/synthesis/infrastructure/claude-agent-runner.d.ts
|
|
583
|
+
declare function createSynthesisAgentRunner(tools: SynthesisTools, config: SynthesisConfig): AgentRunner;
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region src/synthesis/infrastructure/sqlite-synthesis-repository.d.ts
|
|
586
|
+
declare function createSynthesisRepository(db: DatabaseManager): SynthesisRepository;
|
|
587
|
+
//#endregion
|
|
588
|
+
export { type AgentRunner, type CreateMemoryOpts, type CreateReviewEventOpts, DatabaseError, DatabaseManager, type DownloadProgress, type DownloadResult, type Embedder, EmbeddingService, MEMORY_TYPE_VALUES, MIGRATIONS, MODEL_NAME, MembankError, type Memory, type MemoryExportRecord, type MemoryPatch, MemoryPatchSchema, type MemoryRepository, type MemoryRow, MemoryRowSchema, MemorySchema, type MemoryType, MemoryTypeSchema, MigrationMeta, ModelDownloadError, ModelDownloader, PIN_BUDGET_THRESHOLD, type ProgressCallback, Project, type ProjectRepository, ProjectRow, ProjectRowSchema, ProjectSchema, type Querier, type QueryAdapter, QueryEngine, QueryOptions, QueryOptionsSchema, type ReviewEvent, type ReviewEventRow, ReviewEventRowSchema, ReviewEventSchema, ReviewReason, ReviewReasonSchema, type SaveOptions, SaveOptionsSchema, ScopeToProjectsResult, type ScoredMemory, SessionContext, SessionContextBuilder, SessionContextSchema, type SimilarMemoryResult, SqliteMemoryRepository, type StatsResult, Synthesis, type SynthesisConfig, SynthesisEngine, type SynthesisRepository, SynthesisSchema, type SynthesisTools, TagsJsonSchema, createMemoryRepository, createProjectRepository, createSynthesisAgentRunner, createSynthesisRepository, deleteMemory, getSessionContext, isOverBudget, isSynthesisEnabled, listMemoryTypes, queryMemories, resolveProject, resolveReview, resolveScope, rowToMemory, rowToProject, runScopeToProjectsMigration, runSynthesis, saveMemory, updateMemory };
|
|
392
589
|
//# sourceMappingURL=index.d.mts.map
|