agent-knowledge 1.1.6 → 1.1.7
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 +123 -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 +125 -382
- package/dist/server.js.map +1 -1
- package/dist/sessions/parser.d.ts.map +1 -1
- package/dist/sessions/parser.js +44 -69
- 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 +26 -16
- package/dist/sessions/summary.js.map +1 -1
- package/dist/tool-handlers.d.ts +41 -0
- package/dist/tool-handlers.d.ts.map +1 -0
- package/dist/tool-handlers.js +440 -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 +74 -23
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -1,184 +1,75 @@
|
|
|
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, SCOPES } from './tool-handlers.js';
|
|
9
|
+
import { CATEGORIES } from './knowledge/store.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
|
-
description: '
|
|
174
|
-
'
|
|
175
|
-
'
|
|
56
|
+
description: 'Search across sessions AND knowledge entries. ' +
|
|
57
|
+
'Returns both session matches (semantic + TF-IDF) and knowledge base matches. ' +
|
|
58
|
+
'When "scope" is provided, searches within a specific domain (errors, plans, configs, tools, files, decisions) in sessions only.',
|
|
176
59
|
inputSchema: {
|
|
177
60
|
type: 'object',
|
|
178
61
|
properties: {
|
|
179
62
|
query: {
|
|
180
63
|
type: 'string',
|
|
181
|
-
description: 'Search query
|
|
64
|
+
description: 'Search query -- supports keywords and phrases',
|
|
65
|
+
},
|
|
66
|
+
scope: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
enum: [...SCOPES],
|
|
69
|
+
description: 'Search scope (optional): errors (stack traces), plans (architecture, TODOs), ' +
|
|
70
|
+
'configs (settings, env vars), tools (MCP tool calls), ' +
|
|
71
|
+
'files (file paths, code refs), decisions (trade-offs, choices), all (no filter). ' +
|
|
72
|
+
'When provided, performs scoped recall instead of general search.',
|
|
182
73
|
},
|
|
183
74
|
project: {
|
|
184
75
|
type: 'string',
|
|
@@ -187,7 +78,7 @@ export function createServer(options) {
|
|
|
187
78
|
role: {
|
|
188
79
|
type: 'string',
|
|
189
80
|
enum: ['user', 'assistant', 'all'],
|
|
190
|
-
description: 'Filter by message role (default: all)',
|
|
81
|
+
description: 'Filter by message role (default: all, ignored when scope is set)',
|
|
191
82
|
},
|
|
192
83
|
max_results: {
|
|
193
84
|
type: 'number',
|
|
@@ -195,7 +86,7 @@ export function createServer(options) {
|
|
|
195
86
|
},
|
|
196
87
|
ranked: {
|
|
197
88
|
type: 'boolean',
|
|
198
|
-
description: 'Use TF-IDF ranking (default: true). Set false for regex mode.',
|
|
89
|
+
description: 'Use TF-IDF ranking (default: true, ignored when scope is set). Set false for regex mode.',
|
|
199
90
|
},
|
|
200
91
|
semantic: {
|
|
201
92
|
type: 'boolean',
|
|
@@ -206,292 +97,155 @@ export function createServer(options) {
|
|
|
206
97
|
},
|
|
207
98
|
},
|
|
208
99
|
{
|
|
209
|
-
name: '
|
|
210
|
-
description: '
|
|
211
|
-
'
|
|
100
|
+
name: 'knowledge_session',
|
|
101
|
+
description: 'Session operations: list sessions, get a full conversation, or get a summary. ' +
|
|
102
|
+
'Use action "list" to browse sessions, "get" to retrieve messages, "summary" for a quick overview.',
|
|
212
103
|
inputSchema: {
|
|
213
104
|
type: 'object',
|
|
214
105
|
properties: {
|
|
106
|
+
action: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
enum: ['list', 'get', 'summary'],
|
|
109
|
+
description: 'Action to perform',
|
|
110
|
+
},
|
|
215
111
|
session_id: {
|
|
216
112
|
type: 'string',
|
|
217
|
-
description: '
|
|
113
|
+
description: 'Session UUID (required for get, summary)',
|
|
218
114
|
},
|
|
219
115
|
project: {
|
|
220
116
|
type: 'string',
|
|
221
|
-
description: '
|
|
117
|
+
description: 'Filter by project name (substring match)',
|
|
222
118
|
},
|
|
223
119
|
include_tools: {
|
|
224
120
|
type: 'boolean',
|
|
225
|
-
description: 'Include tool_use and tool_result messages (default: false)',
|
|
121
|
+
description: 'Include tool_use and tool_result messages (action=get, default: false)',
|
|
226
122
|
},
|
|
227
123
|
tail: {
|
|
228
124
|
type: 'number',
|
|
229
|
-
description: 'Only return the last N messages
|
|
125
|
+
description: 'Only return the last N messages (action=get)',
|
|
126
|
+
},
|
|
127
|
+
limit: {
|
|
128
|
+
type: 'number',
|
|
129
|
+
description: 'Max sessions to return (action=list, default: 20, max: 500)',
|
|
130
|
+
},
|
|
131
|
+
offset: {
|
|
132
|
+
type: 'number',
|
|
133
|
+
description: 'Skip first N sessions (action=list, default: 0)',
|
|
230
134
|
},
|
|
231
135
|
},
|
|
232
|
-
required: ['
|
|
136
|
+
required: ['action'],
|
|
233
137
|
},
|
|
234
138
|
},
|
|
235
139
|
{
|
|
236
|
-
name: '
|
|
237
|
-
description: '
|
|
238
|
-
'
|
|
140
|
+
name: 'knowledge_admin',
|
|
141
|
+
description: 'Admin operations: view vector store stats or view/update configuration. ' +
|
|
142
|
+
'Use action "status" for index stats, "config" to view or update settings.',
|
|
239
143
|
inputSchema: {
|
|
240
144
|
type: 'object',
|
|
241
145
|
properties: {
|
|
242
|
-
|
|
146
|
+
action: {
|
|
243
147
|
type: 'string',
|
|
244
|
-
|
|
148
|
+
enum: ['status', 'config'],
|
|
149
|
+
description: 'Action: status (vector store stats), config (view/update settings)',
|
|
245
150
|
},
|
|
246
|
-
|
|
151
|
+
git_url: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
description: 'Git remote URL (action=config). Set to empty string to remove.',
|
|
154
|
+
},
|
|
155
|
+
memory_dir: {
|
|
247
156
|
type: 'string',
|
|
248
|
-
description: '
|
|
157
|
+
description: 'Local knowledge base directory (action=config). Empty to reset.',
|
|
158
|
+
},
|
|
159
|
+
auto_distill: {
|
|
160
|
+
type: 'boolean',
|
|
161
|
+
description: 'Enable/disable session distillation (action=config)',
|
|
249
162
|
},
|
|
250
163
|
},
|
|
251
|
-
required: ['
|
|
164
|
+
required: ['action'],
|
|
252
165
|
},
|
|
253
166
|
},
|
|
254
167
|
{
|
|
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.',
|
|
168
|
+
name: 'knowledge_graph',
|
|
169
|
+
description: 'Knowledge graph operations: create/remove edges, list edges, or traverse via BFS. ' +
|
|
170
|
+
'Relationship types: related_to, supersedes, depends_on, contradicts, specializes, part_of, alternative_to, builds_on.',
|
|
260
171
|
inputSchema: {
|
|
261
172
|
type: 'object',
|
|
262
173
|
properties: {
|
|
263
|
-
|
|
174
|
+
action: {
|
|
264
175
|
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)',
|
|
176
|
+
enum: ['link', 'unlink', 'list', 'traverse'],
|
|
177
|
+
description: 'Action: link (create edge), unlink (remove edge), list (list edges), traverse (BFS)',
|
|
269
178
|
},
|
|
270
|
-
|
|
179
|
+
source: {
|
|
271
180
|
type: 'string',
|
|
272
|
-
description:
|
|
181
|
+
description: "Source entry path (action=link/unlink), e.g. 'projects/my-project.md'",
|
|
273
182
|
},
|
|
274
|
-
|
|
183
|
+
target: {
|
|
275
184
|
type: 'string',
|
|
276
|
-
description:
|
|
185
|
+
description: "Target entry path (action=link/unlink), e.g. 'decisions/architecture.md'",
|
|
277
186
|
},
|
|
278
|
-
|
|
187
|
+
entry: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
description: 'Entry path for filtering (action=list) or BFS start (action=traverse)',
|
|
190
|
+
},
|
|
191
|
+
rel_type: {
|
|
192
|
+
type: 'string',
|
|
193
|
+
enum: [...RELATIONSHIP_TYPES],
|
|
194
|
+
description: 'Relationship type (required for link, optional filter for unlink/list)',
|
|
195
|
+
},
|
|
196
|
+
strength: {
|
|
279
197
|
type: 'number',
|
|
280
|
-
description: '
|
|
198
|
+
description: 'Edge strength 0-1 (action=link, default: 0.5)',
|
|
281
199
|
},
|
|
282
|
-
|
|
283
|
-
type: '
|
|
284
|
-
description: '
|
|
200
|
+
depth: {
|
|
201
|
+
type: 'number',
|
|
202
|
+
description: 'Max traversal depth in hops (action=traverse, default: 2)',
|
|
285
203
|
},
|
|
286
204
|
},
|
|
287
|
-
required: ['
|
|
205
|
+
required: ['action'],
|
|
288
206
|
},
|
|
289
207
|
},
|
|
290
208
|
{
|
|
291
|
-
name: '
|
|
292
|
-
description: '
|
|
293
|
-
'
|
|
294
|
-
|
|
295
|
-
type: 'object',
|
|
296
|
-
properties: {},
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
name: 'knowledge_config',
|
|
301
|
-
description: 'View or update knowledge configuration. Without arguments, returns current config. ' +
|
|
302
|
-
'With arguments, persists settings to knowledge-config.json. ' +
|
|
303
|
-
'Set git_url to enable git sync for the knowledge base. ' +
|
|
304
|
-
'Settings are persisted across restarts. Env vars override persisted values.',
|
|
209
|
+
name: 'knowledge_analyze',
|
|
210
|
+
description: 'Analysis tools: find near-duplicate entries or unconnected entries. ' +
|
|
211
|
+
'Use action "consolidate" to scan for duplicates (TF-IDF similarity), ' +
|
|
212
|
+
'"reflect" to find entries with no graph connections and get a structured prompt for linking them.',
|
|
305
213
|
inputSchema: {
|
|
306
214
|
type: 'object',
|
|
307
215
|
properties: {
|
|
308
|
-
|
|
216
|
+
action: {
|
|
309
217
|
type: 'string',
|
|
310
|
-
|
|
218
|
+
enum: ['consolidate', 'reflect'],
|
|
219
|
+
description: 'Action: consolidate (find duplicates), reflect (find unconnected entries)',
|
|
311
220
|
},
|
|
312
|
-
|
|
221
|
+
category: {
|
|
313
222
|
type: 'string',
|
|
314
|
-
|
|
223
|
+
enum: [...CATEGORIES],
|
|
224
|
+
description: 'Scan only this category (omit for all)',
|
|
315
225
|
},
|
|
316
|
-
|
|
317
|
-
type: '
|
|
318
|
-
description: '
|
|
226
|
+
threshold: {
|
|
227
|
+
type: 'number',
|
|
228
|
+
description: 'Similarity threshold 0-1 (action=consolidate, default: 0.5)',
|
|
229
|
+
},
|
|
230
|
+
max_entries: {
|
|
231
|
+
type: 'number',
|
|
232
|
+
description: 'Max unconnected entries to include (action=reflect, default: 20)',
|
|
319
233
|
},
|
|
320
234
|
},
|
|
235
|
+
required: ['action'],
|
|
321
236
|
},
|
|
322
237
|
},
|
|
323
238
|
],
|
|
324
239
|
}));
|
|
325
240
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
326
241
|
const { name, arguments: args = {} } = request.params;
|
|
327
|
-
const
|
|
328
|
-
|
|
242
|
+
const handler = toolHandlers[name];
|
|
243
|
+
if (!handler) {
|
|
244
|
+
return err(`Unknown tool: ${name}`);
|
|
245
|
+
}
|
|
329
246
|
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
|
-
}
|
|
247
|
+
const validated = validateArgs(args);
|
|
248
|
+
return await handler(validated);
|
|
495
249
|
}
|
|
496
250
|
catch (error) {
|
|
497
251
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -502,22 +256,11 @@ export function createServer(options) {
|
|
|
502
256
|
const repoResult = ensureRepo(startupConfig.memoryDir, startupConfig.gitUrl);
|
|
503
257
|
console.error(`[knowledge] Repo init: ${repoResult.message}`);
|
|
504
258
|
if (options?.isLeader !== false) {
|
|
505
|
-
setTimeout(() => backgroundIndex().catch((
|
|
259
|
+
setTimeout(() => backgroundIndex().catch((bgErr) => console.error('[knowledge] Background index failed:', bgErr)), 5000);
|
|
506
260
|
}
|
|
507
261
|
else {
|
|
508
|
-
console.error('[knowledge] Follower instance
|
|
262
|
+
console.error('[knowledge] Follower instance -- skipping background indexing');
|
|
509
263
|
}
|
|
510
264
|
return server;
|
|
511
265
|
}
|
|
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
266
|
//# sourceMappingURL=server.js.map
|