claudecode-rlm 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/LICENSE +21 -0
- package/README.md +209 -0
- package/dist/config.d.ts +176 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +103 -0
- package/dist/config.js.map +1 -0
- package/dist/graph/index.d.ts +10 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +10 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/ingestion.d.ts +68 -0
- package/dist/graph/ingestion.d.ts.map +1 -0
- package/dist/graph/ingestion.js +417 -0
- package/dist/graph/ingestion.js.map +1 -0
- package/dist/graph/storage.d.ts +51 -0
- package/dist/graph/storage.d.ts.map +1 -0
- package/dist/graph/storage.js +552 -0
- package/dist/graph/storage.js.map +1 -0
- package/dist/graph/traversal.d.ts +54 -0
- package/dist/graph/traversal.d.ts.map +1 -0
- package/dist/graph/traversal.js +255 -0
- package/dist/graph/traversal.js.map +1 -0
- package/dist/graph/types.d.ts +152 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +94 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-types.d.ts +96 -0
- package/dist/plugin-types.d.ts.map +1 -0
- package/dist/plugin-types.js +17 -0
- package/dist/plugin-types.js.map +1 -0
- package/dist/search/enhanced.d.ts +95 -0
- package/dist/search/enhanced.d.ts.map +1 -0
- package/dist/search/enhanced.js +194 -0
- package/dist/search/enhanced.js.map +1 -0
- package/dist/search/index.d.ts +8 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +8 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/patterns.d.ts +38 -0
- package/dist/search/patterns.d.ts.map +1 -0
- package/dist/search/patterns.js +124 -0
- package/dist/search/patterns.js.map +1 -0
- package/dist/tools/graph-query.d.ts +14 -0
- package/dist/tools/graph-query.d.ts.map +1 -0
- package/dist/tools/graph-query.js +203 -0
- package/dist/tools/graph-query.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/memory.d.ts +20 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +181 -0
- package/dist/tools/memory.js.map +1 -0
- package/package.json +66 -0
- package/src/config.ts +111 -0
- package/src/graph/index.ts +10 -0
- package/src/graph/ingestion.ts +528 -0
- package/src/graph/storage.ts +639 -0
- package/src/graph/traversal.ts +348 -0
- package/src/graph/types.ts +144 -0
- package/src/index.ts +238 -0
- package/src/plugin-types.ts +107 -0
- package/src/search/enhanced.ts +264 -0
- package/src/search/index.ts +23 -0
- package/src/search/patterns.ts +139 -0
- package/src/tools/graph-query.ts +257 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/memory.ts +208 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph traversal and search for RLM-Graph.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for navigating and searching the knowledge graph:
|
|
5
|
+
* - GraphTraverser: Breadth-first and path-based traversal
|
|
6
|
+
* - GraphSearcher: Combined keyword and semantic search
|
|
7
|
+
*/
|
|
8
|
+
import { NodeType, RelationType, } from "./types.js";
|
|
9
|
+
import { GraphStorage } from "./storage.js";
|
|
10
|
+
/**
|
|
11
|
+
* Traverses the knowledge graph to find related context.
|
|
12
|
+
*/
|
|
13
|
+
export var GraphTraverser;
|
|
14
|
+
(function (GraphTraverser) {
|
|
15
|
+
/**
|
|
16
|
+
* Get neighboring nodes.
|
|
17
|
+
*/
|
|
18
|
+
function getNeighbors(sessionID, nodeID, direction = "outgoing", relationship) {
|
|
19
|
+
return GraphStorage.getNeighbors(sessionID, nodeID, direction, relationship);
|
|
20
|
+
}
|
|
21
|
+
GraphTraverser.getNeighbors = getNeighbors;
|
|
22
|
+
/**
|
|
23
|
+
* Expand context by traversing from given nodes using BFS.
|
|
24
|
+
*/
|
|
25
|
+
function expandContext(sessionID, nodeIDs, maxDepth = 2, maxNodes = 20) {
|
|
26
|
+
const visited = new Set();
|
|
27
|
+
const result = [];
|
|
28
|
+
const queue = nodeIDs.map((nodeID) => ({ nodeID, depth: 0 }));
|
|
29
|
+
while (queue.length > 0 && result.length < maxNodes) {
|
|
30
|
+
const { nodeID, depth } = queue.shift();
|
|
31
|
+
if (visited.has(nodeID)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
visited.add(nodeID);
|
|
35
|
+
const node = GraphStorage.getNode(sessionID, nodeID);
|
|
36
|
+
if (node) {
|
|
37
|
+
result.push(node);
|
|
38
|
+
}
|
|
39
|
+
if (depth < maxDepth) {
|
|
40
|
+
// Get neighbors from edges
|
|
41
|
+
const edges = GraphStorage.getEdges(sessionID, nodeID, "both");
|
|
42
|
+
for (const edge of edges) {
|
|
43
|
+
const neighborID = edge.sourceID === nodeID ? edge.targetID : edge.sourceID;
|
|
44
|
+
if (!visited.has(neighborID)) {
|
|
45
|
+
queue.push({ nodeID: neighborID, depth: depth + 1 });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
GraphTraverser.expandContext = expandContext;
|
|
53
|
+
/**
|
|
54
|
+
* Find a path between two nodes using BFS.
|
|
55
|
+
*/
|
|
56
|
+
function findPath(sessionID, startID, endID, maxDepth = 5) {
|
|
57
|
+
const visited = new Set();
|
|
58
|
+
const queue = [
|
|
59
|
+
{ nodeID: startID, path: [startID] },
|
|
60
|
+
];
|
|
61
|
+
while (queue.length > 0) {
|
|
62
|
+
const { nodeID, path } = queue.shift();
|
|
63
|
+
if (nodeID === endID) {
|
|
64
|
+
// Build node list from path
|
|
65
|
+
const nodes = [];
|
|
66
|
+
for (const id of path) {
|
|
67
|
+
const node = GraphStorage.getNode(sessionID, id);
|
|
68
|
+
if (node) {
|
|
69
|
+
nodes.push(node);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return nodes;
|
|
73
|
+
}
|
|
74
|
+
if (path.length >= maxDepth) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
visited.add(nodeID);
|
|
78
|
+
const edges = GraphStorage.getEdges(sessionID, nodeID, "both");
|
|
79
|
+
for (const edge of edges) {
|
|
80
|
+
const neighborID = edge.sourceID === nodeID ? edge.targetID : edge.sourceID;
|
|
81
|
+
if (!visited.has(neighborID)) {
|
|
82
|
+
queue.push({ nodeID: neighborID, path: [...path, neighborID] });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
GraphTraverser.findPath = findPath;
|
|
89
|
+
/**
|
|
90
|
+
* Get all chunks that mention a specific entity.
|
|
91
|
+
*/
|
|
92
|
+
function getEntityContext(sessionID, entityName, maxChunks = 10) {
|
|
93
|
+
// Find entity nodes matching the name
|
|
94
|
+
const entities = GraphStorage.searchNodes(sessionID, entityName, NodeType.ENTITY, 5);
|
|
95
|
+
const chunkIDs = new Set();
|
|
96
|
+
for (const entity of entities) {
|
|
97
|
+
// Find chunks that mention this entity (incoming MENTIONS edges)
|
|
98
|
+
const edges = GraphStorage.getEdges(sessionID, entity.id, "incoming");
|
|
99
|
+
for (const edge of edges) {
|
|
100
|
+
if (edge.relationship === RelationType.MENTIONS) {
|
|
101
|
+
chunkIDs.add(edge.sourceID);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Get chunk nodes
|
|
106
|
+
const chunks = [];
|
|
107
|
+
for (const chunkID of Array.from(chunkIDs).slice(0, maxChunks)) {
|
|
108
|
+
const node = GraphStorage.getNode(sessionID, chunkID);
|
|
109
|
+
if (node) {
|
|
110
|
+
chunks.push(node);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return chunks;
|
|
114
|
+
}
|
|
115
|
+
GraphTraverser.getEntityContext = getEntityContext;
|
|
116
|
+
/**
|
|
117
|
+
* Get the parent document for a chunk.
|
|
118
|
+
*/
|
|
119
|
+
function getDocumentForChunk(sessionID, chunkID) {
|
|
120
|
+
// Navigate up: chunk -> section -> document
|
|
121
|
+
const chunkEdges = GraphStorage.getEdges(sessionID, chunkID, "incoming");
|
|
122
|
+
for (const edge of chunkEdges) {
|
|
123
|
+
if (edge.relationship === RelationType.HAS_CHUNK) {
|
|
124
|
+
// Found the section
|
|
125
|
+
const sectionID = edge.sourceID;
|
|
126
|
+
// Now find the document
|
|
127
|
+
const sectionEdges = GraphStorage.getEdges(sessionID, sectionID, "incoming");
|
|
128
|
+
for (const sectionEdge of sectionEdges) {
|
|
129
|
+
if (sectionEdge.relationship === RelationType.HAS_SECTION) {
|
|
130
|
+
return GraphStorage.getNode(sessionID, sectionEdge.sourceID);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
GraphTraverser.getDocumentForChunk = getDocumentForChunk;
|
|
138
|
+
})(GraphTraverser || (GraphTraverser = {}));
|
|
139
|
+
/**
|
|
140
|
+
* Search the knowledge graph using combined strategies.
|
|
141
|
+
*/
|
|
142
|
+
export var GraphSearcher;
|
|
143
|
+
(function (GraphSearcher) {
|
|
144
|
+
/**
|
|
145
|
+
* Search the graph for relevant nodes.
|
|
146
|
+
*/
|
|
147
|
+
function search(sessionID, query, options = {}) {
|
|
148
|
+
const { limit = 10, expandContext = true, nodeType = NodeType.CHUNK } = options;
|
|
149
|
+
const results = new Map();
|
|
150
|
+
// 1. Keyword search
|
|
151
|
+
const keywordMatches = GraphStorage.searchNodes(sessionID, query, nodeType, limit * 2);
|
|
152
|
+
const queryTerms = new Set(query.toLowerCase().split(/\s+/));
|
|
153
|
+
for (const node of keywordMatches) {
|
|
154
|
+
const contentTerms = new Set(node.content.toLowerCase().split(/\s+/));
|
|
155
|
+
const overlap = [...queryTerms].filter((t) => contentTerms.has(t)).length;
|
|
156
|
+
const score = overlap / Math.max(queryTerms.size, 1);
|
|
157
|
+
results.set(node.id, {
|
|
158
|
+
node,
|
|
159
|
+
score: score * 0.4, // Keyword weight: 0.4
|
|
160
|
+
matchedOn: "content",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// 2. Entity-based search
|
|
164
|
+
const entities = extractQueryEntities(query);
|
|
165
|
+
for (const entityName of entities) {
|
|
166
|
+
const chunks = GraphTraverser.getEntityContext(sessionID, entityName, 5);
|
|
167
|
+
for (const chunk of chunks) {
|
|
168
|
+
if (results.has(chunk.id)) {
|
|
169
|
+
// Boost existing result
|
|
170
|
+
const existing = results.get(chunk.id);
|
|
171
|
+
results.set(chunk.id, {
|
|
172
|
+
...existing,
|
|
173
|
+
score: existing.score + 0.3,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
results.set(chunk.id, {
|
|
178
|
+
node: chunk,
|
|
179
|
+
score: 0.3,
|
|
180
|
+
matchedOn: "entity",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// 3. Expand context via graph traversal
|
|
186
|
+
if (expandContext && results.size > 0) {
|
|
187
|
+
const topIDs = [...results.entries()]
|
|
188
|
+
.sort((a, b) => b[1].score - a[1].score)
|
|
189
|
+
.slice(0, 3)
|
|
190
|
+
.map(([id]) => id);
|
|
191
|
+
const expanded = GraphTraverser.expandContext(sessionID, topIDs, 1, 5);
|
|
192
|
+
for (const node of expanded) {
|
|
193
|
+
if (!results.has(node.id)) {
|
|
194
|
+
results.set(node.id, {
|
|
195
|
+
node,
|
|
196
|
+
score: 0.2,
|
|
197
|
+
matchedOn: "traversal",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Sort by score and return
|
|
203
|
+
return [...results.values()]
|
|
204
|
+
.sort((a, b) => b.score - a.score)
|
|
205
|
+
.slice(0, limit);
|
|
206
|
+
}
|
|
207
|
+
GraphSearcher.search = search;
|
|
208
|
+
/**
|
|
209
|
+
* Search across all sessions.
|
|
210
|
+
*/
|
|
211
|
+
function searchAllSessions(query, options = {}) {
|
|
212
|
+
const { limit = 10 } = options;
|
|
213
|
+
const allResults = [];
|
|
214
|
+
for (const sessionID of GraphStorage.getSessions()) {
|
|
215
|
+
const sessionResults = search(sessionID, query, {
|
|
216
|
+
...options,
|
|
217
|
+
limit: Math.ceil(limit / 2),
|
|
218
|
+
});
|
|
219
|
+
allResults.push(...sessionResults);
|
|
220
|
+
}
|
|
221
|
+
// Sort by score and deduplicate
|
|
222
|
+
const seen = new Set();
|
|
223
|
+
return allResults
|
|
224
|
+
.sort((a, b) => b.score - a.score)
|
|
225
|
+
.filter((r) => {
|
|
226
|
+
if (seen.has(r.node.id))
|
|
227
|
+
return false;
|
|
228
|
+
seen.add(r.node.id);
|
|
229
|
+
return true;
|
|
230
|
+
})
|
|
231
|
+
.slice(0, limit);
|
|
232
|
+
}
|
|
233
|
+
GraphSearcher.searchAllSessions = searchAllSessions;
|
|
234
|
+
/**
|
|
235
|
+
* Extract potential entity names from a query.
|
|
236
|
+
*/
|
|
237
|
+
function extractQueryEntities(query) {
|
|
238
|
+
const entities = [];
|
|
239
|
+
// Capitalized terms
|
|
240
|
+
const capitalizedPattern = /\b([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)\b/g;
|
|
241
|
+
let match;
|
|
242
|
+
while ((match = capitalizedPattern.exec(query)) !== null) {
|
|
243
|
+
entities.push(match[1]);
|
|
244
|
+
}
|
|
245
|
+
// Code elements (PascalCase, snake_case)
|
|
246
|
+
const codePattern = /\b([A-Z][a-zA-Z0-9]*|[a-z_][a-z0-9_]+)\b/g;
|
|
247
|
+
while ((match = codePattern.exec(query)) !== null) {
|
|
248
|
+
if (match[1].length > 3) {
|
|
249
|
+
entities.push(match[1]);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return [...new Set(entities)];
|
|
253
|
+
}
|
|
254
|
+
})(GraphSearcher || (GraphSearcher = {}));
|
|
255
|
+
//# sourceMappingURL=traversal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traversal.js","sourceRoot":"","sources":["../../src/graph/traversal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,QAAQ,EACR,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C;;GAEG;AACH,MAAM,KAAW,cAAc,CAgL9B;AAhLD,WAAiB,cAAc;IAC7B;;OAEG;IACH,SAAgB,YAAY,CAC1B,SAAiB,EACjB,MAAc,EACd,YAA8C,UAAU,EACxD,YAA2B;QAE3B,OAAO,YAAY,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAAA;IAC9E,CAAC;IAPe,2BAAY,eAO3B,CAAA;IAED;;OAEG;IACH,SAAgB,aAAa,CAC3B,SAAiB,EACjB,OAAiB,EACjB,WAAmB,CAAC,EACpB,WAAmB,EAAE;QAErB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;QACjC,MAAM,MAAM,GAAgB,EAAE,CAAA;QAC9B,MAAM,KAAK,GAA6C,OAAO,CAAC,GAAG,CACjE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CACnC,CAAA;QAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;YACpD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,EAAG,CAAA;YAExC,IAAI,OAAO,CAAC,GAAG,CAAC,MAA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C,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAClD,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC,EAnJgB,aAAa,KAAb,aAAa,QAmJ7B"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph types for RLM-Graph knowledge storage.
|
|
3
|
+
*
|
|
4
|
+
* Defines the node and edge types for the knowledge graph that stores
|
|
5
|
+
* archived conversation context.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* Node types in the knowledge graph.
|
|
10
|
+
*/
|
|
11
|
+
export declare const NodeType: {
|
|
12
|
+
/** Top-level document representing an archived context block */
|
|
13
|
+
readonly DOCUMENT: "document";
|
|
14
|
+
/** Section within a document (e.g., markdown header section) */
|
|
15
|
+
readonly SECTION: "section";
|
|
16
|
+
/** Individual content chunk for retrieval */
|
|
17
|
+
readonly CHUNK: "chunk";
|
|
18
|
+
/** Named entity (code element, file path, concept) */
|
|
19
|
+
readonly ENTITY: "entity";
|
|
20
|
+
};
|
|
21
|
+
export type NodeType = (typeof NodeType)[keyof typeof NodeType];
|
|
22
|
+
/**
|
|
23
|
+
* Relationship types between nodes.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RelationType: {
|
|
26
|
+
/** Document contains section */
|
|
27
|
+
readonly HAS_SECTION: "has_section";
|
|
28
|
+
/** Section/Document contains chunk */
|
|
29
|
+
readonly HAS_CHUNK: "has_chunk";
|
|
30
|
+
/** Chunk mentions entity */
|
|
31
|
+
readonly MENTIONS: "mentions";
|
|
32
|
+
/** Related concepts */
|
|
33
|
+
readonly RELATED_TO: "related_to";
|
|
34
|
+
/** Temporal ordering (chunk follows chunk) */
|
|
35
|
+
readonly FOLLOWS: "follows";
|
|
36
|
+
/** Parent-child relationship */
|
|
37
|
+
readonly PARENT_OF: "parent_of";
|
|
38
|
+
};
|
|
39
|
+
export type RelationType = (typeof RelationType)[keyof typeof RelationType];
|
|
40
|
+
/**
|
|
41
|
+
* Entity types for extracted entities.
|
|
42
|
+
*/
|
|
43
|
+
export declare const EntityType: {
|
|
44
|
+
/** Code element (class, function, variable) */
|
|
45
|
+
readonly CODE_ELEMENT: "code_element";
|
|
46
|
+
/** File path */
|
|
47
|
+
readonly FILE_PATH: "file_path";
|
|
48
|
+
/** Proper noun / named concept */
|
|
49
|
+
readonly PROPER_NOUN: "proper_noun";
|
|
50
|
+
/** Reference (link, citation) */
|
|
51
|
+
readonly REFERENCE: "reference";
|
|
52
|
+
};
|
|
53
|
+
export type EntityType = (typeof EntityType)[keyof typeof EntityType];
|
|
54
|
+
/**
|
|
55
|
+
* Graph node schema.
|
|
56
|
+
*/
|
|
57
|
+
export declare const GraphNodeSchema: z.ZodObject<{
|
|
58
|
+
/** Unique node identifier */
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
/** Session this node belongs to */
|
|
61
|
+
sessionID: z.ZodString;
|
|
62
|
+
/** Node type */
|
|
63
|
+
type: z.ZodEnum<["document", "section", "chunk", "entity"]>;
|
|
64
|
+
/** Node content (text, entity name, etc.) */
|
|
65
|
+
content: z.ZodString;
|
|
66
|
+
/** Additional metadata */
|
|
67
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
68
|
+
/** Optional embedding vector */
|
|
69
|
+
embedding: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
70
|
+
/** Creation timestamp */
|
|
71
|
+
createdAt: z.ZodNumber;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
type: "document" | "section" | "chunk" | "entity";
|
|
74
|
+
id: string;
|
|
75
|
+
sessionID: string;
|
|
76
|
+
content: string;
|
|
77
|
+
metadata: Record<string, any>;
|
|
78
|
+
createdAt: number;
|
|
79
|
+
embedding?: number[] | undefined;
|
|
80
|
+
}, {
|
|
81
|
+
type: "document" | "section" | "chunk" | "entity";
|
|
82
|
+
id: string;
|
|
83
|
+
sessionID: string;
|
|
84
|
+
content: string;
|
|
85
|
+
createdAt: number;
|
|
86
|
+
metadata?: Record<string, any> | undefined;
|
|
87
|
+
embedding?: number[] | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
export type GraphNode = z.infer<typeof GraphNodeSchema>;
|
|
90
|
+
/**
|
|
91
|
+
* Graph edge schema.
|
|
92
|
+
*/
|
|
93
|
+
export declare const GraphEdgeSchema: z.ZodObject<{
|
|
94
|
+
/** Source node ID */
|
|
95
|
+
sourceID: z.ZodString;
|
|
96
|
+
/** Target node ID */
|
|
97
|
+
targetID: z.ZodString;
|
|
98
|
+
/** Relationship type */
|
|
99
|
+
relationship: z.ZodEnum<["has_section", "has_chunk", "mentions", "related_to", "follows", "parent_of"]>;
|
|
100
|
+
/** Edge weight (0-1) */
|
|
101
|
+
weight: z.ZodDefault<z.ZodNumber>;
|
|
102
|
+
/** Additional metadata */
|
|
103
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
104
|
+
/** Creation timestamp */
|
|
105
|
+
createdAt: z.ZodNumber;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
metadata: Record<string, any>;
|
|
108
|
+
createdAt: number;
|
|
109
|
+
sourceID: string;
|
|
110
|
+
targetID: string;
|
|
111
|
+
relationship: "has_section" | "has_chunk" | "mentions" | "related_to" | "follows" | "parent_of";
|
|
112
|
+
weight: number;
|
|
113
|
+
}, {
|
|
114
|
+
createdAt: number;
|
|
115
|
+
sourceID: string;
|
|
116
|
+
targetID: string;
|
|
117
|
+
relationship: "has_section" | "has_chunk" | "mentions" | "related_to" | "follows" | "parent_of";
|
|
118
|
+
metadata?: Record<string, any> | undefined;
|
|
119
|
+
weight?: number | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
export type GraphEdge = z.infer<typeof GraphEdgeSchema>;
|
|
122
|
+
/**
|
|
123
|
+
* Entity extracted from text.
|
|
124
|
+
*/
|
|
125
|
+
export interface Entity {
|
|
126
|
+
name: string;
|
|
127
|
+
type: EntityType;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Search result with relevance score.
|
|
131
|
+
*/
|
|
132
|
+
export interface GraphSearchResult {
|
|
133
|
+
node: GraphNode;
|
|
134
|
+
score: number;
|
|
135
|
+
matchedOn: "content" | "entity" | "traversal" | "embedding";
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Edge adjacency list for storage.
|
|
139
|
+
*/
|
|
140
|
+
export interface EdgeAdjacencyList {
|
|
141
|
+
outgoing: GraphEdge[];
|
|
142
|
+
incoming: GraphEdge[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Type index mapping node types to node IDs.
|
|
146
|
+
*/
|
|
147
|
+
export type TypeIndex = Record<string, string[]>;
|
|
148
|
+
/**
|
|
149
|
+
* Entity index mapping entity names to node IDs.
|
|
150
|
+
*/
|
|
151
|
+
export type EntityIndex = Record<string, string[]>;
|
|
152
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graph/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB,gEAAgE;;IAEhE,gEAAgE;;IAEhE,6CAA6C;;IAE7C,sDAAsD;;CAE9C,CAAA;AAEV,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,C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5D;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,EAAE,CAAA;IACrB,QAAQ,EAAE,SAAS,EAAE,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAEhD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph types for RLM-Graph knowledge storage.
|
|
3
|
+
*
|
|
4
|
+
* Defines the node and edge types for the knowledge graph that stores
|
|
5
|
+
* archived conversation context.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* Node types in the knowledge graph.
|
|
10
|
+
*/
|
|
11
|
+
export const NodeType = {
|
|
12
|
+
/** Top-level document representing an archived context block */
|
|
13
|
+
DOCUMENT: "document",
|
|
14
|
+
/** Section within a document (e.g., markdown header section) */
|
|
15
|
+
SECTION: "section",
|
|
16
|
+
/** Individual content chunk for retrieval */
|
|
17
|
+
CHUNK: "chunk",
|
|
18
|
+
/** Named entity (code element, file path, concept) */
|
|
19
|
+
ENTITY: "entity",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Relationship types between nodes.
|
|
23
|
+
*/
|
|
24
|
+
export const RelationType = {
|
|
25
|
+
/** Document contains section */
|
|
26
|
+
HAS_SECTION: "has_section",
|
|
27
|
+
/** Section/Document contains chunk */
|
|
28
|
+
HAS_CHUNK: "has_chunk",
|
|
29
|
+
/** Chunk mentions entity */
|
|
30
|
+
MENTIONS: "mentions",
|
|
31
|
+
/** Related concepts */
|
|
32
|
+
RELATED_TO: "related_to",
|
|
33
|
+
/** Temporal ordering (chunk follows chunk) */
|
|
34
|
+
FOLLOWS: "follows",
|
|
35
|
+
/** Parent-child relationship */
|
|
36
|
+
PARENT_OF: "parent_of",
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Entity types for extracted entities.
|
|
40
|
+
*/
|
|
41
|
+
export const EntityType = {
|
|
42
|
+
/** Code element (class, function, variable) */
|
|
43
|
+
CODE_ELEMENT: "code_element",
|
|
44
|
+
/** File path */
|
|
45
|
+
FILE_PATH: "file_path",
|
|
46
|
+
/** Proper noun / named concept */
|
|
47
|
+
PROPER_NOUN: "proper_noun",
|
|
48
|
+
/** Reference (link, citation) */
|
|
49
|
+
REFERENCE: "reference",
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Graph node schema.
|
|
53
|
+
*/
|
|
54
|
+
export const GraphNodeSchema = z.object({
|
|
55
|
+
/** Unique node identifier */
|
|
56
|
+
id: z.string(),
|
|
57
|
+
/** Session this node belongs to */
|
|
58
|
+
sessionID: z.string(),
|
|
59
|
+
/** Node type */
|
|
60
|
+
type: z.enum(["document", "section", "chunk", "entity"]),
|
|
61
|
+
/** Node content (text, entity name, etc.) */
|
|
62
|
+
content: z.string(),
|
|
63
|
+
/** Additional metadata */
|
|
64
|
+
metadata: z.record(z.any()).default({}),
|
|
65
|
+
/** Optional embedding vector */
|
|
66
|
+
embedding: z.array(z.number()).optional(),
|
|
67
|
+
/** Creation timestamp */
|
|
68
|
+
createdAt: z.number(),
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Graph edge schema.
|
|
72
|
+
*/
|
|
73
|
+
export const GraphEdgeSchema = z.object({
|
|
74
|
+
/** Source node ID */
|
|
75
|
+
sourceID: z.string(),
|
|
76
|
+
/** Target node ID */
|
|
77
|
+
targetID: z.string(),
|
|
78
|
+
/** Relationship type */
|
|
79
|
+
relationship: z.enum([
|
|
80
|
+
"has_section",
|
|
81
|
+
"has_chunk",
|
|
82
|
+
"mentions",
|
|
83
|
+
"related_to",
|
|
84
|
+
"follows",
|
|
85
|
+
"parent_of",
|
|
86
|
+
]),
|
|
87
|
+
/** Edge weight (0-1) */
|
|
88
|
+
weight: z.number().min(0).max(1).default(1.0),
|
|
89
|
+
/** Additional metadata */
|
|
90
|
+
metadata: z.record(z.any()).default({}),
|
|
91
|
+
/** Creation timestamp */
|
|
92
|
+
createdAt: z.number(),
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/graph/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,gEAAgE;IAChE,QAAQ,EAAE,UAAU;IACpB,gEAAgE;IAChE,OAAO,EAAE,SAAS;IAClB,6CAA6C;IAC7C,KAAK,EAAE,OAAO;IACd,sDAAsD;IACtD,MAAM,EAAE,QAAQ;CACR,CAAA;AAIV;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,gCAAgC;IAChC,WAAW,EAAE,aAAa;IAC1B,sCAAsC;IACtC,SAAS,EAAE,WAAW;IACtB,4BAA4B;IAC5B,QAAQ,EAAE,UAAU;IACpB,uBAAuB;IACvB,UAAU,EAAE,YAAY;IACxB,8CAA8C;IAC9C,OAAO,EAAE,SAAS;IAClB,gCAAgC;IAChC,SAAS,EAAE,WAAW;CACd,CAAA;AAIV;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,+CAA+C;IAC/C,YAAY,EAAE,cAAc;IAC5B,gBAAgB;IAChB,SAAS,EAAE,WAAW;IACtB,kCAAkC;IAClC,WAAW,EAAE,aAAa;IAC1B,iCAAiC;IACjC,SAAS,EAAE,WAAW;CACd,CAAA;AAIV;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,6BAA6B;IAC7B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,mCA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
|
|
|
1
|
+
/**
|
|
2
|
+
* ClaudeCode RLM Plugin for Claude Code
|
|
3
|
+
*
|
|
4
|
+
* Enhances Claude Code's RLM system with:
|
|
5
|
+
* - Knowledge graph-based context storage (74x faster reads)
|
|
6
|
+
* - Extended reference patterns (40+ patterns)
|
|
7
|
+
* - Enhanced hybrid search with recency weighting
|
|
8
|
+
* - Entity extraction and linking
|
|
9
|
+
* - Custom tools for graph query and memory search
|
|
10
|
+
*
|
|
11
|
+
* @module claudecode-rlm
|
|
12
|
+
*/
|
|
13
|
+
import type { Plugin } from "./plugin-types.js";
|
|
14
|
+
export * from "./graph/index.js";
|
|
15
|
+
export * from "./search/index.js";
|
|
16
|
+
export * from "./tools/index.js";
|
|
17
|
+
export { parseConfig, type PluginConfig } from "./config.js";
|
|
18
|
+
export type { Plugin, Hooks, PluginInput } from "./plugin-types.js";
|
|
19
|
+
/**
|
|
20
|
+
* ClaudeCode RLM Plugin entry point.
|
|
21
|
+
*
|
|
22
|
+
* Registers hooks for:
|
|
23
|
+
* - experimental.chat.messages.transform: Inject graph-based context
|
|
24
|
+
* - experimental.session.compacting: Add entity summaries
|
|
25
|
+
* - event: Listen for rlm.archived to ingest into graph
|
|
26
|
+
* - tool: Register graph_query and memory_enhanced tools
|
|
27
|
+
*/
|
|
28
|
+
export declare const ClaudeCodeRLMPlugin: Plugin;
|
|
29
|
+
export default ClaudeCodeRLMPlugin;
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAsB,MAAM,mBAAmB,CAAA;AAYnE,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAC5D,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAenE;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAqLjC,CAAA;AAGD,eAAe,mBAAmB,CAAA"}
|