@vheins/local-memory-mcp 0.1.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/DASHBOARD.md +129 -0
- package/HYBRID_SEARCH.md +204 -0
- package/IMPLEMENTATION.md +159 -0
- package/README.md +175 -0
- package/dist/capabilities.d.ts +22 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +23 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/dashboard/dashboard.test.d.ts +2 -0
- package/dist/dashboard/dashboard.test.d.ts.map +1 -0
- package/dist/dashboard/dashboard.test.js +362 -0
- package/dist/dashboard/dashboard.test.js.map +1 -0
- package/dist/dashboard/public/app.js +1187 -0
- package/dist/dashboard/public/chart.js +0 -0
- package/dist/dashboard/public/index.html +967 -0
- package/dist/dashboard/server.d.ts +3 -0
- package/dist/dashboard/server.d.ts.map +1 -0
- package/dist/dashboard/server.js +297 -0
- package/dist/dashboard/server.js.map +1 -0
- package/dist/mcp/client.d.ts +34 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +181 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/client.test.d.ts +2 -0
- package/dist/mcp/client.test.d.ts.map +1 -0
- package/dist/mcp/client.test.js +130 -0
- package/dist/mcp/client.test.js.map +1 -0
- package/dist/prompts/registry.d.ts +39 -0
- package/dist/prompts/registry.d.ts.map +1 -0
- package/dist/prompts/registry.js +90 -0
- package/dist/prompts/registry.js.map +1 -0
- package/dist/resources/index.d.ts +17 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +100 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/index.test.d.ts +2 -0
- package/dist/resources/index.test.d.ts.map +1 -0
- package/dist/resources/index.test.js +96 -0
- package/dist/resources/index.test.js.map +1 -0
- package/dist/router.d.ts +4 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +60 -0
- package/dist/router.js.map +1 -0
- package/dist/router.test.d.ts +2 -0
- package/dist/router.test.d.ts.map +1 -0
- package/dist/router.test.js +113 -0
- package/dist/router.test.js.map +1 -0
- package/dist/search_memory_example.d.ts +3 -0
- package/dist/search_memory_example.d.ts.map +1 -0
- package/dist/search_memory_example.js +56 -0
- package/dist/search_memory_example.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +91 -0
- package/dist/server.js.map +1 -0
- package/dist/storage/sqlite.d.ts +95 -0
- package/dist/storage/sqlite.d.ts.map +1 -0
- package/dist/storage/sqlite.js +537 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/storage/sqlite.test.d.ts +2 -0
- package/dist/storage/sqlite.test.d.ts.map +1 -0
- package/dist/storage/sqlite.test.js +358 -0
- package/dist/storage/sqlite.test.js.map +1 -0
- package/dist/storage/vectors.stub.d.ts +12 -0
- package/dist/storage/vectors.stub.d.ts.map +1 -0
- package/dist/storage/vectors.stub.js +88 -0
- package/dist/storage/vectors.stub.js.map +1 -0
- package/dist/store_memory_example.d.ts +3 -0
- package/dist/store_memory_example.d.ts.map +1 -0
- package/dist/store_memory_example.js +69 -0
- package/dist/store_memory_example.js.map +1 -0
- package/dist/test_quotes_client.d.ts +3 -0
- package/dist/test_quotes_client.d.ts.map +1 -0
- package/dist/test_quotes_client.js +72 -0
- package/dist/test_quotes_client.js.map +1 -0
- package/dist/tools/memory.delete.d.ts +9 -0
- package/dist/tools/memory.delete.d.ts.map +1 -0
- package/dist/tools/memory.delete.js +22 -0
- package/dist/tools/memory.delete.js.map +1 -0
- package/dist/tools/memory.recap.d.ts +4 -0
- package/dist/tools/memory.recap.d.ts.map +1 -0
- package/dist/tools/memory.recap.js +42 -0
- package/dist/tools/memory.recap.js.map +1 -0
- package/dist/tools/memory.search.d.ts +5 -0
- package/dist/tools/memory.search.d.ts.map +1 -0
- package/dist/tools/memory.search.js +192 -0
- package/dist/tools/memory.search.js.map +1 -0
- package/dist/tools/memory.search.test.d.ts +2 -0
- package/dist/tools/memory.search.test.d.ts.map +1 -0
- package/dist/tools/memory.search.test.js +181 -0
- package/dist/tools/memory.search.test.js.map +1 -0
- package/dist/tools/memory.store.d.ts +5 -0
- package/dist/tools/memory.store.d.ts.map +1 -0
- package/dist/tools/memory.store.js +41 -0
- package/dist/tools/memory.store.js.map +1 -0
- package/dist/tools/memory.summarize.d.ts +4 -0
- package/dist/tools/memory.summarize.d.ts.map +1 -0
- package/dist/tools/memory.summarize.js +13 -0
- package/dist/tools/memory.summarize.js.map +1 -0
- package/dist/tools/memory.update.d.ts +5 -0
- package/dist/tools/memory.update.d.ts.map +1 -0
- package/dist/tools/memory.update.js +31 -0
- package/dist/tools/memory.update.js.map +1 -0
- package/dist/tools/schemas.d.ts +334 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +251 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/git-scope.d.ts +8 -0
- package/dist/utils/git-scope.d.ts.map +1 -0
- package/dist/utils/git-scope.js +38 -0
- package/dist/utils/git-scope.js.map +1 -0
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +40 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logger.test.d.ts +2 -0
- package/dist/utils/logger.test.d.ts.map +1 -0
- package/dist/utils/logger.test.js +84 -0
- package/dist/utils/logger.test.js.map +1 -0
- package/dist/utils/mcp-response.d.ts +44 -0
- package/dist/utils/mcp-response.d.ts.map +1 -0
- package/dist/utils/mcp-response.js +81 -0
- package/dist/utils/mcp-response.js.map +1 -0
- package/dist/utils/normalize.d.ts +4 -0
- package/dist/utils/normalize.d.ts.map +1 -0
- package/dist/utils/normalize.js +51 -0
- package/dist/utils/normalize.js.map +1 -0
- package/dist/utils/normalize.test.d.ts +2 -0
- package/dist/utils/normalize.test.d.ts.map +1 -0
- package/dist/utils/normalize.test.js +159 -0
- package/dist/utils/normalize.test.js.map +1 -0
- package/dist/utils/query-expander.d.ts +2 -0
- package/dist/utils/query-expander.d.ts.map +1 -0
- package/dist/utils/query-expander.js +50 -0
- package/dist/utils/query-expander.js.map +1 -0
- package/dist/utils/query-expander.test.d.ts +2 -0
- package/dist/utils/query-expander.test.d.ts.map +1 -0
- package/dist/utils/query-expander.test.js +35 -0
- package/dist/utils/query-expander.test.js.map +1 -0
- package/docs/PRD.md +199 -0
- package/docs/PROMPT-agent.md +139 -0
- package/docs/SPEC-git-scope.md +172 -0
- package/docs/SPEC-heuristics.md +199 -0
- package/docs/SPEC-server.md +243 -0
- package/docs/SPEC-skeleton.md +255 -0
- package/docs/SPEC-sqlite-schema.md +183 -0
- package/docs/SPEC-tool-schema.md +201 -0
- package/docs/SPEC-vector-search.md +198 -0
- package/docs/TEST-scenarios.md +179 -0
- package/package.json +43 -0
- package/scripts/update-null-titles-ai.mjs +272 -0
- package/scripts/update-titles-batch.mjs +71 -0
- package/scripts/update-titles.mjs +66 -0
- package/seed-data.mjs +151 -0
- package/src/capabilities.ts +22 -0
- package/src/dashboard/dashboard.test.ts +546 -0
- package/src/dashboard/public/app.js +1187 -0
- package/src/dashboard/public/chart.js +0 -0
- package/src/dashboard/public/index.html +967 -0
- package/src/dashboard/server.ts +347 -0
- package/src/mcp/client.test.ts +164 -0
- package/src/mcp/client.ts +212 -0
- package/src/prompts/registry.ts +89 -0
- package/src/resources/index.test.ts +132 -0
- package/src/resources/index.ts +113 -0
- package/src/router.test.ts +145 -0
- package/src/router.ts +80 -0
- package/src/server.ts +99 -0
- package/src/storage/sqlite.test.ts +504 -0
- package/src/storage/sqlite.ts +688 -0
- package/src/storage/vectors.stub.ts +101 -0
- package/src/tools/memory.delete.ts +37 -0
- package/src/tools/memory.recap.ts +61 -0
- package/src/tools/memory.search.test.ts +276 -0
- package/src/tools/memory.search.ts +244 -0
- package/src/tools/memory.store.ts +56 -0
- package/src/tools/memory.summarize.ts +23 -0
- package/src/tools/memory.update.ts +46 -0
- package/src/tools/schemas.ts +261 -0
- package/src/types.ts +36 -0
- package/src/utils/git-scope.ts +42 -0
- package/src/utils/logger.test.ts +125 -0
- package/src/utils/logger.ts +53 -0
- package/src/utils/mcp-response.ts +116 -0
- package/src/utils/normalize.test.ts +203 -0
- package/src/utils/normalize.ts +53 -0
- package/src/utils/query-expander.test.ts +40 -0
- package/src/utils/query-expander.ts +60 -0
- package/storage/.gitkeep +5 -0
- package/test.sh +48 -0
- package/tsconfig.json +21 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// Shared schema components
|
|
3
|
+
export const MemoryScopeSchema = z.object({
|
|
4
|
+
repo: z.string().min(1),
|
|
5
|
+
branch: z.string().optional(),
|
|
6
|
+
folder: z.string().optional(),
|
|
7
|
+
language: z.string().optional()
|
|
8
|
+
});
|
|
9
|
+
export const MemoryTypeSchema = z.enum(["code_fact", "decision", "mistake", "pattern"]);
|
|
10
|
+
// Tool schemas
|
|
11
|
+
export const MemoryStoreSchema = z.object({
|
|
12
|
+
type: MemoryTypeSchema,
|
|
13
|
+
title: z.string().min(3).max(100),
|
|
14
|
+
content: z.string().min(10),
|
|
15
|
+
importance: z.number().min(1).max(5),
|
|
16
|
+
scope: MemoryScopeSchema,
|
|
17
|
+
ttlDays: z.number().min(1).optional()
|
|
18
|
+
});
|
|
19
|
+
export const MemoryUpdateSchema = z.object({
|
|
20
|
+
id: z.string().uuid(),
|
|
21
|
+
title: z.string().min(3).max(100).optional(),
|
|
22
|
+
content: z.string().min(10).optional(),
|
|
23
|
+
importance: z.number().min(1).max(5).optional()
|
|
24
|
+
}).refine((data) => data.content !== undefined || data.title !== undefined || data.importance !== undefined, { message: "At least one of title, content or importance must be provided" });
|
|
25
|
+
export const MemorySearchSchema = z.object({
|
|
26
|
+
query: z.string().min(3),
|
|
27
|
+
prompt: z.string().optional(),
|
|
28
|
+
repo: z.string().min(1),
|
|
29
|
+
types: z.array(MemoryTypeSchema).optional(),
|
|
30
|
+
minImportance: z.number().min(1).max(5).optional(),
|
|
31
|
+
limit: z.number().min(1).max(10).default(5),
|
|
32
|
+
includeRecap: z.boolean().default(false)
|
|
33
|
+
});
|
|
34
|
+
export const MemoryRecapSchema = z.object({
|
|
35
|
+
repo: z.string().min(1),
|
|
36
|
+
limit: z.number().min(1).max(50).default(20),
|
|
37
|
+
offset: z.number().min(0).default(0)
|
|
38
|
+
});
|
|
39
|
+
export const MemorySummarizeSchema = z.object({
|
|
40
|
+
repo: z.string().min(1),
|
|
41
|
+
signals: z.array(z.string().max(200)).min(1)
|
|
42
|
+
});
|
|
43
|
+
// Tool definitions for MCP
|
|
44
|
+
export const TOOL_DEFINITIONS = [
|
|
45
|
+
{
|
|
46
|
+
name: "memory-store",
|
|
47
|
+
description: "Store a new memory entry that affects future behavior",
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
type: {
|
|
52
|
+
type: "string",
|
|
53
|
+
enum: ["code_fact", "decision", "mistake", "pattern"],
|
|
54
|
+
description: "Type of memory being stored"
|
|
55
|
+
},
|
|
56
|
+
title: {
|
|
57
|
+
type: "string",
|
|
58
|
+
minLength: 3,
|
|
59
|
+
maxLength: 100,
|
|
60
|
+
description: "Short title for the memory (required)"
|
|
61
|
+
},
|
|
62
|
+
content: {
|
|
63
|
+
type: "string",
|
|
64
|
+
minLength: 10,
|
|
65
|
+
description: "The memory content (must be durable knowledge)"
|
|
66
|
+
},
|
|
67
|
+
importance: {
|
|
68
|
+
type: "number",
|
|
69
|
+
minimum: 1,
|
|
70
|
+
maximum: 5,
|
|
71
|
+
description: "Importance score (1-5)"
|
|
72
|
+
},
|
|
73
|
+
scope: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
repo: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: "Repository name (required)"
|
|
79
|
+
},
|
|
80
|
+
branch: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Git branch (optional)"
|
|
83
|
+
},
|
|
84
|
+
folder: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Specific folder path (optional)"
|
|
87
|
+
},
|
|
88
|
+
language: {
|
|
89
|
+
type: "string",
|
|
90
|
+
description: "Programming language (optional)"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
required: ["repo"]
|
|
94
|
+
},
|
|
95
|
+
ttlDays: {
|
|
96
|
+
type: "number",
|
|
97
|
+
minimum: 1,
|
|
98
|
+
description: "Time-to-live in days. Memory will expire after this many days (optional)"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
required: ["type", "title", "content", "importance", "scope"]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "memory-update",
|
|
106
|
+
description: "Update an existing memory entry",
|
|
107
|
+
inputSchema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
id: {
|
|
111
|
+
type: "string",
|
|
112
|
+
format: "uuid",
|
|
113
|
+
description: "Memory entry ID"
|
|
114
|
+
},
|
|
115
|
+
title: {
|
|
116
|
+
type: "string",
|
|
117
|
+
minLength: 3,
|
|
118
|
+
maxLength: 100,
|
|
119
|
+
description: "Updated title (optional)"
|
|
120
|
+
},
|
|
121
|
+
content: {
|
|
122
|
+
type: "string",
|
|
123
|
+
minLength: 10,
|
|
124
|
+
description: "Updated content (optional)"
|
|
125
|
+
},
|
|
126
|
+
importance: {
|
|
127
|
+
type: "number",
|
|
128
|
+
minimum: 1,
|
|
129
|
+
maximum: 5,
|
|
130
|
+
description: "Updated importance (optional)"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
required: ["id"]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "memory-search",
|
|
138
|
+
description: "Search for relevant memories in the current repository",
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
query: {
|
|
143
|
+
type: "string",
|
|
144
|
+
minLength: 3,
|
|
145
|
+
description: "Search query"
|
|
146
|
+
},
|
|
147
|
+
prompt: {
|
|
148
|
+
type: "string",
|
|
149
|
+
description: "Context/prompt to help determine relevance. Use this to specify what kind of information you're looking for (optional)"
|
|
150
|
+
},
|
|
151
|
+
repo: {
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "Repository name (required)"
|
|
154
|
+
},
|
|
155
|
+
types: {
|
|
156
|
+
type: "array",
|
|
157
|
+
items: {
|
|
158
|
+
type: "string",
|
|
159
|
+
enum: ["code_fact", "decision", "mistake", "pattern"]
|
|
160
|
+
},
|
|
161
|
+
description: "Filter by memory types (optional)"
|
|
162
|
+
},
|
|
163
|
+
minImportance: {
|
|
164
|
+
type: "number",
|
|
165
|
+
minimum: 1,
|
|
166
|
+
maximum: 5,
|
|
167
|
+
description: "Minimum importance score (optional)"
|
|
168
|
+
},
|
|
169
|
+
limit: {
|
|
170
|
+
type: "number",
|
|
171
|
+
minimum: 1,
|
|
172
|
+
maximum: 10,
|
|
173
|
+
default: 5,
|
|
174
|
+
description: "Maximum number of results"
|
|
175
|
+
},
|
|
176
|
+
includeRecap: {
|
|
177
|
+
type: "boolean",
|
|
178
|
+
default: false,
|
|
179
|
+
description: "Include recent memories recap context in the response (optional, default false)"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
required: ["query", "repo"]
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "memory-summarize",
|
|
187
|
+
description: "Update the summary for a repository",
|
|
188
|
+
inputSchema: {
|
|
189
|
+
type: "object",
|
|
190
|
+
properties: {
|
|
191
|
+
repo: {
|
|
192
|
+
type: "string",
|
|
193
|
+
description: "Repository name"
|
|
194
|
+
},
|
|
195
|
+
signals: {
|
|
196
|
+
type: "array",
|
|
197
|
+
items: {
|
|
198
|
+
type: "string",
|
|
199
|
+
maxLength: 200
|
|
200
|
+
},
|
|
201
|
+
minItems: 1,
|
|
202
|
+
description: "High-level signals to include in summary"
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
required: ["repo", "signals"]
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: "memory-delete",
|
|
210
|
+
description: "Soft-delete a memory entry (remove from active use)",
|
|
211
|
+
inputSchema: {
|
|
212
|
+
type: "object",
|
|
213
|
+
properties: {
|
|
214
|
+
id: {
|
|
215
|
+
type: "string",
|
|
216
|
+
format: "uuid",
|
|
217
|
+
description: "Memory entry ID to delete"
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
required: ["id"]
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "memory-recap",
|
|
225
|
+
description: "Get the last 20 memories from a repository for context",
|
|
226
|
+
inputSchema: {
|
|
227
|
+
type: "object",
|
|
228
|
+
properties: {
|
|
229
|
+
repo: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: "Repository name (required)"
|
|
232
|
+
},
|
|
233
|
+
limit: {
|
|
234
|
+
type: "number",
|
|
235
|
+
minimum: 1,
|
|
236
|
+
maximum: 50,
|
|
237
|
+
default: 20,
|
|
238
|
+
description: "Maximum number of memories to retrieve"
|
|
239
|
+
},
|
|
240
|
+
offset: {
|
|
241
|
+
type: "number",
|
|
242
|
+
minimum: 0,
|
|
243
|
+
default: 0,
|
|
244
|
+
description: "Number of memories to skip for pagination (optional, default 0)"
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
required: ["repo"]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
];
|
|
251
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/tools/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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QAAQ;oBACd,WAAW,EAAE,iBAAiB;iBAC/B;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,SAAS,EAAE,GAAG;qBACf;oBACD,QAAQ,EAAE,CAAC;oBACX,WAAW,EAAE,0CAA0C;iBACxD;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;SAC9B;KACF;IACD;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,qDAAqD;QAClE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,EAAE,EAAE;oBACF,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,MAAM;oBACd,WAAW,EAAE,2BAA2B;iBACzC;aACF;YACD,QAAQ,EAAE,CAAC,IAAI,CAAC;SACjB;KACF;IACD;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,wDAAwD;QACrE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4BAA4B;iBAC1C;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,EAAE;oBACX,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,wCAAwC;iBACtD;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,CAAC;oBACV,WAAW,EAAE,iEAAiE;iBAC/E;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB;KACF;CACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type MemoryType = "code_fact" | "decision" | "mistake" | "pattern";
|
|
2
|
+
export type MemoryScope = {
|
|
3
|
+
repo: string;
|
|
4
|
+
branch?: string;
|
|
5
|
+
folder?: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
};
|
|
8
|
+
export type MemoryEntry = {
|
|
9
|
+
id: string;
|
|
10
|
+
type: MemoryType;
|
|
11
|
+
title?: string;
|
|
12
|
+
content: string;
|
|
13
|
+
importance: number;
|
|
14
|
+
scope: MemoryScope;
|
|
15
|
+
created_at: string;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
hit_count: number;
|
|
18
|
+
recall_count: number;
|
|
19
|
+
last_used_at: string | null;
|
|
20
|
+
expires_at: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type VectorResult = {
|
|
23
|
+
id: string;
|
|
24
|
+
score: number;
|
|
25
|
+
};
|
|
26
|
+
export interface VectorStore {
|
|
27
|
+
upsert(id: string, text: string): Promise<void>;
|
|
28
|
+
remove(id: string): Promise<void>;
|
|
29
|
+
search(query: string, limit: number): Promise<VectorResult[]>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1E,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;CAC/D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oCAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-scope.d.ts","sourceRoot":"","sources":["../../src/utils/git-scope.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,GAAG,SAAgB;;;;;;EAsClD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export function resolveGitScope(cwd = process.cwd()) {
|
|
4
|
+
// 1. Try git root
|
|
5
|
+
try {
|
|
6
|
+
const root = execSync("git rev-parse --show-toplevel", {
|
|
7
|
+
cwd,
|
|
8
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
9
|
+
})
|
|
10
|
+
.toString()
|
|
11
|
+
.trim();
|
|
12
|
+
const repo = path.basename(root);
|
|
13
|
+
let branch;
|
|
14
|
+
try {
|
|
15
|
+
branch = execSync("git rev-parse --abbrev-ref HEAD", {
|
|
16
|
+
cwd,
|
|
17
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
18
|
+
})
|
|
19
|
+
.toString()
|
|
20
|
+
.trim();
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
return {
|
|
24
|
+
repo,
|
|
25
|
+
branch
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch { }
|
|
29
|
+
// 2. Fallback: project folder
|
|
30
|
+
const fallback = path.basename(cwd);
|
|
31
|
+
if (fallback) {
|
|
32
|
+
return {
|
|
33
|
+
repo: fallback
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Unable to resolve project scope (no git repo, no folder)");
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=git-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-scope.js","sourceRoot":"","sources":["../../src/utils/git-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,eAAe,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IACjD,kBAAkB;IAClB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,+BAA+B,EAAE;YACrD,GAAG;YACH,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;SACpC,CAAC;aACC,QAAQ,EAAE;aACV,IAAI,EAAE,CAAC;QAEV,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEjC,IAAI,MAA0B,CAAC;QAC/B,IAAI,CAAC;YACH,MAAM,GAAG,QAAQ,CAAC,iCAAiC,EAAE;gBACnD,GAAG;gBACH,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC;aACpC,CAAC;iBACC,QAAQ,EAAE;iBACV,IAAI,EAAE,CAAC;QACZ,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,OAAO;YACL,IAAI;YACJ,MAAM;SACP,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,8BAA8B;IAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAEpC,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const logger: {
|
|
2
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
3
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
4
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
5
|
+
error(message: string, context?: Record<string, unknown>): void;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAuCA,eAAO,MAAM,MAAM;mBACF,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;kBAGjD,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;kBAGhD,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;mBAG/C,MAAM,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAGhE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Structured logger — outputs JSON to stderr
|
|
2
|
+
// Requirements: 21.1, 21.2
|
|
3
|
+
const LEVELS = {
|
|
4
|
+
debug: 0,
|
|
5
|
+
info: 1,
|
|
6
|
+
warn: 2,
|
|
7
|
+
error: 3,
|
|
8
|
+
};
|
|
9
|
+
function parseLevel(raw) {
|
|
10
|
+
if (raw && raw in LEVELS)
|
|
11
|
+
return raw;
|
|
12
|
+
return "info";
|
|
13
|
+
}
|
|
14
|
+
const configuredLevel = parseLevel(process.env.LOG_LEVEL?.toLowerCase());
|
|
15
|
+
function log(level, message, context) {
|
|
16
|
+
if (LEVELS[level] < LEVELS[configuredLevel])
|
|
17
|
+
return;
|
|
18
|
+
const entry = {
|
|
19
|
+
level,
|
|
20
|
+
timestamp: new Date().toISOString(),
|
|
21
|
+
message,
|
|
22
|
+
...(context !== undefined ? { context } : {}),
|
|
23
|
+
};
|
|
24
|
+
process.stderr.write(JSON.stringify(entry) + "\n");
|
|
25
|
+
}
|
|
26
|
+
export const logger = {
|
|
27
|
+
debug(message, context) {
|
|
28
|
+
log("debug", message, context);
|
|
29
|
+
},
|
|
30
|
+
info(message, context) {
|
|
31
|
+
log("info", message, context);
|
|
32
|
+
},
|
|
33
|
+
warn(message, context) {
|
|
34
|
+
log("warn", message, context);
|
|
35
|
+
},
|
|
36
|
+
error(message, context) {
|
|
37
|
+
log("error", message, context);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,2BAA2B;AAW3B,MAAM,MAAM,GAA6B;IACvC,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,SAAS,UAAU,CAAC,GAAuB;IACzC,IAAI,GAAG,IAAI,GAAG,IAAI,MAAM;QAAE,OAAO,GAAe,CAAC;IACjD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,eAAe,GAAa,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AAEnF,SAAS,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,OAAiC;IAC9E,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC;QAAE,OAAO;IAEpD,MAAM,KAAK,GAAa;QACtB,KAAK;QACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,OAAO;QACP,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,CAAC,OAAe,EAAE,OAAiC;QACtD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,OAAe,EAAE,OAAiC;QACrD,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IACD,IAAI,CAAC,OAAe,EAAE,OAAiC;QACrD,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IACD,KAAK,CAAC,OAAe,EAAE,OAAiC;QACtD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.test.d.ts","sourceRoot":"","sources":["../../src/utils/logger.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Feature: memory-mcp-optimization
|
|
2
|
+
// Property 20: StructuredLogger output adalah JSON valid dengan field wajib
|
|
3
|
+
// Validates: Requirements 21.1, 21.2
|
|
4
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
5
|
+
import * as fc from "fast-check";
|
|
6
|
+
describe("Property 20: StructuredLogger output adalah JSON valid dengan field wajib", () => {
|
|
7
|
+
let stderrOutput = [];
|
|
8
|
+
let stderrSpy;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
stderrOutput = [];
|
|
11
|
+
stderrSpy = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
|
|
12
|
+
stderrOutput.push(typeof chunk === "string" ? chunk : chunk.toString());
|
|
13
|
+
return true;
|
|
14
|
+
});
|
|
15
|
+
// Reset LOG_LEVEL to ensure all levels are logged
|
|
16
|
+
process.env.LOG_LEVEL = "debug";
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
stderrSpy.mockRestore();
|
|
20
|
+
delete process.env.LOG_LEVEL;
|
|
21
|
+
});
|
|
22
|
+
it("each log call produces valid JSON output with required fields", async () => {
|
|
23
|
+
// Re-import logger after setting LOG_LEVEL
|
|
24
|
+
const { logger } = await import("./logger.js?t=" + Date.now());
|
|
25
|
+
fc.assert(fc.property(fc.oneof(fc.constant("debug"), fc.constant("info"), fc.constant("warn"), fc.constant("error")), fc.string({ minLength: 1, maxLength: 100 }), (level, message) => {
|
|
26
|
+
stderrOutput = [];
|
|
27
|
+
logger[level](message);
|
|
28
|
+
expect(stderrOutput.length).toBeGreaterThanOrEqual(1);
|
|
29
|
+
const lastOutput = stderrOutput[stderrOutput.length - 1];
|
|
30
|
+
// Must be parseable JSON
|
|
31
|
+
let parsed;
|
|
32
|
+
expect(() => {
|
|
33
|
+
parsed = JSON.parse(lastOutput.trim());
|
|
34
|
+
}).not.toThrow();
|
|
35
|
+
parsed = JSON.parse(lastOutput.trim());
|
|
36
|
+
// Must have required fields
|
|
37
|
+
expect(parsed).toHaveProperty("level");
|
|
38
|
+
expect(parsed).toHaveProperty("timestamp");
|
|
39
|
+
expect(parsed).toHaveProperty("message");
|
|
40
|
+
// level must match
|
|
41
|
+
expect(parsed.level).toBe(level);
|
|
42
|
+
// message must match
|
|
43
|
+
expect(parsed.message).toBe(message);
|
|
44
|
+
// timestamp must be ISO 8601
|
|
45
|
+
expect(typeof parsed.timestamp).toBe("string");
|
|
46
|
+
const ts = new Date(parsed.timestamp);
|
|
47
|
+
expect(isNaN(ts.getTime())).toBe(false);
|
|
48
|
+
}), { numRuns: 100 });
|
|
49
|
+
});
|
|
50
|
+
it("log output with context includes context field", async () => {
|
|
51
|
+
const { logger } = await import("./logger.js?t=" + Date.now() + "ctx");
|
|
52
|
+
stderrOutput = [];
|
|
53
|
+
logger.info("test message", { key: "value", count: 42 });
|
|
54
|
+
expect(stderrOutput.length).toBeGreaterThanOrEqual(1);
|
|
55
|
+
const lastOutput = stderrOutput[stderrOutput.length - 1];
|
|
56
|
+
const parsed = JSON.parse(lastOutput.trim());
|
|
57
|
+
expect(parsed).toHaveProperty("context");
|
|
58
|
+
expect(parsed.context).toEqual({ key: "value", count: 42 });
|
|
59
|
+
});
|
|
60
|
+
it("log output without context does not include context field", async () => {
|
|
61
|
+
const { logger } = await import("./logger.js?t=" + Date.now() + "noctx");
|
|
62
|
+
stderrOutput = [];
|
|
63
|
+
logger.info("no context message");
|
|
64
|
+
expect(stderrOutput.length).toBeGreaterThanOrEqual(1);
|
|
65
|
+
const lastOutput = stderrOutput[stderrOutput.length - 1];
|
|
66
|
+
const parsed = JSON.parse(lastOutput.trim());
|
|
67
|
+
expect(parsed).not.toHaveProperty("context");
|
|
68
|
+
});
|
|
69
|
+
it("all four log levels produce valid JSON with correct level field", async () => {
|
|
70
|
+
const { logger } = await import("./logger.js?t=" + Date.now() + "levels");
|
|
71
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
72
|
+
for (const level of levels) {
|
|
73
|
+
stderrOutput = [];
|
|
74
|
+
logger[level](`test ${level} message`);
|
|
75
|
+
expect(stderrOutput.length).toBeGreaterThanOrEqual(1);
|
|
76
|
+
const lastOutput = stderrOutput[stderrOutput.length - 1];
|
|
77
|
+
const parsed = JSON.parse(lastOutput.trim());
|
|
78
|
+
expect(parsed.level).toBe(level);
|
|
79
|
+
expect(parsed.message).toBe(`test ${level} message`);
|
|
80
|
+
expect(typeof parsed.timestamp).toBe("string");
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=logger.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.test.js","sourceRoot":"","sources":["../../src/utils/logger.test.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,4EAA4E;AAC5E,qCAAqC;AAErC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAOjC,QAAQ,CAAC,2EAA2E,EAAE,GAAG,EAAE;IACzF,IAAI,YAAY,GAAa,EAAE,CAAC;IAChC,IAAI,SAAsC,CAAC;IAE3C,UAAU,CAAC,GAAG,EAAE;QACd,YAAY,GAAG,EAAE,CAAC;QAClB,SAAS,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,EAAE;YACzE,YAAY,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACxE,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,kDAAkD;QAClD,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,OAAO,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,CAAC,WAAW,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,GAA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AY,CAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACzD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YAE7C,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC;YACrD,MAAM,CAAC,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const McpContentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
type: z.ZodLiteral<"text">;
|
|
4
|
+
text: z.ZodString;
|
|
5
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
6
|
+
type: z.ZodLiteral<"image">;
|
|
7
|
+
data: z.ZodString;
|
|
8
|
+
mimeType: z.ZodString;
|
|
9
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"resource">;
|
|
11
|
+
resource: z.ZodObject<{
|
|
12
|
+
uri: z.ZodString;
|
|
13
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
14
|
+
text: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
}, z.core.$strip>], "type">;
|
|
17
|
+
export type McpContent = z.infer<typeof McpContentSchema>;
|
|
18
|
+
export type McpResponse = {
|
|
19
|
+
content: McpContent[];
|
|
20
|
+
};
|
|
21
|
+
export declare function createMcpResponse(data: unknown, summary: string, options?: {
|
|
22
|
+
query?: string;
|
|
23
|
+
results?: Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
content: string;
|
|
28
|
+
importance?: number;
|
|
29
|
+
scope?: {
|
|
30
|
+
repo: string;
|
|
31
|
+
folder?: string;
|
|
32
|
+
language?: string;
|
|
33
|
+
};
|
|
34
|
+
created_at?: string;
|
|
35
|
+
updated_at?: string;
|
|
36
|
+
hit_count?: number;
|
|
37
|
+
recall_count?: number;
|
|
38
|
+
last_used_at?: string | null;
|
|
39
|
+
expires_at?: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
}): McpResponse;
|
|
42
|
+
export declare function createTextOnlyResponse(text: string): McpResponse;
|
|
43
|
+
export declare function isMcpResponse(obj: unknown): obj is McpResponse;
|
|
44
|
+
//# sourceMappingURL=mcp-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-response.d.ts","sourceRoot":"","sources":["../../src/utils/mcp-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;2BAkB3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IACR,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,CAAC,CAAA;CACH,GACA,WAAW,CA2Cb;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAShE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW,CAW9D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const McpContentSchema = z.discriminatedUnion("type", [
|
|
3
|
+
z.object({
|
|
4
|
+
type: z.literal("text"),
|
|
5
|
+
text: z.string(),
|
|
6
|
+
}),
|
|
7
|
+
z.object({
|
|
8
|
+
type: z.literal("image"),
|
|
9
|
+
data: z.string(),
|
|
10
|
+
mimeType: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
z.object({
|
|
13
|
+
type: z.literal("resource"),
|
|
14
|
+
resource: z.object({
|
|
15
|
+
uri: z.string(),
|
|
16
|
+
mimeType: z.string().optional(),
|
|
17
|
+
text: z.string().optional(),
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
export function createMcpResponse(data, summary, options) {
|
|
22
|
+
const { query, results } = options || {};
|
|
23
|
+
const content = [
|
|
24
|
+
{
|
|
25
|
+
type: "text",
|
|
26
|
+
text: summary,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
// Add resource for each result with embedded content
|
|
30
|
+
if (results && results.length > 0) {
|
|
31
|
+
for (const result of results) {
|
|
32
|
+
const resultId = Buffer.from(result.id).toString('base64').substring(0, 8);
|
|
33
|
+
// Generate title from content if not present
|
|
34
|
+
const title = result.title || (result.content.length > 50 ? result.content.substring(0, 50) + '...' : result.content);
|
|
35
|
+
content.push({
|
|
36
|
+
type: "resource",
|
|
37
|
+
resource: {
|
|
38
|
+
uri: `memory://${resultId}`,
|
|
39
|
+
mimeType: "application/json",
|
|
40
|
+
text: JSON.stringify({
|
|
41
|
+
id: result.id,
|
|
42
|
+
type: result.type,
|
|
43
|
+
title: title,
|
|
44
|
+
content: result.content,
|
|
45
|
+
importance: result.importance,
|
|
46
|
+
scope: result.scope,
|
|
47
|
+
created_at: result.created_at,
|
|
48
|
+
updated_at: result.updated_at,
|
|
49
|
+
hit_count: result.hit_count,
|
|
50
|
+
recall_count: result.recall_count,
|
|
51
|
+
last_used_at: result.last_used_at,
|
|
52
|
+
expires_at: result.expires_at
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { content };
|
|
59
|
+
}
|
|
60
|
+
export function createTextOnlyResponse(text) {
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function isMcpResponse(obj) {
|
|
71
|
+
if (typeof obj !== "object" || obj === null)
|
|
72
|
+
return false;
|
|
73
|
+
const response = obj;
|
|
74
|
+
if (!Array.isArray(response.content))
|
|
75
|
+
return false;
|
|
76
|
+
return response.content.every((item) => typeof item === "object" &&
|
|
77
|
+
item !== null &&
|
|
78
|
+
"type" in item &&
|
|
79
|
+
typeof item.type === "string");
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=mcp-response.js.map
|