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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference patterns for detecting context-related queries.
|
|
3
|
+
*
|
|
4
|
+
* These patterns trigger proactive context retrieval from the
|
|
5
|
+
* knowledge graph when detected in user messages.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Explicit memory reference patterns.
|
|
9
|
+
* High confidence that user is referring to past context.
|
|
10
|
+
*/
|
|
11
|
+
export declare const EXPLICIT_MEMORY_PATTERNS: RegExp[];
|
|
12
|
+
/**
|
|
13
|
+
* Extended patterns from PinkyClawd.
|
|
14
|
+
* Broader context references and conversational cues.
|
|
15
|
+
*/
|
|
16
|
+
export declare const EXTENDED_PATTERNS: RegExp[];
|
|
17
|
+
/**
|
|
18
|
+
* Task completion patterns.
|
|
19
|
+
* Indicates a task may have been completed.
|
|
20
|
+
*/
|
|
21
|
+
export declare const TASK_COMPLETION_PATTERNS: RegExp[];
|
|
22
|
+
/**
|
|
23
|
+
* All patterns combined.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ALL_PATTERNS: RegExp[];
|
|
26
|
+
/**
|
|
27
|
+
* Check if a message contains reference patterns.
|
|
28
|
+
*/
|
|
29
|
+
export declare function detectsReference(message: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Get all matching patterns in a message.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getMatchingPatterns(message: string): RegExp[];
|
|
34
|
+
/**
|
|
35
|
+
* Check if a message indicates task completion.
|
|
36
|
+
*/
|
|
37
|
+
export declare function detectsTaskCompletion(message: string): boolean;
|
|
38
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/search/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,EA0B5C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAmDrC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAS5C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,EAGhC,CAAA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAE7D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference patterns for detecting context-related queries.
|
|
3
|
+
*
|
|
4
|
+
* These patterns trigger proactive context retrieval from the
|
|
5
|
+
* knowledge graph when detected in user messages.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Explicit memory reference patterns.
|
|
9
|
+
* High confidence that user is referring to past context.
|
|
10
|
+
*/
|
|
11
|
+
export const EXPLICIT_MEMORY_PATTERNS = [
|
|
12
|
+
// Direct memory references
|
|
13
|
+
/\bremember\s+(when|that|the|what|how)/i,
|
|
14
|
+
/\bdo\s+you\s+remember/i,
|
|
15
|
+
/\bcan\s+you\s+recall/i,
|
|
16
|
+
/\brecall\s+(when|that|the|what|how)/i,
|
|
17
|
+
/\byou\s+mentioned/i,
|
|
18
|
+
/\byou\s+said/i,
|
|
19
|
+
/\byou\s+told\s+me/i,
|
|
20
|
+
/\bwe\s+(discussed|talked\s+about)/i,
|
|
21
|
+
// Temporal references
|
|
22
|
+
/\bearlier\s+(you|we|I)/i,
|
|
23
|
+
/\bpreviously\s+(you|we|I)/i,
|
|
24
|
+
/\bbefore\s+(you|we|I)/i,
|
|
25
|
+
/\blast\s+time/i,
|
|
26
|
+
/\bthe\s+other\s+day/i,
|
|
27
|
+
/\ba\s+while\s+ago/i,
|
|
28
|
+
/\bsome\s+time\s+ago/i,
|
|
29
|
+
// Context continuation
|
|
30
|
+
/\bpick\s+up\s+where/i,
|
|
31
|
+
/\bcontinue\s+(from|where|with)/i,
|
|
32
|
+
/\bresume\s+(from|where)/i,
|
|
33
|
+
/\bback\s+to\s+(what|where)/i,
|
|
34
|
+
/\bgoing\s+back\s+to/i,
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Extended patterns from PinkyClawd.
|
|
38
|
+
* Broader context references and conversational cues.
|
|
39
|
+
*/
|
|
40
|
+
export const EXTENDED_PATTERNS = [
|
|
41
|
+
// Historical task references
|
|
42
|
+
/\bwhat\s+did\s+we\s+(do|try|use|build|create|implement|fix)/i,
|
|
43
|
+
/\bwhat\s+have\s+we\s+(done|tried|built|created|implemented|fixed)/i,
|
|
44
|
+
/\bwhere\s+were\s+we/i,
|
|
45
|
+
/\bwhere\s+did\s+we\s+(leave\s+off|stop)/i,
|
|
46
|
+
/\bhow\s+did\s+we\s+(do|handle|implement|fix|solve)/i,
|
|
47
|
+
/\bwhy\s+did\s+we\s+(decide|choose|use)/i,
|
|
48
|
+
// Continuation cues
|
|
49
|
+
/\blet's\s+(continue|resume|pick\s+up)/i,
|
|
50
|
+
/\blet's\s+go\s+back\s+to/i,
|
|
51
|
+
/\bcan\s+we\s+(continue|resume)/i,
|
|
52
|
+
/\bshall\s+we\s+(continue|resume)/i,
|
|
53
|
+
// Decision references
|
|
54
|
+
/\bthe\s+approach\s+we\s+(chose|decided|used)/i,
|
|
55
|
+
/\bthe\s+solution\s+we/i,
|
|
56
|
+
/\bthe\s+method\s+we/i,
|
|
57
|
+
/\bthe\s+way\s+we/i,
|
|
58
|
+
/\bour\s+(approach|solution|implementation)/i,
|
|
59
|
+
// Error/fix references
|
|
60
|
+
/\bthat\s+error\s+(we|you)/i,
|
|
61
|
+
/\bthe\s+bug\s+(we|you)/i,
|
|
62
|
+
/\bthe\s+issue\s+(we|you)/i,
|
|
63
|
+
/\bthe\s+problem\s+(we|you)/i,
|
|
64
|
+
/\bwhen\s+(it|that)\s+(broke|failed|crashed)/i,
|
|
65
|
+
// Feature references
|
|
66
|
+
/\bthe\s+feature\s+(we|you)/i,
|
|
67
|
+
/\bthat\s+functionality/i,
|
|
68
|
+
/\bthe\s+component\s+(we|you)/i,
|
|
69
|
+
/\bthe\s+module\s+(we|you)/i,
|
|
70
|
+
// Code references
|
|
71
|
+
/\bthat\s+function\s+(we|you)/i,
|
|
72
|
+
/\bthe\s+class\s+(we|you)/i,
|
|
73
|
+
/\bthat\s+file\s+(we|you)/i,
|
|
74
|
+
/\bthe\s+code\s+(we|you)/i,
|
|
75
|
+
// Discussion references
|
|
76
|
+
/\bas\s+we\s+(discussed|mentioned|said)/i,
|
|
77
|
+
/\blike\s+(we|you)\s+said/i,
|
|
78
|
+
/\baccording\s+to\s+(our|what\s+we)/i,
|
|
79
|
+
/\bbased\s+on\s+(our|what\s+we)/i,
|
|
80
|
+
// Session references
|
|
81
|
+
/\bin\s+our\s+(last|previous)\s+(session|conversation|chat)/i,
|
|
82
|
+
/\bearlier\s+in\s+this\s+(session|conversation)/i,
|
|
83
|
+
/\bfrom\s+our\s+(last|previous)/i,
|
|
84
|
+
];
|
|
85
|
+
/**
|
|
86
|
+
* Task completion patterns.
|
|
87
|
+
* Indicates a task may have been completed.
|
|
88
|
+
*/
|
|
89
|
+
export const TASK_COMPLETION_PATTERNS = [
|
|
90
|
+
/\b(done|finished|completed|fixed|resolved|implemented|working\s+now)/i,
|
|
91
|
+
/\bthat\s+(should|seems\s+to)\s+(work|fix|solve)/i,
|
|
92
|
+
/\blet\s+me\s+know\s+if/i,
|
|
93
|
+
/\btry\s+(it|that)\s+(now|again)/i,
|
|
94
|
+
/\bshould\s+be\s+(good|fixed|working)/i,
|
|
95
|
+
/\bI've\s+(finished|completed|done|fixed)/i,
|
|
96
|
+
/\bthat's\s+(it|all|done)/i,
|
|
97
|
+
/\ball\s+(done|set|good)/i,
|
|
98
|
+
];
|
|
99
|
+
/**
|
|
100
|
+
* All patterns combined.
|
|
101
|
+
*/
|
|
102
|
+
export const ALL_PATTERNS = [
|
|
103
|
+
...EXPLICIT_MEMORY_PATTERNS,
|
|
104
|
+
...EXTENDED_PATTERNS,
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* Check if a message contains reference patterns.
|
|
108
|
+
*/
|
|
109
|
+
export function detectsReference(message) {
|
|
110
|
+
return ALL_PATTERNS.some((pattern) => pattern.test(message));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get all matching patterns in a message.
|
|
114
|
+
*/
|
|
115
|
+
export function getMatchingPatterns(message) {
|
|
116
|
+
return ALL_PATTERNS.filter((pattern) => pattern.test(message));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check if a message indicates task completion.
|
|
120
|
+
*/
|
|
121
|
+
export function detectsTaskCompletion(message) {
|
|
122
|
+
return TASK_COMPLETION_PATTERNS.some((pattern) => pattern.test(message));
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/search/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAa;IAChD,2BAA2B;IAC3B,wCAAwC;IACxC,wBAAwB;IACxB,uBAAuB;IACvB,sCAAsC;IACtC,oBAAoB;IACpB,eAAe;IACf,oBAAoB;IACpB,oCAAoC;IAEpC,sBAAsB;IACtB,yBAAyB;IACzB,4BAA4B;IAC5B,wBAAwB;IACxB,gBAAgB;IAChB,sBAAsB;IACtB,oBAAoB;IACpB,sBAAsB;IAEtB,uBAAuB;IACvB,sBAAsB;IACtB,iCAAiC;IACjC,0BAA0B;IAC1B,6BAA6B;IAC7B,sBAAsB;CACvB,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAa;IACzC,6BAA6B;IAC7B,8DAA8D;IAC9D,oEAAoE;IACpE,sBAAsB;IACtB,0CAA0C;IAC1C,qDAAqD;IACrD,yCAAyC;IAEzC,oBAAoB;IACpB,wCAAwC;IACxC,2BAA2B;IAC3B,iCAAiC;IACjC,mCAAmC;IAEnC,sBAAsB;IACtB,+CAA+C;IAC/C,wBAAwB;IACxB,sBAAsB;IACtB,mBAAmB;IACnB,6CAA6C;IAE7C,uBAAuB;IACvB,4BAA4B;IAC5B,yBAAyB;IACzB,2BAA2B;IAC3B,6BAA6B;IAC7B,8CAA8C;IAE9C,qBAAqB;IACrB,6BAA6B;IAC7B,yBAAyB;IACzB,+BAA+B;IAC/B,4BAA4B;IAE5B,kBAAkB;IAClB,+BAA+B;IAC/B,2BAA2B;IAC3B,2BAA2B;IAC3B,0BAA0B;IAE1B,wBAAwB;IACxB,yCAAyC;IACzC,2BAA2B;IAC3B,qCAAqC;IACrC,iCAAiC;IAEjC,qBAAqB;IACrB,6DAA6D;IAC7D,iDAAiD;IACjD,iCAAiC;CAClC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAa;IAChD,uEAAuE;IACvE,kDAAkD;IAClD,yBAAyB;IACzB,kCAAkC;IAClC,uCAAuC;IACvC,2CAA2C;IAC3C,2BAA2B;IAC3B,0BAA0B;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAa;IACpC,GAAG,wBAAwB;IAC3B,GAAG,iBAAiB;CACrB,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph query tool for searching the knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Allows the LLM to query the graph structure for:
|
|
5
|
+
* - Entity relationships
|
|
6
|
+
* - Chunk context expansion
|
|
7
|
+
* - Path finding between concepts
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolDefinition } from "../plugin-types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Graph query tool definition.
|
|
12
|
+
*/
|
|
13
|
+
export declare const graphQueryTool: ToolDefinition;
|
|
14
|
+
//# sourceMappingURL=graph-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/tools/graph-query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,oBAAoB,CAAA;AAqBpE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,cA8N5B,CAAA"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph query tool for searching the knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Allows the LLM to query the graph structure for:
|
|
5
|
+
* - Entity relationships
|
|
6
|
+
* - Chunk context expansion
|
|
7
|
+
* - Path finding between concepts
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { GraphStorage, GraphSearcher, GraphTraverser, NodeType, } from "../graph/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Format a node for display.
|
|
13
|
+
*/
|
|
14
|
+
function formatNode(node, index) {
|
|
15
|
+
const lines = [`[${index + 1}] ${node.type.toUpperCase()}: ${node.id}`];
|
|
16
|
+
lines.push(` Content: ${node.content.slice(0, 200)}${node.content.length > 200 ? "..." : ""}`);
|
|
17
|
+
if (node.metadata && Object.keys(node.metadata).length > 0) {
|
|
18
|
+
lines.push(` Metadata: ${JSON.stringify(node.metadata)}`);
|
|
19
|
+
}
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Graph query tool definition.
|
|
24
|
+
*/
|
|
25
|
+
export const graphQueryTool = {
|
|
26
|
+
description: `Query the PinkyClawd knowledge graph to find related context and entities.
|
|
27
|
+
|
|
28
|
+
Operations:
|
|
29
|
+
- search: Find chunks matching a query (uses hybrid keyword + entity matching)
|
|
30
|
+
- entity: Find all chunks mentioning a specific entity (code element, file, concept)
|
|
31
|
+
- expand: Get related context around a specific node
|
|
32
|
+
- path: Find connection path between two entities
|
|
33
|
+
|
|
34
|
+
Use this tool when you need to:
|
|
35
|
+
- Find where something was discussed or defined
|
|
36
|
+
- Understand relationships between concepts
|
|
37
|
+
- Get historical context about a topic
|
|
38
|
+
- Navigate the conversation history structurally`,
|
|
39
|
+
args: {
|
|
40
|
+
operation: z
|
|
41
|
+
.enum(["search", "entity", "expand", "path"])
|
|
42
|
+
.describe("The operation to perform"),
|
|
43
|
+
query: z
|
|
44
|
+
.string()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Search query or entity name (for search/entity operations)"),
|
|
47
|
+
nodeId: z
|
|
48
|
+
.string()
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Node ID to expand from (for expand operation)"),
|
|
51
|
+
startEntity: z
|
|
52
|
+
.string()
|
|
53
|
+
.optional()
|
|
54
|
+
.describe("Starting entity name (for path operation)"),
|
|
55
|
+
endEntity: z
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Ending entity name (for path operation)"),
|
|
59
|
+
limit: z
|
|
60
|
+
.number()
|
|
61
|
+
.optional()
|
|
62
|
+
.default(10)
|
|
63
|
+
.describe("Maximum results to return"),
|
|
64
|
+
},
|
|
65
|
+
execute: async (args, context) => {
|
|
66
|
+
const { operation, query, nodeId, startEntity, endEntity, limit = 10 } = args;
|
|
67
|
+
const sessionID = context.sessionID;
|
|
68
|
+
try {
|
|
69
|
+
switch (operation) {
|
|
70
|
+
case "search": {
|
|
71
|
+
if (!query) {
|
|
72
|
+
return {
|
|
73
|
+
title: "Graph Query - Search",
|
|
74
|
+
output: "Error: 'query' parameter is required for search operation",
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const results = GraphSearcher.search(sessionID, query, {
|
|
78
|
+
limit,
|
|
79
|
+
expandContext: true,
|
|
80
|
+
});
|
|
81
|
+
if (results.length === 0) {
|
|
82
|
+
return {
|
|
83
|
+
title: "Graph Query - Search",
|
|
84
|
+
output: `No results found for query: "${query}"`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const output = [
|
|
88
|
+
`Found ${results.length} results for "${query}":`,
|
|
89
|
+
"",
|
|
90
|
+
...results.map((r, i) => formatNode(r.node, i)),
|
|
91
|
+
].join("\n");
|
|
92
|
+
return {
|
|
93
|
+
title: "Graph Query - Search",
|
|
94
|
+
output,
|
|
95
|
+
metadata: { resultCount: results.length },
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
case "entity": {
|
|
99
|
+
if (!query) {
|
|
100
|
+
return {
|
|
101
|
+
title: "Graph Query - Entity",
|
|
102
|
+
output: "Error: 'query' parameter is required for entity operation",
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const chunks = GraphTraverser.getEntityContext(sessionID, query, limit);
|
|
106
|
+
if (chunks.length === 0) {
|
|
107
|
+
return {
|
|
108
|
+
title: "Graph Query - Entity",
|
|
109
|
+
output: `No chunks found mentioning entity: "${query}"`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const output = [
|
|
113
|
+
`Found ${chunks.length} chunks mentioning "${query}":`,
|
|
114
|
+
"",
|
|
115
|
+
...chunks.map((node, i) => formatNode(node, i)),
|
|
116
|
+
].join("\n");
|
|
117
|
+
return {
|
|
118
|
+
title: "Graph Query - Entity",
|
|
119
|
+
output,
|
|
120
|
+
metadata: { resultCount: chunks.length },
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
case "expand": {
|
|
124
|
+
if (!nodeId) {
|
|
125
|
+
return {
|
|
126
|
+
title: "Graph Query - Expand",
|
|
127
|
+
output: "Error: 'nodeId' parameter is required for expand operation",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const expanded = GraphTraverser.expandContext(sessionID, [nodeId], 2, limit);
|
|
131
|
+
if (expanded.length === 0) {
|
|
132
|
+
return {
|
|
133
|
+
title: "Graph Query - Expand",
|
|
134
|
+
output: `No context found around node: "${nodeId}"`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const output = [
|
|
138
|
+
`Expanded context around "${nodeId}" (${expanded.length} nodes):`,
|
|
139
|
+
"",
|
|
140
|
+
...expanded.map((node, i) => formatNode(node, i)),
|
|
141
|
+
].join("\n");
|
|
142
|
+
return {
|
|
143
|
+
title: "Graph Query - Expand",
|
|
144
|
+
output,
|
|
145
|
+
metadata: { resultCount: expanded.length },
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
case "path": {
|
|
149
|
+
if (!startEntity || !endEntity) {
|
|
150
|
+
return {
|
|
151
|
+
title: "Graph Query - Path",
|
|
152
|
+
output: "Error: 'startEntity' and 'endEntity' parameters are required for path operation",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// Find entity nodes
|
|
156
|
+
const startNodes = GraphStorage.searchNodes(sessionID, startEntity, NodeType.ENTITY, 1);
|
|
157
|
+
const endNodes = GraphStorage.searchNodes(sessionID, endEntity, NodeType.ENTITY, 1);
|
|
158
|
+
if (startNodes.length === 0) {
|
|
159
|
+
return {
|
|
160
|
+
title: "Graph Query - Path",
|
|
161
|
+
output: `Start entity not found: "${startEntity}"`,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (endNodes.length === 0) {
|
|
165
|
+
return {
|
|
166
|
+
title: "Graph Query - Path",
|
|
167
|
+
output: `End entity not found: "${endEntity}"`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const path = GraphTraverser.findPath(sessionID, startNodes[0].id, endNodes[0].id, 5);
|
|
171
|
+
if (!path) {
|
|
172
|
+
return {
|
|
173
|
+
title: "Graph Query - Path",
|
|
174
|
+
output: `No path found between "${startEntity}" and "${endEntity}"`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const output = [
|
|
178
|
+
`Path from "${startEntity}" to "${endEntity}" (${path.length} nodes):`,
|
|
179
|
+
"",
|
|
180
|
+
...path.map((node, i) => formatNode(node, i)),
|
|
181
|
+
].join("\n");
|
|
182
|
+
return {
|
|
183
|
+
title: "Graph Query - Path",
|
|
184
|
+
output,
|
|
185
|
+
metadata: { pathLength: path.length },
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
default:
|
|
189
|
+
return {
|
|
190
|
+
title: "Graph Query",
|
|
191
|
+
output: `Unknown operation: ${operation}`,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
title: "Graph Query - Error",
|
|
198
|
+
output: `Error executing graph query: ${error instanceof Error ? error.message : String(error)}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
//# sourceMappingURL=graph-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-query.js","sourceRoot":"","sources":["../../src/tools/graph-query.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,GAET,MAAM,mBAAmB,CAAA;AAE1B;;GAEG;AACH,SAAS,UAAU,CAAC,IAAe,EAAE,KAAa;IAChD,MAAM,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACvE,KAAK,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACjG,IAAI,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3D,KAAK,CAAC,IAAI,CAA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,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;qBAC9C,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBAEZ,OAAO;wBACL,KAAK,EAAE,oBAAoB;wBAC3B,MAAM;wBACN,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE;qBACtC,CAAA;gBACH,CAAC;gBAED;oBACE,OAAO;wBACL,KAAK,EAAE,aAAa;wBACpB,MAAM,EAAE,sBAAsB,SAAS,EAAE;qBAC1C,CAAA;YACL,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,KAAK,EAAE,qBAAqB;gBAC5B,MAAM,EAAE,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aACjG,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools module exports.
|
|
3
|
+
*
|
|
4
|
+
* Custom tools for graph query and memory search.
|
|
5
|
+
*/
|
|
6
|
+
export { graphQueryTool } from "./graph-query.js";
|
|
7
|
+
export { memoryEnhancedTool, listEntitiesTool, graphStatsTool } from "./memory.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-enhanced tools for context retrieval.
|
|
3
|
+
*
|
|
4
|
+
* Provides tools for searching archived context with
|
|
5
|
+
* enhanced scoring and entity awareness.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition } from "../plugin-types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Memory enhanced search tool.
|
|
10
|
+
*/
|
|
11
|
+
export declare const memoryEnhancedTool: ToolDefinition;
|
|
12
|
+
/**
|
|
13
|
+
* List entities tool.
|
|
14
|
+
*/
|
|
15
|
+
export declare const listEntitiesTool: ToolDefinition;
|
|
16
|
+
/**
|
|
17
|
+
* Graph stats tool.
|
|
18
|
+
*/
|
|
19
|
+
export declare const graphStatsTool: ToolDefinition;
|
|
20
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,oBAAoB,CAAA;AAapE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,cAgEhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAmE9B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,cA0C5B,CAAA"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory-enhanced tools for context retrieval.
|
|
3
|
+
*
|
|
4
|
+
* Provides tools for searching archived context with
|
|
5
|
+
* enhanced scoring and entity awareness.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { GraphStorage, NodeType } from "../graph/index.js";
|
|
9
|
+
import { EnhancedSearch } from "../search/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Format a node for display.
|
|
12
|
+
*/
|
|
13
|
+
function formatNode(node, index) {
|
|
14
|
+
const lines = [`[${index + 1}] ${node.type.toUpperCase()}`];
|
|
15
|
+
lines.push(` ${node.content.slice(0, 300)}${node.content.length > 300 ? "..." : ""}`);
|
|
16
|
+
return lines.join("\n");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Memory enhanced search tool.
|
|
20
|
+
*/
|
|
21
|
+
export const memoryEnhancedTool = {
|
|
22
|
+
description: `Search archived conversation context with enhanced scoring.
|
|
23
|
+
|
|
24
|
+
Features:
|
|
25
|
+
- Keyword matching with recency weighting
|
|
26
|
+
- Entity-aware boosting
|
|
27
|
+
- Graph traversal for related context
|
|
28
|
+
|
|
29
|
+
Use this tool when you need to:
|
|
30
|
+
- Find past discussions about a topic
|
|
31
|
+
- Recall specific decisions or implementations
|
|
32
|
+
- Get context about entities (classes, files, concepts)`,
|
|
33
|
+
args: {
|
|
34
|
+
query: z.string().describe("Search query"),
|
|
35
|
+
limit: z.number().optional().default(5).describe("Maximum results"),
|
|
36
|
+
recencyWeight: z
|
|
37
|
+
.number()
|
|
38
|
+
.optional()
|
|
39
|
+
.default(0.3)
|
|
40
|
+
.describe("Weight for recency (0-1)"),
|
|
41
|
+
},
|
|
42
|
+
execute: async (args, context) => {
|
|
43
|
+
const { query, limit = 5, recencyWeight = 0.3 } = args;
|
|
44
|
+
const sessionID = context.sessionID;
|
|
45
|
+
try {
|
|
46
|
+
const results = EnhancedSearch.search(sessionID, query, {
|
|
47
|
+
limit,
|
|
48
|
+
recencyWeight,
|
|
49
|
+
});
|
|
50
|
+
if (results.length === 0) {
|
|
51
|
+
return {
|
|
52
|
+
title: "Memory Search",
|
|
53
|
+
output: `No archived context found for: "${query}"`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const output = [
|
|
57
|
+
`Found ${results.length} relevant context blocks for "${query}":`,
|
|
58
|
+
"",
|
|
59
|
+
...results.map((r, i) => {
|
|
60
|
+
const node = r.node;
|
|
61
|
+
return [
|
|
62
|
+
`[${i + 1}] Score: ${r.finalScore.toFixed(2)} (recency: ${r.recencyScore.toFixed(2)})`,
|
|
63
|
+
` ${node.content.slice(0, 300)}${node.content.length > 300 ? "..." : ""}`,
|
|
64
|
+
].join("\n");
|
|
65
|
+
}),
|
|
66
|
+
].join("\n");
|
|
67
|
+
return {
|
|
68
|
+
title: "Memory Search",
|
|
69
|
+
output,
|
|
70
|
+
metadata: { resultCount: results.length },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
title: "Memory Search - Error",
|
|
76
|
+
output: `Error searching memory: ${error instanceof Error ? error.message : String(error)}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* List entities tool.
|
|
83
|
+
*/
|
|
84
|
+
export const listEntitiesTool = {
|
|
85
|
+
description: `List entities (code elements, files, concepts) tracked in the knowledge graph.
|
|
86
|
+
|
|
87
|
+
Use this to discover what entities have been discussed and can be queried.`,
|
|
88
|
+
args: {
|
|
89
|
+
filter: z.string().optional().describe("Filter entities by name"),
|
|
90
|
+
limit: z.number().optional().default(20).describe("Maximum entities"),
|
|
91
|
+
},
|
|
92
|
+
execute: async (args, context) => {
|
|
93
|
+
const { filter, limit = 20 } = args;
|
|
94
|
+
const sessionID = context.sessionID;
|
|
95
|
+
try {
|
|
96
|
+
let entities;
|
|
97
|
+
if (filter) {
|
|
98
|
+
entities = GraphStorage.searchNodes(sessionID, filter, NodeType.ENTITY, limit);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
entities = GraphStorage.getNodesByType(sessionID, NodeType.ENTITY, limit);
|
|
102
|
+
}
|
|
103
|
+
if (entities.length === 0) {
|
|
104
|
+
return {
|
|
105
|
+
title: "List Entities",
|
|
106
|
+
output: filter
|
|
107
|
+
? `No entities found matching: "${filter}"`
|
|
108
|
+
: "No entities tracked in the knowledge graph yet.",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Group by entity type
|
|
112
|
+
const byType = new Map();
|
|
113
|
+
for (const entity of entities) {
|
|
114
|
+
const type = entity.metadata?.entityType || "unknown";
|
|
115
|
+
if (!byType.has(type))
|
|
116
|
+
byType.set(type, []);
|
|
117
|
+
byType.get(type).push(entity);
|
|
118
|
+
}
|
|
119
|
+
const sections = [`Found ${entities.length} entities:`];
|
|
120
|
+
for (const [type, typeEntities] of byType) {
|
|
121
|
+
sections.push("");
|
|
122
|
+
sections.push(`${type.toUpperCase()}:`);
|
|
123
|
+
for (const entity of typeEntities) {
|
|
124
|
+
sections.push(` - ${entity.content}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
title: "List Entities",
|
|
129
|
+
output: sections.join("\n"),
|
|
130
|
+
metadata: { entityCount: entities.length },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return {
|
|
135
|
+
title: "List Entities - Error",
|
|
136
|
+
output: `Error listing entities: ${error instanceof Error ? error.message : String(error)}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Graph stats tool.
|
|
143
|
+
*/
|
|
144
|
+
export const graphStatsTool = {
|
|
145
|
+
description: `Get statistics about the knowledge graph.
|
|
146
|
+
|
|
147
|
+
Shows counts of nodes, edges, and cache performance.`,
|
|
148
|
+
args: {},
|
|
149
|
+
execute: async (args, context) => {
|
|
150
|
+
const sessionID = context.sessionID;
|
|
151
|
+
try {
|
|
152
|
+
const stats = GraphStorage.getStats(sessionID);
|
|
153
|
+
const output = [
|
|
154
|
+
"Knowledge Graph Statistics:",
|
|
155
|
+
"",
|
|
156
|
+
`Total nodes: ${stats.nodeCount}`,
|
|
157
|
+
`Total edges: ${stats.edgeCount}`,
|
|
158
|
+
"",
|
|
159
|
+
"Nodes by type:",
|
|
160
|
+
...Object.entries(stats.nodesByType).map(([type, count]) => ` - ${type}: ${count}`),
|
|
161
|
+
"",
|
|
162
|
+
"Cache performance:",
|
|
163
|
+
` - Hits: ${stats.cacheStats.hits}`,
|
|
164
|
+
` - Misses: ${stats.cacheStats.misses}`,
|
|
165
|
+
` - Hit rate: ${stats.cacheStats.hitRate}`,
|
|
166
|
+
].join("\n");
|
|
167
|
+
return {
|
|
168
|
+
title: "Graph Stats",
|
|
169
|
+
output,
|
|
170
|
+
metadata: stats,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
title: "Graph Stats - Error",
|
|
176
|
+
output: `Error getting stats: ${error instanceof Error ? error.message : String(error)}`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/tools/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAiB,QAAQ,EAAkB,MAAM,mBAAmB,CAAA;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,SAAS,UAAU,CAAC,IAAe,EAAE,KAAa;IAChD,MAAM,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;IAC3D,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAA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