agent-knowledge 1.1.6 → 1.3.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/CHANGELOG.md +115 -5
- package/README.md +86 -24
- package/dist/dashboard.d.ts +1 -0
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js +145 -19
- package/dist/dashboard.js.map +1 -1
- package/dist/embeddings/anthropic.d.ts.map +1 -1
- package/dist/embeddings/anthropic.js +2 -1
- package/dist/embeddings/anthropic.js.map +1 -1
- package/dist/embeddings/gemini.d.ts.map +1 -1
- package/dist/embeddings/gemini.js +2 -1
- package/dist/embeddings/gemini.js.map +1 -1
- package/dist/embeddings/local.d.ts.map +1 -1
- package/dist/embeddings/local.js +3 -0
- package/dist/embeddings/local.js.map +1 -1
- package/dist/knowledge/consolidate.d.ts +46 -0
- package/dist/knowledge/consolidate.d.ts.map +1 -0
- package/dist/knowledge/consolidate.js +164 -0
- package/dist/knowledge/consolidate.js.map +1 -0
- package/dist/knowledge/distill.d.ts.map +1 -1
- package/dist/knowledge/distill.js +4 -2
- package/dist/knowledge/distill.js.map +1 -1
- package/dist/knowledge/graph.d.ts +64 -0
- package/dist/knowledge/graph.d.ts.map +1 -0
- package/dist/knowledge/graph.js +214 -0
- package/dist/knowledge/graph.js.map +1 -0
- package/dist/knowledge/reflect.d.ts +33 -0
- package/dist/knowledge/reflect.d.ts.map +1 -0
- package/dist/knowledge/reflect.js +115 -0
- package/dist/knowledge/reflect.js.map +1 -0
- package/dist/knowledge/scoring.d.ts +57 -0
- package/dist/knowledge/scoring.d.ts.map +1 -0
- package/dist/knowledge/scoring.js +194 -0
- package/dist/knowledge/scoring.js.map +1 -0
- package/dist/knowledge/search.d.ts.map +1 -1
- package/dist/knowledge/search.js +15 -2
- package/dist/knowledge/search.js.map +1 -1
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +4 -3
- package/dist/knowledge/store.js.map +1 -1
- package/dist/search/excerpt.d.ts.map +1 -1
- package/dist/search/excerpt.js +2 -1
- package/dist/search/excerpt.js.map +1 -1
- package/dist/search/tfidf.d.ts +1 -0
- package/dist/search/tfidf.d.ts.map +1 -1
- package/dist/search/tfidf.js +38 -3
- package/dist/search/tfidf.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +117 -381
- package/dist/server.js.map +1 -1
- package/dist/sessions/parser.d.ts.map +1 -1
- package/dist/sessions/parser.js +12 -10
- package/dist/sessions/parser.js.map +1 -1
- package/dist/sessions/search.js +17 -3
- package/dist/sessions/search.js.map +1 -1
- package/dist/sessions/summary.d.ts.map +1 -1
- package/dist/sessions/summary.js +6 -3
- package/dist/sessions/summary.js.map +1 -1
- package/dist/tool-handlers.d.ts +42 -0
- package/dist/tool-handlers.d.ts.map +1 -0
- package/dist/tool-handlers.js +425 -0
- package/dist/tool-handlers.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -4
- package/dist/types.js.map +1 -1
- package/dist/ui/app.js +94 -723
- package/dist/ui/index.html +29 -0
- package/dist/ui/render-knowledge.js +233 -0
- package/dist/ui/render-panel.js +350 -0
- package/dist/ui/render-search.js +109 -0
- package/dist/ui/render-sessions.js +234 -0
- package/dist/ui/styles.css +261 -0
- package/dist/ui/ui-utils.js +196 -0
- package/dist/vectorstore/store.d.ts +25 -44
- package/dist/vectorstore/store.d.ts.map +1 -1
- package/dist/vectorstore/store.js +167 -167
- package/dist/vectorstore/store.js.map +1 -1
- package/docs/ARCHITECTURE.md +94 -1
- package/docs/DASHBOARD.md +26 -13
- package/docs/SETUP.md +17 -3
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -1,184 +1,76 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { searchSessions } from './sessions/search.js';
|
|
6
|
-
import { listSessions, getSessionSummary } from './sessions/summary.js';
|
|
7
|
-
import { scopedSearch } from './sessions/scopes.js';
|
|
3
|
+
import { ensureRepo } from './knowledge/git.js';
|
|
4
|
+
import { RELATIONSHIP_TYPES } from './knowledge/graph.js';
|
|
8
5
|
import { backgroundIndex } from './sessions/indexer.js';
|
|
9
|
-
import {
|
|
10
|
-
import { getProjectDirs, getSessionFiles, parseSessionFile, extractMessages, getSessionMeta, } from './sessions/parser.js';
|
|
11
|
-
import { getConfig, loadPersistedConfig, savePersistedConfig, getConfigLocation } from './types.js';
|
|
6
|
+
import { getConfig } from './types.js';
|
|
12
7
|
import { getVersion } from './version.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// ── Input validation helpers ─────────────────────────────────────────────────
|
|
16
|
-
function requireString(args, key, label) {
|
|
17
|
-
const val = args[key];
|
|
18
|
-
if (val === undefined || val === null || typeof val !== 'string') {
|
|
19
|
-
throw new Error(`Missing or invalid required parameter: ${label ?? key} (expected string)`);
|
|
20
|
-
}
|
|
21
|
-
if (val.length === 0) {
|
|
22
|
-
throw new Error(`Parameter ${label ?? key} must not be empty`);
|
|
23
|
-
}
|
|
24
|
-
return val;
|
|
25
|
-
}
|
|
26
|
-
function optionalString(args, key) {
|
|
27
|
-
const val = args[key];
|
|
28
|
-
if (val === undefined || val === null)
|
|
29
|
-
return undefined;
|
|
30
|
-
if (typeof val !== 'string') {
|
|
31
|
-
throw new Error(`Parameter ${key} must be a string`);
|
|
32
|
-
}
|
|
33
|
-
return val;
|
|
34
|
-
}
|
|
35
|
-
function optionalNumber(args, key, min, max) {
|
|
36
|
-
const val = args[key];
|
|
37
|
-
if (val === undefined || val === null)
|
|
38
|
-
return undefined;
|
|
39
|
-
const num = typeof val === 'number' ? val : Number(val);
|
|
40
|
-
if (isNaN(num)) {
|
|
41
|
-
throw new Error(`Parameter ${key} must be a number`);
|
|
42
|
-
}
|
|
43
|
-
if (min !== undefined && num < min) {
|
|
44
|
-
throw new Error(`Parameter ${key} must be >= ${min}`);
|
|
45
|
-
}
|
|
46
|
-
if (max !== undefined && num > max) {
|
|
47
|
-
throw new Error(`Parameter ${key} must be <= ${max}`);
|
|
48
|
-
}
|
|
49
|
-
return num;
|
|
50
|
-
}
|
|
51
|
-
function optionalBoolean(args, key) {
|
|
52
|
-
const val = args[key];
|
|
53
|
-
if (val === undefined || val === null)
|
|
54
|
-
return undefined;
|
|
55
|
-
if (typeof val === 'boolean')
|
|
56
|
-
return val;
|
|
57
|
-
if (val === 'true')
|
|
58
|
-
return true;
|
|
59
|
-
if (val === 'false')
|
|
60
|
-
return false;
|
|
61
|
-
throw new Error(`Parameter ${key} must be a boolean`);
|
|
62
|
-
}
|
|
63
|
-
function validateEnum(val, allowed, key) {
|
|
64
|
-
if (val === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
if (!allowed.includes(val)) {
|
|
67
|
-
throw new Error(`Parameter ${key} must be one of: ${allowed.join(', ')}`);
|
|
68
|
-
}
|
|
69
|
-
return val;
|
|
70
|
-
}
|
|
8
|
+
import { toolHandlers, validateArgs, err } from './tool-handlers.js';
|
|
9
|
+
import { CATEGORIES, SCOPES } from './tool-handlers.js';
|
|
71
10
|
export function createServer(options) {
|
|
72
11
|
const server = new Server({ name: 'agent-knowledge', version: getVersion() }, { capabilities: { tools: {} } });
|
|
73
12
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
74
13
|
tools: [
|
|
75
14
|
{
|
|
76
|
-
name: '
|
|
77
|
-
description: '
|
|
78
|
-
'
|
|
15
|
+
name: 'knowledge',
|
|
16
|
+
description: 'Knowledge base CRUD and sync. Actions: ' +
|
|
17
|
+
'"list" (browse entries), "read" (get entry content), ' +
|
|
18
|
+
'"write" (create/update entry, auto git sync), ' +
|
|
19
|
+
'"delete" (remove entry, auto git sync), "sync" (manual git pull + push).',
|
|
79
20
|
inputSchema: {
|
|
80
21
|
type: 'object',
|
|
81
22
|
properties: {
|
|
23
|
+
action: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
enum: ['list', 'read', 'write', 'delete', 'sync'],
|
|
26
|
+
description: 'Action to perform',
|
|
27
|
+
},
|
|
82
28
|
category: {
|
|
83
29
|
type: 'string',
|
|
84
30
|
enum: [...CATEGORIES],
|
|
85
|
-
description: '
|
|
31
|
+
description: 'Category (action=list: filter; action=write: target directory). ' +
|
|
32
|
+
'One of: projects, people, decisions, workflows, notes',
|
|
86
33
|
},
|
|
87
34
|
tag: {
|
|
88
35
|
type: 'string',
|
|
89
|
-
description: 'Filter by tag
|
|
36
|
+
description: 'Filter by tag (action=list)',
|
|
90
37
|
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
name: 'knowledge_read',
|
|
96
|
-
description: 'Read the full content of a knowledge base entry by its path (relative to the memory dir). ' +
|
|
97
|
-
'Returns the raw markdown including frontmatter.',
|
|
98
|
-
inputSchema: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
38
|
path: {
|
|
102
39
|
type: 'string',
|
|
103
|
-
description: "Relative path to the entry, e.g. 'projects/my-project.md'",
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
required: ['path'],
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'knowledge_write',
|
|
111
|
-
description: 'Create or update a knowledge base entry. The file is written under the given category directory. ' +
|
|
112
|
-
'Content should be markdown (frontmatter is optional). ' +
|
|
113
|
-
'Automatically commits and pushes after writing.',
|
|
114
|
-
inputSchema: {
|
|
115
|
-
type: 'object',
|
|
116
|
-
properties: {
|
|
117
|
-
category: {
|
|
118
|
-
type: 'string',
|
|
119
|
-
enum: [...CATEGORIES],
|
|
120
|
-
description: 'Category directory to write into',
|
|
40
|
+
description: "Relative path to the entry, e.g. 'projects/my-project.md' (action=read, delete)",
|
|
121
41
|
},
|
|
122
42
|
filename: {
|
|
123
43
|
type: 'string',
|
|
124
|
-
description: "Filename
|
|
44
|
+
description: "Filename with or without .md extension (action=write), e.g. 'my-project.md'",
|
|
125
45
|
},
|
|
126
46
|
content: {
|
|
127
47
|
type: 'string',
|
|
128
|
-
description: 'Full markdown content for the entry',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
required: ['category', 'filename', 'content'],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: 'knowledge_delete',
|
|
136
|
-
description: 'Delete a knowledge base entry by path. Automatically commits and pushes after deletion.',
|
|
137
|
-
inputSchema: {
|
|
138
|
-
type: 'object',
|
|
139
|
-
properties: {
|
|
140
|
-
path: {
|
|
141
|
-
type: 'string',
|
|
142
|
-
description: "Relative path to the entry to delete, e.g. 'notes/old-note.md'",
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
required: ['path'],
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'knowledge_sync',
|
|
150
|
-
description: 'Synchronize the knowledge base with the remote git repository (pull then push). ' +
|
|
151
|
-
'Use this to ensure you have the latest entries from other machines/sessions.',
|
|
152
|
-
inputSchema: {
|
|
153
|
-
type: 'object',
|
|
154
|
-
properties: {},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
name: 'knowledge_sessions',
|
|
159
|
-
description: 'List sessions with metadata (timestamps, branch, message counts, preview). ' +
|
|
160
|
-
'Optionally filter to a specific project. Returns sessions sorted newest first.',
|
|
161
|
-
inputSchema: {
|
|
162
|
-
type: 'object',
|
|
163
|
-
properties: {
|
|
164
|
-
project: {
|
|
165
|
-
type: 'string',
|
|
166
|
-
description: 'Filter by project name (substring match)',
|
|
48
|
+
description: 'Full markdown content for the entry (action=write)',
|
|
167
49
|
},
|
|
168
50
|
},
|
|
51
|
+
required: ['action'],
|
|
169
52
|
},
|
|
170
53
|
},
|
|
171
54
|
{
|
|
172
55
|
name: 'knowledge_search',
|
|
173
56
|
description: 'Hybrid semantic + TF-IDF search across session conversations. ' +
|
|
174
|
-
'Results
|
|
175
|
-
'
|
|
57
|
+
'Results ranked by blended relevance (semantic similarity + keyword match) x recency. ' +
|
|
58
|
+
'When "scope" is provided, searches within a specific domain (errors, plans, configs, tools, files, decisions). ' +
|
|
59
|
+
'Without scope, performs general search across all sessions.',
|
|
176
60
|
inputSchema: {
|
|
177
61
|
type: 'object',
|
|
178
62
|
properties: {
|
|
179
63
|
query: {
|
|
180
64
|
type: 'string',
|
|
181
|
-
description: 'Search query
|
|
65
|
+
description: 'Search query -- supports keywords and phrases',
|
|
66
|
+
},
|
|
67
|
+
scope: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
enum: [...SCOPES],
|
|
70
|
+
description: 'Search scope (optional): errors (stack traces), plans (architecture, TODOs), ' +
|
|
71
|
+
'configs (settings, env vars), tools (MCP tool calls), ' +
|
|
72
|
+
'files (file paths, code refs), decisions (trade-offs, choices), all (no filter). ' +
|
|
73
|
+
'When provided, performs scoped recall instead of general search.',
|
|
182
74
|
},
|
|
183
75
|
project: {
|
|
184
76
|
type: 'string',
|
|
@@ -187,7 +79,7 @@ export function createServer(options) {
|
|
|
187
79
|
role: {
|
|
188
80
|
type: 'string',
|
|
189
81
|
enum: ['user', 'assistant', 'all'],
|
|
190
|
-
description: 'Filter by message role (default: all)',
|
|
82
|
+
description: 'Filter by message role (default: all, ignored when scope is set)',
|
|
191
83
|
},
|
|
192
84
|
max_results: {
|
|
193
85
|
type: 'number',
|
|
@@ -195,7 +87,7 @@ export function createServer(options) {
|
|
|
195
87
|
},
|
|
196
88
|
ranked: {
|
|
197
89
|
type: 'boolean',
|
|
198
|
-
description: 'Use TF-IDF ranking (default: true). Set false for regex mode.',
|
|
90
|
+
description: 'Use TF-IDF ranking (default: true, ignored when scope is set). Set false for regex mode.',
|
|
199
91
|
},
|
|
200
92
|
semantic: {
|
|
201
93
|
type: 'boolean',
|
|
@@ -206,292 +98,147 @@ export function createServer(options) {
|
|
|
206
98
|
},
|
|
207
99
|
},
|
|
208
100
|
{
|
|
209
|
-
name: '
|
|
210
|
-
description: '
|
|
211
|
-
'
|
|
101
|
+
name: 'knowledge_session',
|
|
102
|
+
description: 'Session operations: list sessions, get a full conversation, or get a summary. ' +
|
|
103
|
+
'Use action "list" to browse sessions, "get" to retrieve messages, "summary" for a quick overview.',
|
|
212
104
|
inputSchema: {
|
|
213
105
|
type: 'object',
|
|
214
106
|
properties: {
|
|
107
|
+
action: {
|
|
108
|
+
type: 'string',
|
|
109
|
+
enum: ['list', 'get', 'summary'],
|
|
110
|
+
description: 'Action to perform',
|
|
111
|
+
},
|
|
215
112
|
session_id: {
|
|
216
113
|
type: 'string',
|
|
217
|
-
description: '
|
|
114
|
+
description: 'Session UUID (required for get, summary)',
|
|
218
115
|
},
|
|
219
116
|
project: {
|
|
220
117
|
type: 'string',
|
|
221
|
-
description: '
|
|
118
|
+
description: 'Filter by project name (substring match)',
|
|
222
119
|
},
|
|
223
120
|
include_tools: {
|
|
224
121
|
type: 'boolean',
|
|
225
|
-
description: 'Include tool_use and tool_result messages (default: false)',
|
|
122
|
+
description: 'Include tool_use and tool_result messages (action=get, default: false)',
|
|
226
123
|
},
|
|
227
124
|
tail: {
|
|
228
125
|
type: 'number',
|
|
229
|
-
description: 'Only return the last N messages
|
|
126
|
+
description: 'Only return the last N messages (action=get)',
|
|
230
127
|
},
|
|
231
128
|
},
|
|
232
|
-
required: ['
|
|
129
|
+
required: ['action'],
|
|
233
130
|
},
|
|
234
131
|
},
|
|
235
132
|
{
|
|
236
|
-
name: '
|
|
237
|
-
description: '
|
|
238
|
-
'
|
|
133
|
+
name: 'knowledge_admin',
|
|
134
|
+
description: 'Admin operations: view vector store stats or view/update configuration. ' +
|
|
135
|
+
'Use action "status" for index stats, "config" to view or update settings.',
|
|
239
136
|
inputSchema: {
|
|
240
137
|
type: 'object',
|
|
241
138
|
properties: {
|
|
242
|
-
|
|
139
|
+
action: {
|
|
243
140
|
type: 'string',
|
|
244
|
-
|
|
141
|
+
enum: ['status', 'config'],
|
|
142
|
+
description: 'Action: status (vector store stats), config (view/update settings)',
|
|
245
143
|
},
|
|
246
|
-
|
|
144
|
+
git_url: {
|
|
247
145
|
type: 'string',
|
|
248
|
-
description: '
|
|
146
|
+
description: 'Git remote URL (action=config). Set to empty string to remove.',
|
|
147
|
+
},
|
|
148
|
+
memory_dir: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'Local knowledge base directory (action=config). Empty to reset.',
|
|
151
|
+
},
|
|
152
|
+
auto_distill: {
|
|
153
|
+
type: 'boolean',
|
|
154
|
+
description: 'Enable/disable session distillation (action=config)',
|
|
249
155
|
},
|
|
250
156
|
},
|
|
251
|
-
required: ['
|
|
157
|
+
required: ['action'],
|
|
252
158
|
},
|
|
253
159
|
},
|
|
254
160
|
{
|
|
255
|
-
name: '
|
|
256
|
-
description: '
|
|
257
|
-
'
|
|
258
|
-
'Results ranked by blended relevance (semantic + keyword) × recency. ' +
|
|
259
|
-
'More targeted than knowledge_search when you know what kind of information you need.',
|
|
161
|
+
name: 'knowledge_graph',
|
|
162
|
+
description: 'Knowledge graph operations: create/remove edges, list edges, or traverse via BFS. ' +
|
|
163
|
+
'Relationship types: related_to, supersedes, depends_on, contradicts, specializes, part_of, alternative_to, builds_on.',
|
|
260
164
|
inputSchema: {
|
|
261
165
|
type: 'object',
|
|
262
166
|
properties: {
|
|
263
|
-
|
|
167
|
+
action: {
|
|
264
168
|
type: 'string',
|
|
265
|
-
enum: [
|
|
266
|
-
description: '
|
|
267
|
-
'configs (settings, env vars), tools (MCP tool calls), ' +
|
|
268
|
-
'files (file paths, code refs), decisions (trade-offs, choices), all (no filter)',
|
|
169
|
+
enum: ['link', 'unlink', 'list', 'traverse'],
|
|
170
|
+
description: 'Action: link (create edge), unlink (remove edge), list (list edges), traverse (BFS)',
|
|
269
171
|
},
|
|
270
|
-
|
|
172
|
+
source: {
|
|
271
173
|
type: 'string',
|
|
272
|
-
description:
|
|
174
|
+
description: "Source entry path (action=link/unlink), e.g. 'projects/my-project.md'",
|
|
273
175
|
},
|
|
274
|
-
|
|
176
|
+
target: {
|
|
275
177
|
type: 'string',
|
|
276
|
-
description:
|
|
178
|
+
description: "Target entry path (action=link/unlink), e.g. 'decisions/architecture.md'",
|
|
277
179
|
},
|
|
278
|
-
|
|
180
|
+
entry: {
|
|
181
|
+
type: 'string',
|
|
182
|
+
description: 'Entry path for filtering (action=list) or BFS start (action=traverse)',
|
|
183
|
+
},
|
|
184
|
+
rel_type: {
|
|
185
|
+
type: 'string',
|
|
186
|
+
enum: [...RELATIONSHIP_TYPES],
|
|
187
|
+
description: 'Relationship type (required for link, optional filter for unlink/list)',
|
|
188
|
+
},
|
|
189
|
+
strength: {
|
|
279
190
|
type: 'number',
|
|
280
|
-
description: '
|
|
191
|
+
description: 'Edge strength 0-1 (action=link, default: 0.5)',
|
|
281
192
|
},
|
|
282
|
-
|
|
283
|
-
type: '
|
|
284
|
-
description: '
|
|
193
|
+
depth: {
|
|
194
|
+
type: 'number',
|
|
195
|
+
description: 'Max traversal depth in hops (action=traverse, default: 2)',
|
|
285
196
|
},
|
|
286
197
|
},
|
|
287
|
-
required: ['
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
name: 'knowledge_index_status',
|
|
292
|
-
description: 'Get vector store statistics: total entries, breakdown by source (knowledge vs session), ' +
|
|
293
|
-
'database size, active embedding provider, and vector dimensions.',
|
|
294
|
-
inputSchema: {
|
|
295
|
-
type: 'object',
|
|
296
|
-
properties: {},
|
|
198
|
+
required: ['action'],
|
|
297
199
|
},
|
|
298
200
|
},
|
|
299
201
|
{
|
|
300
|
-
name: '
|
|
301
|
-
description: '
|
|
302
|
-
'
|
|
303
|
-
'
|
|
304
|
-
'Settings are persisted across restarts. Env vars override persisted values.',
|
|
202
|
+
name: 'knowledge_analyze',
|
|
203
|
+
description: 'Analysis tools: find near-duplicate entries or unconnected entries. ' +
|
|
204
|
+
'Use action "consolidate" to scan for duplicates (TF-IDF similarity), ' +
|
|
205
|
+
'"reflect" to find entries with no graph connections and get a structured prompt for linking them.',
|
|
305
206
|
inputSchema: {
|
|
306
207
|
type: 'object',
|
|
307
208
|
properties: {
|
|
308
|
-
|
|
209
|
+
action: {
|
|
309
210
|
type: 'string',
|
|
310
|
-
|
|
211
|
+
enum: ['consolidate', 'reflect'],
|
|
212
|
+
description: 'Action: consolidate (find duplicates), reflect (find unconnected entries)',
|
|
311
213
|
},
|
|
312
|
-
|
|
214
|
+
category: {
|
|
313
215
|
type: 'string',
|
|
314
|
-
|
|
216
|
+
enum: [...CATEGORIES],
|
|
217
|
+
description: 'Scan only this category (omit for all)',
|
|
315
218
|
},
|
|
316
|
-
|
|
317
|
-
type: '
|
|
318
|
-
description: '
|
|
219
|
+
threshold: {
|
|
220
|
+
type: 'number',
|
|
221
|
+
description: 'Similarity threshold 0-1 (action=consolidate, default: 0.5)',
|
|
222
|
+
},
|
|
223
|
+
max_entries: {
|
|
224
|
+
type: 'number',
|
|
225
|
+
description: 'Max unconnected entries to include (action=reflect, default: 20)',
|
|
319
226
|
},
|
|
320
227
|
},
|
|
228
|
+
required: ['action'],
|
|
321
229
|
},
|
|
322
230
|
},
|
|
323
231
|
],
|
|
324
232
|
}));
|
|
325
233
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
326
234
|
const { name, arguments: args = {} } = request.params;
|
|
327
|
-
const
|
|
328
|
-
|
|
235
|
+
const handler = toolHandlers[name];
|
|
236
|
+
if (!handler) {
|
|
237
|
+
return err(`Unknown tool: ${name}`);
|
|
238
|
+
}
|
|
329
239
|
try {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const category = validateEnum(optionalString(a, 'category'), CATEGORIES, 'category');
|
|
333
|
-
const tag = optionalString(a, 'tag');
|
|
334
|
-
await gitPull(config.memoryDir);
|
|
335
|
-
const entries = listEntries(config.memoryDir, category, tag);
|
|
336
|
-
return ok(entries);
|
|
337
|
-
}
|
|
338
|
-
case 'knowledge_read': {
|
|
339
|
-
const entryPath = requireString(a, 'path');
|
|
340
|
-
await gitPull(config.memoryDir);
|
|
341
|
-
const result = readEntry(config.memoryDir, entryPath);
|
|
342
|
-
return ok(result);
|
|
343
|
-
}
|
|
344
|
-
case 'knowledge_write': {
|
|
345
|
-
const category = requireString(a, 'category');
|
|
346
|
-
const filename = requireString(a, 'filename');
|
|
347
|
-
const content = requireString(a, 'content');
|
|
348
|
-
if (content.length > 1_000_000) {
|
|
349
|
-
return err('Content too large (max 1MB)');
|
|
350
|
-
}
|
|
351
|
-
await gitPull(config.memoryDir);
|
|
352
|
-
const filePath = writeEntry(config.memoryDir, category, filename, content);
|
|
353
|
-
const pushResult = await gitPush(config.memoryDir);
|
|
354
|
-
return ok({ path: filePath, git: pushResult });
|
|
355
|
-
}
|
|
356
|
-
case 'knowledge_delete': {
|
|
357
|
-
const entryPath = requireString(a, 'path');
|
|
358
|
-
await gitPull(config.memoryDir);
|
|
359
|
-
const deleted = deleteEntry(config.memoryDir, entryPath);
|
|
360
|
-
const pushResult = await gitPush(config.memoryDir);
|
|
361
|
-
return ok({ deleted, git: pushResult });
|
|
362
|
-
}
|
|
363
|
-
case 'knowledge_sync': {
|
|
364
|
-
const result = await gitSync(config.memoryDir);
|
|
365
|
-
return ok(result);
|
|
366
|
-
}
|
|
367
|
-
case 'knowledge_sessions': {
|
|
368
|
-
const project = optionalString(a, 'project');
|
|
369
|
-
const sessions = listSessions(project);
|
|
370
|
-
return ok(sessions);
|
|
371
|
-
}
|
|
372
|
-
case 'knowledge_search': {
|
|
373
|
-
const query = requireString(a, 'query');
|
|
374
|
-
const project = optionalString(a, 'project');
|
|
375
|
-
const role = validateEnum(optionalString(a, 'role'), ['user', 'assistant', 'all'], 'role') ?? 'all';
|
|
376
|
-
const maxResults = optionalNumber(a, 'max_results', 1, 500) ?? 20;
|
|
377
|
-
const ranked = optionalBoolean(a, 'ranked') ?? true;
|
|
378
|
-
const semantic = optionalBoolean(a, 'semantic') ?? true;
|
|
379
|
-
const results = await searchSessions(query, {
|
|
380
|
-
project,
|
|
381
|
-
role,
|
|
382
|
-
maxResults,
|
|
383
|
-
ranked,
|
|
384
|
-
semantic,
|
|
385
|
-
});
|
|
386
|
-
return ok(results);
|
|
387
|
-
}
|
|
388
|
-
case 'knowledge_get': {
|
|
389
|
-
const sessionId = requireString(a, 'session_id');
|
|
390
|
-
const projectFilter = optionalString(a, 'project');
|
|
391
|
-
const includeTools = optionalBoolean(a, 'include_tools') ?? false;
|
|
392
|
-
const tail = optionalNumber(a, 'tail', 1, 10000);
|
|
393
|
-
const projects = getProjectDirs().filter((p) => !projectFilter || p.name.toLowerCase().includes(projectFilter.toLowerCase()));
|
|
394
|
-
for (const proj of projects) {
|
|
395
|
-
const sessions = getSessionFiles(proj.path);
|
|
396
|
-
const match = sessions.find((s) => s.id === sessionId);
|
|
397
|
-
if (match) {
|
|
398
|
-
const entries = parseSessionFile(match.file);
|
|
399
|
-
let messages = extractMessages(entries);
|
|
400
|
-
if (!includeTools) {
|
|
401
|
-
messages = messages.filter((m) => m.role === 'user' || m.role === 'assistant');
|
|
402
|
-
}
|
|
403
|
-
if (tail && tail > 0) {
|
|
404
|
-
messages = messages.slice(-tail);
|
|
405
|
-
}
|
|
406
|
-
const meta = getSessionMeta(entries);
|
|
407
|
-
return ok({ meta, messages });
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return err(`Session ${sessionId} not found.`);
|
|
411
|
-
}
|
|
412
|
-
case 'knowledge_summary': {
|
|
413
|
-
const sessionId = requireString(a, 'session_id');
|
|
414
|
-
const project = optionalString(a, 'project');
|
|
415
|
-
const result = getSessionSummary(sessionId, project);
|
|
416
|
-
if (!result) {
|
|
417
|
-
return err(`Session ${sessionId} not found.`);
|
|
418
|
-
}
|
|
419
|
-
return ok(result);
|
|
420
|
-
}
|
|
421
|
-
case 'knowledge_recall': {
|
|
422
|
-
const scope = requireString(a, 'scope');
|
|
423
|
-
validateEnum(scope, SCOPES, 'scope');
|
|
424
|
-
const query = requireString(a, 'query');
|
|
425
|
-
const project = optionalString(a, 'project');
|
|
426
|
-
const maxResults = optionalNumber(a, 'max_results', 1, 500) ?? 20;
|
|
427
|
-
const semantic = optionalBoolean(a, 'semantic') ?? true;
|
|
428
|
-
const results = await scopedSearch(scope, query, {
|
|
429
|
-
project,
|
|
430
|
-
maxResults,
|
|
431
|
-
semantic,
|
|
432
|
-
});
|
|
433
|
-
return ok(results);
|
|
434
|
-
}
|
|
435
|
-
case 'knowledge_index_status': {
|
|
436
|
-
const store = new VectorStore();
|
|
437
|
-
const stats = store.stats();
|
|
438
|
-
return ok(stats);
|
|
439
|
-
}
|
|
440
|
-
case 'knowledge_config': {
|
|
441
|
-
const gitUrlArg = optionalString(a, 'git_url');
|
|
442
|
-
const memoryDirArg = optionalString(a, 'memory_dir');
|
|
443
|
-
const autoDistillArg = optionalBoolean(a, 'auto_distill');
|
|
444
|
-
const hasUpdates = gitUrlArg !== undefined || memoryDirArg !== undefined || autoDistillArg !== undefined;
|
|
445
|
-
if (hasUpdates) {
|
|
446
|
-
const updates = {};
|
|
447
|
-
if (gitUrlArg !== undefined)
|
|
448
|
-
updates.gitUrl = gitUrlArg || undefined;
|
|
449
|
-
if (memoryDirArg !== undefined)
|
|
450
|
-
updates.memoryDir = memoryDirArg || undefined;
|
|
451
|
-
if (autoDistillArg !== undefined)
|
|
452
|
-
updates.autoDistill = autoDistillArg;
|
|
453
|
-
savePersistedConfig(updates);
|
|
454
|
-
const newConfig = getConfig();
|
|
455
|
-
if (gitUrlArg && gitUrlArg.length > 0) {
|
|
456
|
-
const repoResult = ensureRepo(newConfig.memoryDir, newConfig.gitUrl);
|
|
457
|
-
return ok({
|
|
458
|
-
message: 'Config saved',
|
|
459
|
-
repoSetup: repoResult,
|
|
460
|
-
config: {
|
|
461
|
-
gitUrl: newConfig.gitUrl,
|
|
462
|
-
memoryDir: newConfig.memoryDir,
|
|
463
|
-
autoDistill: newConfig.autoDistill,
|
|
464
|
-
embeddingProvider: newConfig.embeddingProvider,
|
|
465
|
-
},
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
return ok({
|
|
469
|
-
message: 'Config saved',
|
|
470
|
-
config: {
|
|
471
|
-
gitUrl: newConfig.gitUrl,
|
|
472
|
-
memoryDir: newConfig.memoryDir,
|
|
473
|
-
autoDistill: newConfig.autoDistill,
|
|
474
|
-
embeddingProvider: newConfig.embeddingProvider,
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
const persisted = loadPersistedConfig();
|
|
479
|
-
return ok({
|
|
480
|
-
active: {
|
|
481
|
-
gitUrl: config.gitUrl ?? null,
|
|
482
|
-
memoryDir: config.memoryDir,
|
|
483
|
-
autoDistill: config.autoDistill,
|
|
484
|
-
embeddingProvider: config.embeddingProvider,
|
|
485
|
-
embeddingAlpha: config.embeddingAlpha,
|
|
486
|
-
},
|
|
487
|
-
persisted,
|
|
488
|
-
configFile: getConfigLocation(),
|
|
489
|
-
note: 'Config stored at a tool-agnostic location. Env vars override persisted config.',
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
default:
|
|
493
|
-
return err(`Unknown tool: ${name}`);
|
|
494
|
-
}
|
|
240
|
+
const validated = validateArgs(args);
|
|
241
|
+
return await handler(validated);
|
|
495
242
|
}
|
|
496
243
|
catch (error) {
|
|
497
244
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -502,22 +249,11 @@ export function createServer(options) {
|
|
|
502
249
|
const repoResult = ensureRepo(startupConfig.memoryDir, startupConfig.gitUrl);
|
|
503
250
|
console.error(`[knowledge] Repo init: ${repoResult.message}`);
|
|
504
251
|
if (options?.isLeader !== false) {
|
|
505
|
-
setTimeout(() => backgroundIndex().catch((
|
|
252
|
+
setTimeout(() => backgroundIndex().catch((bgErr) => console.error('[knowledge] Background index failed:', bgErr)), 5000);
|
|
506
253
|
}
|
|
507
254
|
else {
|
|
508
|
-
console.error('[knowledge] Follower instance
|
|
255
|
+
console.error('[knowledge] Follower instance -- skipping background indexing');
|
|
509
256
|
}
|
|
510
257
|
return server;
|
|
511
258
|
}
|
|
512
|
-
function ok(result) {
|
|
513
|
-
return {
|
|
514
|
-
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
function err(message) {
|
|
518
|
-
return {
|
|
519
|
-
content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }],
|
|
520
|
-
isError: true,
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
259
|
//# sourceMappingURL=server.js.map
|