@sparkleideas/memory 3.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +249 -0
  2. package/benchmarks/cache-hit-rate.bench.ts +535 -0
  3. package/benchmarks/hnsw-indexing.bench.ts +552 -0
  4. package/benchmarks/memory-write.bench.ts +469 -0
  5. package/benchmarks/vector-search.bench.ts +449 -0
  6. package/docs/AGENTDB-INTEGRATION.md +388 -0
  7. package/docs/CROSS_PLATFORM.md +505 -0
  8. package/docs/WINDOWS_SUPPORT.md +422 -0
  9. package/examples/agentdb-example.ts +345 -0
  10. package/examples/cross-platform-usage.ts +326 -0
  11. package/framework/benchmark.ts +112 -0
  12. package/package.json +42 -0
  13. package/src/agentdb-adapter.ts +1037 -0
  14. package/src/agentdb-backend.test.ts +339 -0
  15. package/src/agentdb-backend.ts +1016 -0
  16. package/src/agents/architect.yaml +11 -0
  17. package/src/agents/coder.yaml +11 -0
  18. package/src/agents/reviewer.yaml +10 -0
  19. package/src/agents/security-architect.yaml +10 -0
  20. package/src/agents/tester.yaml +10 -0
  21. package/src/application/commands/delete-memory.command.ts +172 -0
  22. package/src/application/commands/store-memory.command.ts +103 -0
  23. package/src/application/index.ts +36 -0
  24. package/src/application/queries/search-memory.query.ts +237 -0
  25. package/src/application/services/memory-application-service.ts +236 -0
  26. package/src/cache-manager.ts +516 -0
  27. package/src/database-provider.test.ts +364 -0
  28. package/src/database-provider.ts +511 -0
  29. package/src/domain/entities/memory-entry.ts +289 -0
  30. package/src/domain/index.ts +35 -0
  31. package/src/domain/repositories/memory-repository.interface.ts +120 -0
  32. package/src/domain/services/memory-domain-service.ts +403 -0
  33. package/src/hnsw-index.ts +1013 -0
  34. package/src/hybrid-backend.test.ts +399 -0
  35. package/src/hybrid-backend.ts +694 -0
  36. package/src/index.ts +515 -0
  37. package/src/infrastructure/index.ts +23 -0
  38. package/src/infrastructure/repositories/hybrid-memory-repository.ts +516 -0
  39. package/src/migration.ts +669 -0
  40. package/src/query-builder.ts +542 -0
  41. package/src/sqlite-backend.ts +732 -0
  42. package/src/sqljs-backend.ts +763 -0
  43. package/src/tmp.json +0 -0
  44. package/src/types.ts +727 -0
  45. package/tmp.json +0 -0
  46. package/tsconfig.json +11 -0
  47. package/verify-cross-platform.ts +170 -0
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Benchmark Framework
3
+ *
4
+ * Utilities for running performance benchmarks.
5
+ */
6
+
7
+ export interface BenchmarkResult {
8
+ name: string;
9
+ iterations: number;
10
+ totalTime: number;
11
+ avgTime: number;
12
+ minTime: number;
13
+ maxTime: number;
14
+ opsPerSecond: number;
15
+ meetsTarget: boolean;
16
+ }
17
+
18
+ export interface BenchmarkOptions {
19
+ iterations?: number;
20
+ warmupIterations?: number;
21
+ targetTime?: number;
22
+ }
23
+
24
+ export class BenchmarkRunner {
25
+ private results: BenchmarkResult[] = [];
26
+
27
+ async run(name: string, fn: () => void | Promise<void>, options: BenchmarkOptions = {}): Promise<BenchmarkResult> {
28
+ const { iterations = 1000, warmupIterations = 100, targetTime } = options;
29
+
30
+ // Warmup
31
+ for (let i = 0; i < warmupIterations; i++) {
32
+ await fn();
33
+ }
34
+
35
+ // Actual benchmark
36
+ const times: number[] = [];
37
+ const start = performance.now();
38
+
39
+ for (let i = 0; i < iterations; i++) {
40
+ const iterStart = performance.now();
41
+ await fn();
42
+ times.push(performance.now() - iterStart);
43
+ }
44
+
45
+ const totalTime = performance.now() - start;
46
+ const avgTime = totalTime / iterations;
47
+ const minTime = Math.min(...times);
48
+ const maxTime = Math.max(...times);
49
+ const opsPerSecond = 1000 / avgTime;
50
+
51
+ const result: BenchmarkResult = {
52
+ name,
53
+ iterations,
54
+ totalTime,
55
+ avgTime,
56
+ minTime,
57
+ maxTime,
58
+ opsPerSecond,
59
+ meetsTarget: targetTime ? avgTime <= targetTime : true,
60
+ };
61
+
62
+ this.results.push(result);
63
+ return result;
64
+ }
65
+
66
+ getResults(): BenchmarkResult[] {
67
+ return [...this.results];
68
+ }
69
+
70
+ printSummary(): void {
71
+ console.log('\n=== Benchmark Summary ===\n');
72
+ for (const result of this.results) {
73
+ const status = result.meetsTarget ? '✅' : '❌';
74
+ console.log(`${status} ${result.name}`);
75
+ console.log(` Avg: ${formatTime(result.avgTime)}`);
76
+ console.log(` Min: ${formatTime(result.minTime)}`);
77
+ console.log(` Max: ${formatTime(result.maxTime)}`);
78
+ console.log(` Ops/sec: ${result.opsPerSecond.toFixed(2)}`);
79
+ console.log('');
80
+ }
81
+ }
82
+ }
83
+
84
+ export function formatTime(ms: number): string {
85
+ if (ms < 0.001) {
86
+ return `${(ms * 1000000).toFixed(2)}ns`;
87
+ } else if (ms < 1) {
88
+ return `${(ms * 1000).toFixed(2)}μs`;
89
+ } else if (ms < 1000) {
90
+ return `${ms.toFixed(2)}ms`;
91
+ } else {
92
+ return `${(ms / 1000).toFixed(2)}s`;
93
+ }
94
+ }
95
+
96
+ export function meetsTarget(actual: number, target: number): boolean {
97
+ return actual <= target;
98
+ }
99
+
100
+ export async function benchmark(
101
+ name: string,
102
+ fn: () => void | Promise<void>,
103
+ options: BenchmarkOptions = {}
104
+ ): Promise<BenchmarkResult> {
105
+ const runner = new BenchmarkRunner();
106
+ return runner.run(name, fn, options);
107
+ }
108
+
109
+ export function createBenchmarkSuite(name: string): BenchmarkRunner {
110
+ console.log(`\n📊 Benchmark Suite: ${name}\n`);
111
+ return new BenchmarkRunner();
112
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@sparkleideas/memory",
3
+ "version": "3.0.0-alpha.7",
4
+ "type": "module",
5
+ "description": "Memory module - AgentDB unification, HNSW indexing, vector search, hybrid SQLite+AgentDB backend (ADR-009)",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./*": "./dist/*.js"
11
+ },
12
+ "scripts": {
13
+ "test": "vitest run",
14
+ "bench": "vitest bench",
15
+ "build": "tsc"
16
+ },
17
+ "dependencies": {
18
+ "sql.js": "^1.10.3",
19
+ "@sparkleideas/agentdb": "alpha"
20
+ },
21
+ "optionalDependencies": {
22
+ "better-sqlite3": "^11.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/better-sqlite3": "^7.6.11",
26
+ "@types/sql.js": "^1.4.9",
27
+ "vitest": "^4.0.16"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "tag": "v3alpha"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ]
42
+ }