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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 tekcin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# claudecode-rlm
|
|
2
|
+
|
|
3
|
+
**Advanced RLM (Recursive Language Model) plugin for [Claude Code](https://github.com/tekcin/claude-code) - Knowledge graph-based context storage with 74x faster reads.**
|
|
4
|
+
|
|
5
|
+
**Author:** Michael Thornton (tekcin@yahoo.com)
|
|
6
|
+
**Repository:** https://github.com/tekcin/claudecode-rlm
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Automatic Context Injection** - Proactively injects relevant context when reference patterns detected
|
|
11
|
+
- **Knowledge Graph Storage** - Hierarchical context storage (Document → Section → Chunk → Entity)
|
|
12
|
+
- **74x Faster Reads** - LRU cache with inverted index for instant retrieval
|
|
13
|
+
- **40+ Reference Patterns** - Extended pattern detection for context references
|
|
14
|
+
- **Enhanced Hybrid Search** - Keyword matching with recency weighting and entity boost
|
|
15
|
+
- **Entity Extraction** - Automatic extraction of code elements, files, and concepts
|
|
16
|
+
- **Custom Tools** - `graph_query`, `memory_enhanced`, `list_entities`, `graph_stats`
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install claudecode-rlm
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or add to your Claude Code configuration:
|
|
25
|
+
|
|
26
|
+
```jsonc
|
|
27
|
+
// .claude/claudecode.jsonc
|
|
28
|
+
{
|
|
29
|
+
"plugin": ["claudecode-rlm"],
|
|
30
|
+
"claudecode-rlm": {
|
|
31
|
+
"graph": {
|
|
32
|
+
"enabled": true,
|
|
33
|
+
"auto_ingest": true
|
|
34
|
+
},
|
|
35
|
+
"enhanced_search": {
|
|
36
|
+
"additional_patterns": true,
|
|
37
|
+
"recency_weight": 0.3,
|
|
38
|
+
"entity_boost": 0.2
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Performance
|
|
45
|
+
|
|
46
|
+
Benchmarks comparing basic vs optimized storage (10,000 nodes):
|
|
47
|
+
|
|
48
|
+
| Operation | Basic | Optimized | Speedup |
|
|
49
|
+
|-----------|-------|-----------|---------|
|
|
50
|
+
| Node reads | 21.3µs | 0.3µs | **74x** |
|
|
51
|
+
| Get by type | 1.1ms | 21µs | **54x** |
|
|
52
|
+
| Bulk insert | 6.07s | 1.21s | **5x** |
|
|
53
|
+
| Search | 0.45ms | 0.65ms | ~1x |
|
|
54
|
+
|
|
55
|
+
The LRU cache achieves **100% hit rate** after initial population, ideal for read-heavy RLM workloads.
|
|
56
|
+
|
|
57
|
+
## Architecture
|
|
58
|
+
|
|
59
|
+
### Knowledge Graph Structure
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Document (archived context block)
|
|
63
|
+
├── Section (markdown header or paragraph group)
|
|
64
|
+
│ ├── Chunk (retrieval unit, ~300 chars)
|
|
65
|
+
│ │ ├── Entity (code element)
|
|
66
|
+
│ │ ├── Entity (file path)
|
|
67
|
+
│ │ └── Entity (concept)
|
|
68
|
+
│ └── Chunk
|
|
69
|
+
│ └── [FOLLOWS] → next chunk
|
|
70
|
+
└── Section
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Storage Optimizations
|
|
74
|
+
|
|
75
|
+
1. **LRU Cache** (2000 nodes/session) - Eliminates repeated disk reads
|
|
76
|
+
2. **Inverted Index** - O(1) keyword lookup instead of O(n) scan
|
|
77
|
+
3. **Batched Writes** - Flushes every 100ms or 50 ops, reducing I/O ~90%
|
|
78
|
+
|
|
79
|
+
### Reference Patterns
|
|
80
|
+
|
|
81
|
+
The plugin detects 40+ patterns that trigger proactive context retrieval:
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
// Explicit memory references
|
|
85
|
+
"do you remember..."
|
|
86
|
+
"we discussed..."
|
|
87
|
+
"earlier we..."
|
|
88
|
+
|
|
89
|
+
// Task references
|
|
90
|
+
"what did we do..."
|
|
91
|
+
"where were we..."
|
|
92
|
+
"let's continue..."
|
|
93
|
+
|
|
94
|
+
// Code references
|
|
95
|
+
"that function we..."
|
|
96
|
+
"the class that..."
|
|
97
|
+
"the file where..."
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Configuration
|
|
101
|
+
|
|
102
|
+
```jsonc
|
|
103
|
+
{
|
|
104
|
+
"claudecode-rlm": {
|
|
105
|
+
"graph": {
|
|
106
|
+
"enabled": true, // Enable graph features
|
|
107
|
+
"auto_ingest": true, // Auto-ingest archived context
|
|
108
|
+
"max_traversal_nodes": 50, // Max nodes in traversal
|
|
109
|
+
"max_traversal_depth": 3 // Max BFS depth
|
|
110
|
+
},
|
|
111
|
+
"enhanced_search": {
|
|
112
|
+
"additional_patterns": true, // Use extended patterns
|
|
113
|
+
"recency_weight": 0.3, // Recency scoring weight (0-1)
|
|
114
|
+
"entity_boost": 0.2, // Entity match boost (0-1)
|
|
115
|
+
"max_age_days": 30, // Max age for recency
|
|
116
|
+
"min_score_threshold": 0.3 // Min score for results
|
|
117
|
+
},
|
|
118
|
+
"task_detection": {
|
|
119
|
+
"auto_archive_on_completion": true
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Tools
|
|
126
|
+
|
|
127
|
+
### graph_query
|
|
128
|
+
|
|
129
|
+
Query the knowledge graph directly:
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
Operations:
|
|
133
|
+
- search: Find chunks matching a query
|
|
134
|
+
- entity: Find chunks mentioning an entity
|
|
135
|
+
- expand: Get related context around a node
|
|
136
|
+
- path: Find connection between entities
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### memory_enhanced
|
|
140
|
+
|
|
141
|
+
Search with enhanced scoring:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
- Keyword matching with recency weighting
|
|
145
|
+
- Entity-aware boosting
|
|
146
|
+
- Graph traversal for related context
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### list_entities
|
|
150
|
+
|
|
151
|
+
List tracked entities (code elements, files, concepts).
|
|
152
|
+
|
|
153
|
+
### graph_stats
|
|
154
|
+
|
|
155
|
+
Get knowledge graph statistics and cache performance.
|
|
156
|
+
|
|
157
|
+
## Development
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Install dependencies
|
|
161
|
+
npm install
|
|
162
|
+
|
|
163
|
+
# Type check
|
|
164
|
+
npm run typecheck
|
|
165
|
+
|
|
166
|
+
# Build
|
|
167
|
+
npm run build
|
|
168
|
+
|
|
169
|
+
# Run benchmarks
|
|
170
|
+
npm run test
|
|
171
|
+
npm run test:optimized
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## How It Works
|
|
175
|
+
|
|
176
|
+
1. **Context Archival**: When Claude Code archives context (RLM threshold reached), claudecode-rlm:
|
|
177
|
+
- Creates a Document node for the archived block
|
|
178
|
+
- Splits content into Sections (by headers or paragraphs)
|
|
179
|
+
- Chunks sections into retrieval units (~300 chars with overlap)
|
|
180
|
+
- Extracts entities (code elements, file paths, concepts)
|
|
181
|
+
- Links everything with typed edges
|
|
182
|
+
|
|
183
|
+
2. **Context Injection**: When a user message matches reference patterns (e.g., "do you remember...", "we discussed..."):
|
|
184
|
+
- claudecode-rlm detects the pattern via `experimental.chat.messages.transform` hook
|
|
185
|
+
- Searches the inverted index for matching chunks
|
|
186
|
+
- Boosts results by entity matches and recency
|
|
187
|
+
- Expands context via graph traversal
|
|
188
|
+
- **Injects relevant context into the message stream before the LLM sees it**
|
|
189
|
+
|
|
190
|
+
3. **Caching**: The LRU cache ensures:
|
|
191
|
+
- Recently accessed nodes are instant to retrieve
|
|
192
|
+
- Cache hit rate approaches 100% in typical usage
|
|
193
|
+
- Memory usage bounded by cache size (2000 nodes)
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
198
|
+
|
|
199
|
+
## Author
|
|
200
|
+
|
|
201
|
+
**Michael Thornton**
|
|
202
|
+
- Email: tekcin@yahoo.com
|
|
203
|
+
- GitHub: [@tekcin](https://github.com/tekcin)
|
|
204
|
+
|
|
205
|
+
## Links
|
|
206
|
+
|
|
207
|
+
- [claudecode-rlm Repository](https://github.com/tekcin/claudecode-rlm)
|
|
208
|
+
- [Claude Code](https://github.com/tekcin/claude-code)
|
|
209
|
+
- [Issues](https://github.com/tekcin/claudecode-rlm/issues)
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin configuration schema.
|
|
3
|
+
*
|
|
4
|
+
* Configuration is loaded from .claude/claudecode.jsonc under the
|
|
5
|
+
* "claudecode-rlm" key.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* Graph configuration schema.
|
|
10
|
+
*/
|
|
11
|
+
export declare const GraphConfigSchema: z.ZodObject<{
|
|
12
|
+
/** Whether graph features are enabled */
|
|
13
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
14
|
+
/** Whether to automatically ingest archived context into graph */
|
|
15
|
+
auto_ingest: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
+
/** Maximum nodes to traverse in a search */
|
|
17
|
+
max_traversal_nodes: z.ZodDefault<z.ZodNumber>;
|
|
18
|
+
/** Maximum depth for graph traversal */
|
|
19
|
+
max_traversal_depth: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
auto_ingest: boolean;
|
|
23
|
+
max_traversal_nodes: number;
|
|
24
|
+
max_traversal_depth: number;
|
|
25
|
+
}, {
|
|
26
|
+
enabled?: boolean | undefined;
|
|
27
|
+
auto_ingest?: boolean | undefined;
|
|
28
|
+
max_traversal_nodes?: number | undefined;
|
|
29
|
+
max_traversal_depth?: number | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Enhanced search configuration schema.
|
|
33
|
+
*/
|
|
34
|
+
export declare const EnhancedSearchConfigSchema: z.ZodObject<{
|
|
35
|
+
/** Use additional reference patterns from PinkyClawd */
|
|
36
|
+
additional_patterns: z.ZodDefault<z.ZodBoolean>;
|
|
37
|
+
/** Weight for recency in scoring (0-1) */
|
|
38
|
+
recency_weight: z.ZodDefault<z.ZodNumber>;
|
|
39
|
+
/** Weight for entity matches in scoring (0-1) */
|
|
40
|
+
entity_boost: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
/** Maximum age in days for recency scoring */
|
|
42
|
+
max_age_days: z.ZodDefault<z.ZodNumber>;
|
|
43
|
+
/** Minimum score threshold for results */
|
|
44
|
+
min_score_threshold: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
additional_patterns: boolean;
|
|
47
|
+
recency_weight: number;
|
|
48
|
+
entity_boost: number;
|
|
49
|
+
max_age_days: number;
|
|
50
|
+
min_score_threshold: number;
|
|
51
|
+
}, {
|
|
52
|
+
additional_patterns?: boolean | undefined;
|
|
53
|
+
recency_weight?: number | undefined;
|
|
54
|
+
entity_boost?: number | undefined;
|
|
55
|
+
max_age_days?: number | undefined;
|
|
56
|
+
min_score_threshold?: number | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Task detection configuration schema.
|
|
60
|
+
*/
|
|
61
|
+
export declare const TaskDetectionConfigSchema: z.ZodObject<{
|
|
62
|
+
/** Archive context when task completion is detected */
|
|
63
|
+
auto_archive_on_completion: z.ZodDefault<z.ZodBoolean>;
|
|
64
|
+
}, "strip", z.ZodTypeAny, {
|
|
65
|
+
auto_archive_on_completion: boolean;
|
|
66
|
+
}, {
|
|
67
|
+
auto_archive_on_completion?: boolean | undefined;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Full plugin configuration schema.
|
|
71
|
+
*/
|
|
72
|
+
export declare const PluginConfigSchema: z.ZodObject<{
|
|
73
|
+
/** Graph-based context storage */
|
|
74
|
+
graph: z.ZodDefault<z.ZodObject<{
|
|
75
|
+
/** Whether graph features are enabled */
|
|
76
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
77
|
+
/** Whether to automatically ingest archived context into graph */
|
|
78
|
+
auto_ingest: z.ZodDefault<z.ZodBoolean>;
|
|
79
|
+
/** Maximum nodes to traverse in a search */
|
|
80
|
+
max_traversal_nodes: z.ZodDefault<z.ZodNumber>;
|
|
81
|
+
/** Maximum depth for graph traversal */
|
|
82
|
+
max_traversal_depth: z.ZodDefault<z.ZodNumber>;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
auto_ingest: boolean;
|
|
86
|
+
max_traversal_nodes: number;
|
|
87
|
+
max_traversal_depth: number;
|
|
88
|
+
}, {
|
|
89
|
+
enabled?: boolean | undefined;
|
|
90
|
+
auto_ingest?: boolean | undefined;
|
|
91
|
+
max_traversal_nodes?: number | undefined;
|
|
92
|
+
max_traversal_depth?: number | undefined;
|
|
93
|
+
}>>;
|
|
94
|
+
/** Enhanced search settings */
|
|
95
|
+
enhanced_search: z.ZodDefault<z.ZodObject<{
|
|
96
|
+
/** Use additional reference patterns from PinkyClawd */
|
|
97
|
+
additional_patterns: z.ZodDefault<z.ZodBoolean>;
|
|
98
|
+
/** Weight for recency in scoring (0-1) */
|
|
99
|
+
recency_weight: z.ZodDefault<z.ZodNumber>;
|
|
100
|
+
/** Weight for entity matches in scoring (0-1) */
|
|
101
|
+
entity_boost: z.ZodDefault<z.ZodNumber>;
|
|
102
|
+
/** Maximum age in days for recency scoring */
|
|
103
|
+
max_age_days: z.ZodDefault<z.ZodNumber>;
|
|
104
|
+
/** Minimum score threshold for results */
|
|
105
|
+
min_score_threshold: z.ZodDefault<z.ZodNumber>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
additional_patterns: boolean;
|
|
108
|
+
recency_weight: number;
|
|
109
|
+
entity_boost: number;
|
|
110
|
+
max_age_days: number;
|
|
111
|
+
min_score_threshold: number;
|
|
112
|
+
}, {
|
|
113
|
+
additional_patterns?: boolean | undefined;
|
|
114
|
+
recency_weight?: number | undefined;
|
|
115
|
+
entity_boost?: number | undefined;
|
|
116
|
+
max_age_days?: number | undefined;
|
|
117
|
+
min_score_threshold?: number | undefined;
|
|
118
|
+
}>>;
|
|
119
|
+
/** Task detection settings */
|
|
120
|
+
task_detection: z.ZodDefault<z.ZodObject<{
|
|
121
|
+
/** Archive context when task completion is detected */
|
|
122
|
+
auto_archive_on_completion: z.ZodDefault<z.ZodBoolean>;
|
|
123
|
+
}, "strip", z.ZodTypeAny, {
|
|
124
|
+
auto_archive_on_completion: boolean;
|
|
125
|
+
}, {
|
|
126
|
+
auto_archive_on_completion?: boolean | undefined;
|
|
127
|
+
}>>;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
graph: {
|
|
130
|
+
enabled: boolean;
|
|
131
|
+
auto_ingest: boolean;
|
|
132
|
+
max_traversal_nodes: number;
|
|
133
|
+
max_traversal_depth: number;
|
|
134
|
+
};
|
|
135
|
+
enhanced_search: {
|
|
136
|
+
additional_patterns: boolean;
|
|
137
|
+
recency_weight: number;
|
|
138
|
+
entity_boost: number;
|
|
139
|
+
max_age_days: number;
|
|
140
|
+
min_score_threshold: number;
|
|
141
|
+
};
|
|
142
|
+
task_detection: {
|
|
143
|
+
auto_archive_on_completion: boolean;
|
|
144
|
+
};
|
|
145
|
+
}, {
|
|
146
|
+
graph?: {
|
|
147
|
+
enabled?: boolean | undefined;
|
|
148
|
+
auto_ingest?: boolean | undefined;
|
|
149
|
+
max_traversal_nodes?: number | undefined;
|
|
150
|
+
max_traversal_depth?: number | undefined;
|
|
151
|
+
} | undefined;
|
|
152
|
+
enhanced_search?: {
|
|
153
|
+
additional_patterns?: boolean | undefined;
|
|
154
|
+
recency_weight?: number | undefined;
|
|
155
|
+
entity_boost?: number | undefined;
|
|
156
|
+
max_age_days?: number | undefined;
|
|
157
|
+
min_score_threshold?: number | undefined;
|
|
158
|
+
} | undefined;
|
|
159
|
+
task_detection?: {
|
|
160
|
+
auto_archive_on_completion?: boolean | undefined;
|
|
161
|
+
} | undefined;
|
|
162
|
+
}>;
|
|
163
|
+
export type PluginConfig = z.infer<typeof PluginConfigSchema>;
|
|
164
|
+
/**
|
|
165
|
+
* Default configuration.
|
|
166
|
+
*/
|
|
167
|
+
export declare const DEFAULT_CONFIG: PluginConfig;
|
|
168
|
+
/**
|
|
169
|
+
* Parse and validate configuration.
|
|
170
|
+
*/
|
|
171
|
+
export declare function parseConfig(config: unknown): PluginConfig;
|
|
172
|
+
/**
|
|
173
|
+
* Merge partial config with defaults.
|
|
174
|
+
*/
|
|
175
|
+
export declare function mergeConfig(partial: Partial<PluginConfig>): PluginConfig;
|
|
176
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,yCAAyC;;IAEzC,kEAAkE;;IAElE,4CAA4C;;IAE5C,wCAAwC;;;;;;;;;;;;EAExC,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B;IACrC,wDAAwD;;IAExD,0CAA0C;;IAE1C,iDAAiD;;IAEjD,8CAA8C;;IAE9C,0CAA0C;;;;;;;;;;;;;;EAE1C,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB;IACpC,uDAAuD;;;;;;EAEvD,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,kCAAkC;;QAtClC,yCAAyC;;QAEzC,kEAAkE;;QAElE,4CAA4C;;QAE5C,wCAAwC;;;;;;;;;;;;;IAkCxC,+BAA+B;;QA1B/B,wDAAwD;;QAExD,0CAA0C;;QAE1C,iDAAiD;;QAEjD,8CAA8C;;QAE9C,0CAA0C;;;;;;;;;;;;;;;IAoB1C,8BAA8B;;QAZ9B,uDAAuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcvD,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAE7D;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,YAiB5B,CAAA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAOzD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAYxE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin configuration schema.
|
|
3
|
+
*
|
|
4
|
+
* Configuration is loaded from .claude/claudecode.jsonc under the
|
|
5
|
+
* "claudecode-rlm" key.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* Graph configuration schema.
|
|
10
|
+
*/
|
|
11
|
+
export const GraphConfigSchema = z.object({
|
|
12
|
+
/** Whether graph features are enabled */
|
|
13
|
+
enabled: z.boolean().default(true),
|
|
14
|
+
/** Whether to automatically ingest archived context into graph */
|
|
15
|
+
auto_ingest: z.boolean().default(true),
|
|
16
|
+
/** Maximum nodes to traverse in a search */
|
|
17
|
+
max_traversal_nodes: z.number().default(50),
|
|
18
|
+
/** Maximum depth for graph traversal */
|
|
19
|
+
max_traversal_depth: z.number().default(3),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Enhanced search configuration schema.
|
|
23
|
+
*/
|
|
24
|
+
export const EnhancedSearchConfigSchema = z.object({
|
|
25
|
+
/** Use additional reference patterns from PinkyClawd */
|
|
26
|
+
additional_patterns: z.boolean().default(true),
|
|
27
|
+
/** Weight for recency in scoring (0-1) */
|
|
28
|
+
recency_weight: z.number().min(0).max(1).default(0.3),
|
|
29
|
+
/** Weight for entity matches in scoring (0-1) */
|
|
30
|
+
entity_boost: z.number().min(0).max(1).default(0.2),
|
|
31
|
+
/** Maximum age in days for recency scoring */
|
|
32
|
+
max_age_days: z.number().default(30),
|
|
33
|
+
/** Minimum score threshold for results */
|
|
34
|
+
min_score_threshold: z.number().default(0.3),
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Task detection configuration schema.
|
|
38
|
+
*/
|
|
39
|
+
export const TaskDetectionConfigSchema = z.object({
|
|
40
|
+
/** Archive context when task completion is detected */
|
|
41
|
+
auto_archive_on_completion: z.boolean().default(true),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Full plugin configuration schema.
|
|
45
|
+
*/
|
|
46
|
+
export const PluginConfigSchema = z.object({
|
|
47
|
+
/** Graph-based context storage */
|
|
48
|
+
graph: GraphConfigSchema.default({}),
|
|
49
|
+
/** Enhanced search settings */
|
|
50
|
+
enhanced_search: EnhancedSearchConfigSchema.default({}),
|
|
51
|
+
/** Task detection settings */
|
|
52
|
+
task_detection: TaskDetectionConfigSchema.default({}),
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Default configuration.
|
|
56
|
+
*/
|
|
57
|
+
export const DEFAULT_CONFIG = {
|
|
58
|
+
graph: {
|
|
59
|
+
enabled: true,
|
|
60
|
+
auto_ingest: true,
|
|
61
|
+
max_traversal_nodes: 50,
|
|
62
|
+
max_traversal_depth: 3,
|
|
63
|
+
},
|
|
64
|
+
enhanced_search: {
|
|
65
|
+
additional_patterns: true,
|
|
66
|
+
recency_weight: 0.3,
|
|
67
|
+
entity_boost: 0.2,
|
|
68
|
+
max_age_days: 30,
|
|
69
|
+
min_score_threshold: 0.3,
|
|
70
|
+
},
|
|
71
|
+
task_detection: {
|
|
72
|
+
auto_archive_on_completion: true,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Parse and validate configuration.
|
|
77
|
+
*/
|
|
78
|
+
export function parseConfig(config) {
|
|
79
|
+
try {
|
|
80
|
+
return PluginConfigSchema.parse(config ?? {});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Return defaults on parse error
|
|
84
|
+
return DEFAULT_CONFIG;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Merge partial config with defaults.
|
|
89
|
+
*/
|
|
90
|
+
export function mergeConfig(partial) {
|
|
91
|
+
return {
|
|
92
|
+
graph: { ...DEFAULT_CONFIG.graph, ...partial.graph },
|
|
93
|
+
enhanced_search: {
|
|
94
|
+
...DEFAULT_CONFIG.enhanced_search,
|
|
95
|
+
...partial.enhanced_search,
|
|
96
|
+
},
|
|
97
|
+
task_detection: {
|
|
98
|
+
...DEFAULT_CONFIG.task_detection,
|
|
99
|
+
...partial.task_detection,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,yCAAyC;IACzC,O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|
1
|
+
/**
|
|
2
|
+
* Graph module exports.
|
|
3
|
+
*
|
|
4
|
+
* RLM-Graph: Knowledge graph-based context storage and retrieval.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { GraphStorage } from "./storage.js";
|
|
8
|
+
export { EntityExtractor, ContentChunker, GraphIngester } from "./ingestion.js";
|
|
9
|
+
export { GraphTraverser, GraphSearcher } from "./traversal.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph module exports.
|
|
3
|
+
*
|
|
4
|
+
* RLM-Graph: Knowledge graph-based context storage and retrieval.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { GraphStorage } from "./storage.js";
|
|
8
|
+
export { EntityExtractor, ContentChunker, GraphIngester } from "./ingestion.js";
|
|
9
|
+
export { GraphTraverser, GraphSearcher } from "./traversal.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph ingestion: Entity extraction and content chunking.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for processing text content:
|
|
5
|
+
* - EntityExtractor: Identifies named entities and code elements
|
|
6
|
+
* - ContentChunker: Splits content into hierarchical chunks
|
|
7
|
+
* - GraphIngester: Converts content into graph structure
|
|
8
|
+
*/
|
|
9
|
+
import { type GraphNode, type Entity } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Extracts entities from text content.
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace EntityExtractor {
|
|
14
|
+
/**
|
|
15
|
+
* Extract entities from text.
|
|
16
|
+
*/
|
|
17
|
+
function extract(text: string): Entity[];
|
|
18
|
+
/**
|
|
19
|
+
* Extract top keywords based on frequency.
|
|
20
|
+
*/
|
|
21
|
+
function extractKeywords(text: string, topN?: number): string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Splits content into hierarchical chunks.
|
|
25
|
+
*/
|
|
26
|
+
export declare namespace ContentChunker {
|
|
27
|
+
/**
|
|
28
|
+
* Split content into sections.
|
|
29
|
+
*/
|
|
30
|
+
function splitIntoSections(content: string, minChars?: number): Array<{
|
|
31
|
+
title: string;
|
|
32
|
+
content: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Split content into overlapping chunks.
|
|
36
|
+
*/
|
|
37
|
+
function splitIntoChunks(content: string, targetChars?: number, overlap?: number): string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Ingests content into the knowledge graph.
|
|
41
|
+
*/
|
|
42
|
+
export declare namespace GraphIngester {
|
|
43
|
+
/**
|
|
44
|
+
* Context block interface (compatible with Claude Code RLM types).
|
|
45
|
+
*/
|
|
46
|
+
interface ContextBlock {
|
|
47
|
+
id: string;
|
|
48
|
+
sessionID: string;
|
|
49
|
+
content: string;
|
|
50
|
+
tokens: number;
|
|
51
|
+
summary?: string;
|
|
52
|
+
taskID?: string;
|
|
53
|
+
taskDescription?: string;
|
|
54
|
+
createdAt: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Ingest a context block into the graph.
|
|
58
|
+
*/
|
|
59
|
+
function ingestContextBlock(block: ContextBlock): GraphNode;
|
|
60
|
+
/**
|
|
61
|
+
* Ingest messages into the graph.
|
|
62
|
+
*/
|
|
63
|
+
function ingestMessages(sessionID: string, messages: Array<{
|
|
64
|
+
role: string;
|
|
65
|
+
content: string;
|
|
66
|
+
}>): GraphNode | null;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=ingestion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingestion.d.ts","sourceRoot":"","sources":["../../src/graph/ingestion.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,KAAK,SAAS,EAEd,KAAK,MAAM,EAIZ,MAAM,YAAY,CAAA;AAsCnB;;GAEG;AACH,yBAAiB,eAAe,CAAC;IAe/B;;OAEG;IACH,SAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CA2C9C;IAED;;OAEG;IACH,SAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,EAAE,CAgBzE;CACF;AAED;;GAEG;AACH,yBAAiB,cAAc,CAAC;IAK9B;;OAEG;IACH,SAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAkC,GAC3C,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CA+D3C;IAED;;OAEG;IACH,SAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,WAAW,GAAE,MAAmC,EAChD,OAAO,GAAE,MAA8B,GACtC,MAA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