agent-memory-graph 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +341 -0
  3. package/config/default.json +28 -0
  4. package/config/graph.config.json +28 -0
  5. package/dist/cli/index.d.ts +3 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +303 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/plugin/entry.d.ts +3 -0
  10. package/dist/plugin/entry.d.ts.map +1 -0
  11. package/dist/plugin/entry.js +1652 -0
  12. package/dist/plugin/entry.js.map +1 -0
  13. package/dist/src/config/defaults.d.ts +8 -0
  14. package/dist/src/config/defaults.d.ts.map +1 -0
  15. package/dist/src/config/defaults.js +31 -0
  16. package/dist/src/config/defaults.js.map +1 -0
  17. package/dist/src/config/schema.d.ts +162 -0
  18. package/dist/src/config/schema.d.ts.map +1 -0
  19. package/dist/src/config/schema.js +39 -0
  20. package/dist/src/config/schema.js.map +1 -0
  21. package/dist/src/extract/dedup.d.ts +14 -0
  22. package/dist/src/extract/dedup.d.ts.map +1 -0
  23. package/dist/src/extract/dedup.js +79 -0
  24. package/dist/src/extract/dedup.js.map +1 -0
  25. package/dist/src/extract/extractor.d.ts +24 -0
  26. package/dist/src/extract/extractor.d.ts.map +1 -0
  27. package/dist/src/extract/extractor.js +162 -0
  28. package/dist/src/extract/extractor.js.map +1 -0
  29. package/dist/src/graph/engine.d.ts +90 -0
  30. package/dist/src/graph/engine.d.ts.map +1 -0
  31. package/dist/src/graph/engine.js +307 -0
  32. package/dist/src/graph/engine.js.map +1 -0
  33. package/dist/src/graph/schema.d.ts +12 -0
  34. package/dist/src/graph/schema.d.ts.map +1 -0
  35. package/dist/src/graph/schema.js +115 -0
  36. package/dist/src/graph/schema.js.map +1 -0
  37. package/dist/src/index.d.ts +129 -0
  38. package/dist/src/index.d.ts.map +1 -0
  39. package/dist/src/index.js +174 -0
  40. package/dist/src/index.js.map +1 -0
  41. package/dist/src/search/hybrid.d.ts +22 -0
  42. package/dist/src/search/hybrid.d.ts.map +1 -0
  43. package/dist/src/search/hybrid.js +38 -0
  44. package/dist/src/search/hybrid.js.map +1 -0
  45. package/dist/src/search/natural-language.d.ts +20 -0
  46. package/dist/src/search/natural-language.d.ts.map +1 -0
  47. package/dist/src/search/natural-language.js +429 -0
  48. package/dist/src/search/natural-language.js.map +1 -0
  49. package/dist/src/sync/export.d.ts +12 -0
  50. package/dist/src/sync/export.d.ts.map +1 -0
  51. package/dist/src/sync/export.js +117 -0
  52. package/dist/src/sync/export.js.map +1 -0
  53. package/dist/src/sync/memory-md.d.ts +19 -0
  54. package/dist/src/sync/memory-md.d.ts.map +1 -0
  55. package/dist/src/sync/memory-md.js +78 -0
  56. package/dist/src/sync/memory-md.js.map +1 -0
  57. package/openclaw.plugin.json +55 -0
  58. package/package.json +90 -0
@@ -0,0 +1,78 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { extractFromText } from '../extract/extractor.js';
3
+ /**
4
+ * Import entities and relationships from a MEMORY.md file.
5
+ * Splits the file into sections and extracts from each.
6
+ */
7
+ export async function importFromMemoryMd(filePath, engine, config) {
8
+ if (!existsSync(filePath)) {
9
+ throw new Error(`File not found: ${filePath}`);
10
+ }
11
+ const content = readFileSync(filePath, 'utf-8');
12
+ // Split into meaningful sections (by headers or double newlines)
13
+ const sections = splitIntoSections(content);
14
+ let totalEntities = 0;
15
+ let totalRelationships = 0;
16
+ for (const section of sections) {
17
+ if (section.trim().length < 20)
18
+ continue; // Skip tiny sections
19
+ try {
20
+ const result = await extractFromText(section, config);
21
+ // Store entities
22
+ for (const entity of result.entities) {
23
+ engine.addEntity(entity.name, entity.type, entity.properties ?? {}, {
24
+ source: filePath,
25
+ confidence: entity.confidence,
26
+ });
27
+ totalEntities++;
28
+ }
29
+ // Store relationships
30
+ for (const rel of result.relationships) {
31
+ engine.addRelation(rel.from, rel.relation, rel.to, {
32
+ source: filePath,
33
+ confidence: rel.confidence,
34
+ fromType: rel.fromType,
35
+ toType: rel.toType,
36
+ });
37
+ totalRelationships++;
38
+ }
39
+ }
40
+ catch (err) {
41
+ console.warn(`[agent-memory-graph] Failed to extract from section: ${err}`);
42
+ }
43
+ }
44
+ return { entities: totalEntities, relationships: totalRelationships };
45
+ }
46
+ /**
47
+ * Import from a directory of markdown files.
48
+ */
49
+ export async function importFromDirectory(dirPath, engine, config) {
50
+ const { readdirSync, statSync } = await import('node:fs');
51
+ const { join } = await import('node:path');
52
+ let totalEntities = 0;
53
+ let totalRelationships = 0;
54
+ let fileCount = 0;
55
+ const entries = readdirSync(dirPath);
56
+ for (const entry of entries) {
57
+ const fullPath = join(dirPath, entry);
58
+ const stat = statSync(fullPath);
59
+ if (stat.isFile() && (entry.endsWith('.md') || entry.endsWith('.txt'))) {
60
+ const result = await importFromMemoryMd(fullPath, engine, config);
61
+ totalEntities += result.entities;
62
+ totalRelationships += result.relationships;
63
+ fileCount++;
64
+ }
65
+ }
66
+ return { entities: totalEntities, relationships: totalRelationships, files: fileCount };
67
+ }
68
+ // ─── Helpers ─────────────────────────────────────────────────────
69
+ function splitIntoSections(content) {
70
+ // Split by markdown headers or double newlines
71
+ const sections = content.split(/(?=^#{1,3}\s)/m);
72
+ // If no headers found, split by double newlines
73
+ if (sections.length <= 1) {
74
+ return content.split(/\n\n+/).filter(s => s.trim().length > 0);
75
+ }
76
+ return sections.filter(s => s.trim().length > 0);
77
+ }
78
+ //# sourceMappingURL=memory-md.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-md.js","sourceRoot":"","sources":["../../../src/sync/memory-md.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAgB,EA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AAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC1F,CAAC;AAED,oEAAoE;AAEpE,SAAS,iBAAiB,CAAC,OAAe;IACxC,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEjD,gDAAgD;IAChD,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1,55 @@
1
+ {
2
+ "id": "memory-graph",
3
+ "name": "Memory Graph",
4
+ "description": "Auto-builds a knowledge graph from conversations. Extracts entities and relationships from every message, stores in local SQLite, and exposes query/search/path tools to the agent.",
5
+ "contracts": {
6
+ "tools": ["memory_graph_query", "memory_graph_ingest", "memory_graph_search", "memory_graph_path", "memory_graph_stats"]
7
+ },
8
+ "activation": {
9
+ "onStartup": true
10
+ },
11
+ "configSchema": {
12
+ "type": "object",
13
+ "properties": {
14
+ "dbPath": {
15
+ "type": "string",
16
+ "description": "Path to SQLite database file",
17
+ "default": "~/.openclaw/data/memory-graph.db"
18
+ },
19
+ "autoIngest": {
20
+ "type": "boolean",
21
+ "description": "Automatically extract entities from every inbound message",
22
+ "default": true
23
+ },
24
+ "minConfidence": {
25
+ "type": "number",
26
+ "description": "Minimum confidence threshold for extracted entities (0.0-1.0)",
27
+ "default": 0.7
28
+ },
29
+ "extractionModel": {
30
+ "type": "string",
31
+ "description": "Model to use for entity extraction (empty = use default agent model)",
32
+ "default": ""
33
+ },
34
+ "maxHops": {
35
+ "type": "number",
36
+ "description": "Maximum graph traversal hops for path queries",
37
+ "default": 3
38
+ },
39
+ "domains": {
40
+ "type": "array",
41
+ "description": "Optional domain hints to improve extraction accuracy",
42
+ "items": {
43
+ "type": "object",
44
+ "properties": {
45
+ "name": { "type": "string" },
46
+ "entityHints": { "type": "array", "items": { "type": "string" } },
47
+ "relationHints": { "type": "array", "items": { "type": "string" } }
48
+ }
49
+ },
50
+ "default": []
51
+ }
52
+ },
53
+ "additionalProperties": false
54
+ }
55
+ }
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "agent-memory-graph",
3
+ "version": "0.1.0",
4
+ "description": "Domain-agnostic knowledge graph memory for AI agents. Zero-config, local-first, SQLite-powered. Works as OpenClaw skill (CLI) or plugin (auto-hook).",
5
+ "type": "module",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "bin": {
9
+ "memory-graph": "dist/cli/index.js"
10
+ },
11
+ "openclaw": {
12
+ "extensions": [
13
+ "./dist/plugin/entry.js"
14
+ ],
15
+ "compat": {
16
+ "pluginApi": ">=2026.3.24-beta.2",
17
+ "minGatewayVersion": "2026.3.24-beta.2"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "dev": "tsc --watch",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "lint": "eslint src/",
26
+ "prepublishOnly": "npm run build"
27
+ },
28
+ "keywords": [
29
+ "ai",
30
+ "agent",
31
+ "memory",
32
+ "knowledge-graph",
33
+ "graph-database",
34
+ "sqlite",
35
+ "llm",
36
+ "openclaw",
37
+ "openclaw-plugin",
38
+ "local-first",
39
+ "domain-agnostic"
40
+ ],
41
+ "author": "KLSGG",
42
+ "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/KLSGG/agent-memory-graph"
46
+ },
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "dependencies": {
51
+ "better-sqlite3": "^11.7.0",
52
+ "nanoid": "^5.0.9",
53
+ "openai": "^4.78.0",
54
+ "zod": "^3.24.0"
55
+ },
56
+ "devDependencies": {
57
+ "@types/better-sqlite3": "^7.6.12",
58
+ "@types/node": "^22.10.0",
59
+ "typescript": "^5.7.0",
60
+ "vitest": "^3.0.0",
61
+ "eslint": "^9.0.0"
62
+ },
63
+ "peerDependencies": {
64
+ "openclaw": ">=2026.3.24-beta.2",
65
+ "@sinclair/typebox": ">=0.32.0",
66
+ "@anthropic-ai/sdk": ">=0.30.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "openclaw": {
70
+ "optional": true
71
+ },
72
+ "@sinclair/typebox": {
73
+ "optional": true
74
+ },
75
+ "@anthropic-ai/sdk": {
76
+ "optional": true
77
+ }
78
+ },
79
+ "files": [
80
+ "dist/",
81
+ "config/",
82
+ "openclaw.plugin.json",
83
+ "README.md",
84
+ "LICENSE"
85
+ ],
86
+ "homepage": "https://github.com/KLSGG/agent-memory-graph#readme",
87
+ "bugs": {
88
+ "url": "https://github.com/KLSGG/agent-memory-graph/issues"
89
+ }
90
+ }