sverklo 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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/bin/sverklo.d.ts +2 -0
- package/dist/bin/sverklo.js +41 -0
- package/dist/bin/sverklo.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/indexer/describer.d.ts +2 -0
- package/dist/src/indexer/describer.js +112 -0
- package/dist/src/indexer/describer.js.map +1 -0
- package/dist/src/indexer/embedder.d.ts +4 -0
- package/dist/src/indexer/embedder.js +249 -0
- package/dist/src/indexer/embedder.js.map +1 -0
- package/dist/src/indexer/file-discovery.d.ts +9 -0
- package/dist/src/indexer/file-discovery.js +52 -0
- package/dist/src/indexer/file-discovery.js.map +1 -0
- package/dist/src/indexer/graph-builder.d.ts +5 -0
- package/dist/src/indexer/graph-builder.js +77 -0
- package/dist/src/indexer/graph-builder.js.map +1 -0
- package/dist/src/indexer/indexer.d.ts +26 -0
- package/dist/src/indexer/indexer.js +180 -0
- package/dist/src/indexer/indexer.js.map +1 -0
- package/dist/src/indexer/parser.d.ts +2 -0
- package/dist/src/indexer/parser.js +467 -0
- package/dist/src/indexer/parser.js.map +1 -0
- package/dist/src/indexer/setup.d.ts +1 -0
- package/dist/src/indexer/setup.js +38 -0
- package/dist/src/indexer/setup.js.map +1 -0
- package/dist/src/indexer/watcher.d.ts +2 -0
- package/dist/src/indexer/watcher.js +51 -0
- package/dist/src/indexer/watcher.js.map +1 -0
- package/dist/src/memory/git-state.d.ts +4 -0
- package/dist/src/memory/git-state.js +12 -0
- package/dist/src/memory/git-state.js.map +1 -0
- package/dist/src/memory/staleness.d.ts +4 -0
- package/dist/src/memory/staleness.js +19 -0
- package/dist/src/memory/staleness.js.map +1 -0
- package/dist/src/search/hybrid-search.d.ts +13 -0
- package/dist/src/search/hybrid-search.js +97 -0
- package/dist/src/search/hybrid-search.js.map +1 -0
- package/dist/src/search/pagerank.d.ts +4 -0
- package/dist/src/search/pagerank.js +64 -0
- package/dist/src/search/pagerank.js.map +1 -0
- package/dist/src/search/token-budget.d.ts +10 -0
- package/dist/src/search/token-budget.js +67 -0
- package/dist/src/search/token-budget.js.map +1 -0
- package/dist/src/server/mcp-server.d.ts +1 -0
- package/dist/src/server/mcp-server.js +120 -0
- package/dist/src/server/mcp-server.js.map +1 -0
- package/dist/src/server/tools/dependencies.d.ts +29 -0
- package/dist/src/server/tools/dependencies.js +118 -0
- package/dist/src/server/tools/dependencies.js.map +1 -0
- package/dist/src/server/tools/find-references.d.ts +20 -0
- package/dist/src/server/tools/find-references.js +80 -0
- package/dist/src/server/tools/find-references.js.map +1 -0
- package/dist/src/server/tools/forget.d.ts +16 -0
- package/dist/src/server/tools/forget.js +24 -0
- package/dist/src/server/tools/forget.js.map +1 -0
- package/dist/src/server/tools/index-status.d.ts +10 -0
- package/dist/src/server/tools/index-status.js +21 -0
- package/dist/src/server/tools/index-status.js.map +1 -0
- package/dist/src/server/tools/lookup.d.ts +25 -0
- package/dist/src/server/tools/lookup.js +54 -0
- package/dist/src/server/tools/lookup.js.map +1 -0
- package/dist/src/server/tools/memories.d.ts +24 -0
- package/dist/src/server/tools/memories.js +61 -0
- package/dist/src/server/tools/memories.js.map +1 -0
- package/dist/src/server/tools/overview.d.ts +19 -0
- package/dist/src/server/tools/overview.js +32 -0
- package/dist/src/server/tools/overview.js.map +1 -0
- package/dist/src/server/tools/recall.d.ts +29 -0
- package/dist/src/server/tools/recall.js +113 -0
- package/dist/src/server/tools/recall.js.map +1 -0
- package/dist/src/server/tools/remember.d.ts +39 -0
- package/dist/src/server/tools/remember.js +56 -0
- package/dist/src/server/tools/remember.js.map +1 -0
- package/dist/src/server/tools/search.d.ts +33 -0
- package/dist/src/server/tools/search.js +43 -0
- package/dist/src/server/tools/search.js.map +1 -0
- package/dist/src/storage/chunk-store.d.ts +25 -0
- package/dist/src/storage/chunk-store.js +74 -0
- package/dist/src/storage/chunk-store.js.map +1 -0
- package/dist/src/storage/database.d.ts +2 -0
- package/dist/src/storage/database.js +140 -0
- package/dist/src/storage/database.js.map +1 -0
- package/dist/src/storage/embedding-store.d.ts +14 -0
- package/dist/src/storage/embedding-store.js +42 -0
- package/dist/src/storage/embedding-store.js.map +1 -0
- package/dist/src/storage/file-store.d.ts +19 -0
- package/dist/src/storage/file-store.js +44 -0
- package/dist/src/storage/file-store.js.map +1 -0
- package/dist/src/storage/graph-store.d.ts +16 -0
- package/dist/src/storage/graph-store.js +37 -0
- package/dist/src/storage/graph-store.js.map +1 -0
- package/dist/src/storage/memory-embedding-store.d.ts +13 -0
- package/dist/src/storage/memory-embedding-store.js +38 -0
- package/dist/src/storage/memory-embedding-store.js.map +1 -0
- package/dist/src/storage/memory-store.d.ts +29 -0
- package/dist/src/storage/memory-store.js +86 -0
- package/dist/src/storage/memory-store.js.map +1 -0
- package/dist/src/types/index.d.ts +87 -0
- package/dist/src/types/index.js +21 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/config.d.ts +2 -0
- package/dist/src/utils/config.js +18 -0
- package/dist/src/utils/config.js.map +1 -0
- package/dist/src/utils/ignore.d.ts +2 -0
- package/dist/src/utils/ignore.js +72 -0
- package/dist/src/utils/ignore.js.map +1 -0
- package/dist/src/utils/logger.d.ts +2 -0
- package/dist/src/utils/logger.js +16 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/tokens.d.ts +2 -0
- package/dist/src/utils/tokens.js +12 -0
- package/dist/src/utils/tokens.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const findReferencesTool = {
|
|
2
|
+
name: "find_references",
|
|
3
|
+
description: "Find all references to a symbol across the codebase. Shows where a function, class, or type is imported, called, or used.",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
symbol: {
|
|
8
|
+
type: "string",
|
|
9
|
+
description: "Symbol name to find references for",
|
|
10
|
+
},
|
|
11
|
+
token_budget: {
|
|
12
|
+
type: "number",
|
|
13
|
+
description: "Max tokens to return (default: 3000)",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
required: ["symbol"],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export function handleFindReferences(indexer, args) {
|
|
20
|
+
const symbol = args.symbol;
|
|
21
|
+
const tokenBudget = args.token_budget || 3000;
|
|
22
|
+
// Use FTS to find all mentions of the symbol
|
|
23
|
+
const ftsResults = indexer.chunkStore.searchFts(symbol, 50);
|
|
24
|
+
const fileCache = new Map();
|
|
25
|
+
for (const f of indexer.fileStore.getAll()) {
|
|
26
|
+
fileCache.set(f.id, f);
|
|
27
|
+
}
|
|
28
|
+
// Group by file
|
|
29
|
+
const byFile = new Map();
|
|
30
|
+
for (const chunk of ftsResults) {
|
|
31
|
+
const file = fileCache.get(chunk.file_id);
|
|
32
|
+
if (!file)
|
|
33
|
+
continue;
|
|
34
|
+
// Check if this chunk actually contains the symbol name
|
|
35
|
+
if (!chunk.content.includes(symbol))
|
|
36
|
+
continue;
|
|
37
|
+
// Find specific lines with the symbol
|
|
38
|
+
const lines = chunk.content.split("\n");
|
|
39
|
+
for (let i = 0; i < lines.length; i++) {
|
|
40
|
+
if (lines[i].includes(symbol)) {
|
|
41
|
+
const refs = byFile.get(file.path) || [];
|
|
42
|
+
refs.push({
|
|
43
|
+
line: chunk.start_line + i,
|
|
44
|
+
context: lines[i].trim(),
|
|
45
|
+
type: chunk.type,
|
|
46
|
+
});
|
|
47
|
+
byFile.set(file.path, refs);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Format output
|
|
52
|
+
const parts = [];
|
|
53
|
+
let remaining = tokenBudget;
|
|
54
|
+
// Sort files by PageRank
|
|
55
|
+
const sortedFiles = [...byFile.entries()].sort((a, b) => {
|
|
56
|
+
const fileA = [...fileCache.values()].find((f) => f.path === a[0]);
|
|
57
|
+
const fileB = [...fileCache.values()].find((f) => f.path === b[0]);
|
|
58
|
+
return (fileB?.pagerank || 0) - (fileA?.pagerank || 0);
|
|
59
|
+
});
|
|
60
|
+
parts.push(`## References to '${symbol}' (${sortedFiles.reduce((s, [, refs]) => s + refs.length, 0)} total)\n`);
|
|
61
|
+
for (const [filePath, refs] of sortedFiles) {
|
|
62
|
+
const header = `### ${filePath}`;
|
|
63
|
+
const headerCost = Math.ceil(header.length / 3.5);
|
|
64
|
+
if (remaining < headerCost + 20)
|
|
65
|
+
break;
|
|
66
|
+
parts.push(header);
|
|
67
|
+
remaining -= headerCost;
|
|
68
|
+
for (const ref of refs) {
|
|
69
|
+
const line = ` L${ref.line}: ${ref.context}`;
|
|
70
|
+
const lineCost = Math.ceil(line.length / 3.5);
|
|
71
|
+
if (remaining < lineCost)
|
|
72
|
+
break;
|
|
73
|
+
parts.push(line);
|
|
74
|
+
remaining -= lineCost;
|
|
75
|
+
}
|
|
76
|
+
parts.push("");
|
|
77
|
+
}
|
|
78
|
+
return parts.length > 1 ? parts.join("\n") : `No references found for '${symbol}'.`;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=find-references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-references.js","sourceRoot":"","sources":["../../../../src/server/tools/find-references.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EACT,2HAA2H;IAC7H,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,oCAAoC;aAClD;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;SACF;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB;CACF,CAAC;AAEF,MAAM,U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,MAAM,GAAG,OAAO,QAAQ,EAAE,CAAC;QACjC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;QAClD,IAAI,SAAS,GAAG,UAAU,GAAG,EAAE;YAAE,MAAM;QAEvC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,SAAS,IAAI,UAAU,CAAC;QAExB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;YAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;YAC9C,IAAI,SAAS,GAAG,QAAQ;gBAAE,MAAM;YAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,SAAS,IAAI,QAAQ,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,4BAA4B,MAAM,IAAI,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const forgetTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
id: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
required: string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare function handleForget(indexer: Indexer, args: Record<string, unknown>): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const forgetTool = {
|
|
2
|
+
name: "forget",
|
|
3
|
+
description: "Remove a memory by ID.",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
id: {
|
|
8
|
+
type: "number",
|
|
9
|
+
description: "Memory ID to delete (from recall results)",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
required: ["id"],
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
export function handleForget(indexer, args) {
|
|
16
|
+
const id = args.id;
|
|
17
|
+
const memory = indexer.memoryStore.getById(id);
|
|
18
|
+
if (!memory) {
|
|
19
|
+
return `Memory #${id} not found.`;
|
|
20
|
+
}
|
|
21
|
+
indexer.memoryStore.delete(id);
|
|
22
|
+
return `Deleted memory #${id} (${memory.category}): "${memory.content.slice(0, 80)}${memory.content.length > 80 ? "..." : ""}"`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=forget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forget.js","sourceRoot":"","sources":["../../../../src/server/tools/forget.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,wBAAwB;IACrC,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,EAAE,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,2CAA2C;aACzD;SACF;QACD,QAAQ,EAAE,CAAC,IAAI,CAAC;KACjB;CACF,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,OAAgB,EAChB,IAA6B;IAE7B,MAAM,EAAE,GAAG,IAAI,CAAC,EAAY,CAAC;IAE7B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,WAAW,EAAE,aAAa,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC/B,OAAO,mBAAmB,EAAE,KAAK,MAAM,CAAC,QAAQ,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;AAClI,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const indexStatusTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {};
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare function handleIndexStatus(indexer: Indexer): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const indexStatusTool = {
|
|
2
|
+
name: "index_status",
|
|
3
|
+
description: "Check the status of the codebase index. Shows whether indexing is complete, how many files are indexed, and when the index was last updated.",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {},
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
export function handleIndexStatus(indexer) {
|
|
10
|
+
const status = indexer.getStatus();
|
|
11
|
+
const parts = [
|
|
12
|
+
`Project: ${status.projectName}`,
|
|
13
|
+
`Root: ${status.rootPath}`,
|
|
14
|
+
`Files indexed: ${status.fileCount}`,
|
|
15
|
+
`Code chunks: ${status.chunkCount}`,
|
|
16
|
+
`Languages: ${status.languages.join(", ") || "none"}`,
|
|
17
|
+
`Status: ${status.indexing ? `indexing (${status.progress?.done}/${status.progress?.total})` : "ready"}`,
|
|
18
|
+
];
|
|
19
|
+
return parts.join("\n");
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-status.js","sourceRoot":"","sources":["../../../../src/server/tools/index-status.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc;IACpB,WAAW,EACT,8IAA8I;IAChJ,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE,EAAE;KACf;CACF,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAEnC,MAAM,KAAK,GAAG;QACZ,YAAY,MAAM,CAAC,WAAW,EAAE;QAChC,SAAS,MAAM,CAAC,QAAQ,EAAE;QAC1B,kBAAkB,MAAM,CAAC,SAAS,EAAE;QACpC,gBAAgB,MAAM,CAAC,UAAU,EAAE;QACnC,cAAc,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE;QACrD,WAAW,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,QAAQ,EAAE,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE;KACzG,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const lookupTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
symbol: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
type: {
|
|
13
|
+
type: string;
|
|
14
|
+
enum: string[];
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
token_budget: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
required: string[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function handleLookup(indexer: Indexer, args: Record<string, unknown>): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { formatLookup } from "../../search/token-budget.js";
|
|
2
|
+
export const lookupTool = {
|
|
3
|
+
name: "lookup",
|
|
4
|
+
description: "Look up a specific symbol (function, class, type, variable) by name. Returns its full definition, signature, and location.",
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object",
|
|
7
|
+
properties: {
|
|
8
|
+
symbol: {
|
|
9
|
+
type: "string",
|
|
10
|
+
description: "Symbol name to look up (exact or prefix match)",
|
|
11
|
+
},
|
|
12
|
+
type: {
|
|
13
|
+
type: "string",
|
|
14
|
+
enum: [
|
|
15
|
+
"function",
|
|
16
|
+
"class",
|
|
17
|
+
"type",
|
|
18
|
+
"interface",
|
|
19
|
+
"method",
|
|
20
|
+
"variable",
|
|
21
|
+
"any",
|
|
22
|
+
],
|
|
23
|
+
description: "Filter by symbol type",
|
|
24
|
+
},
|
|
25
|
+
token_budget: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Max tokens to return (default: 2000)",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["symbol"],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export function handleLookup(indexer, args) {
|
|
34
|
+
const symbol = args.symbol;
|
|
35
|
+
const type = args.type || "any";
|
|
36
|
+
const tokenBudget = args.token_budget || 2000;
|
|
37
|
+
let chunks = indexer.chunkStore.getByName(symbol, 20);
|
|
38
|
+
if (type !== "any") {
|
|
39
|
+
chunks = chunks.filter((c) => c.type === type);
|
|
40
|
+
}
|
|
41
|
+
// Get file data for PageRank ordering
|
|
42
|
+
const fileCache = new Map();
|
|
43
|
+
for (const f of indexer.fileStore.getAll()) {
|
|
44
|
+
fileCache.set(f.id, f);
|
|
45
|
+
}
|
|
46
|
+
// Sort by PageRank of containing file
|
|
47
|
+
chunks.sort((a, b) => {
|
|
48
|
+
const fa = fileCache.get(a.file_id);
|
|
49
|
+
const fb = fileCache.get(b.file_id);
|
|
50
|
+
return (fb?.pagerank || 0) - (fa?.pagerank || 0);
|
|
51
|
+
});
|
|
52
|
+
return formatLookup(chunks, fileCache, tokenBudget);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../../../src/server/tools/lookup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,WAAW,EACT,4HAA4H;IAC9H,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gDAAgD;aAC9D;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE;oBACJ,UAAU;oBACV,OAAO;oBACP,MAAM;oBACN,WAAW;oBACX,QAAQ;oBACR,UAAU;oBACV,KAAK;iBACN;gBACD,WAAW,EAAE,uBAAuB;aACrC;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;SACF;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB;CACF,CAAC;AAEF,MAAM,UAAU,YAAY,CAC1B,OAAgB,EAChB,IAA6B;IAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAgB,CAAC;IACrC,MAAM,IAAI,GAAI,IAAI,CAAC,IAA0B,IAAI,KAAK,CAAC;IACvD,MAAM,WAAW,GAAI,IAAI,CAAC,YAAuB,IAAI,IAAI,CAAC;IAE1D,IAAI,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEtD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,sCAAsC;IACtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAChD,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QAC3C,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC;IAED,sCAAsC;IACtC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACpC,OAAO,CAAC,EAAE,EAAE,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const memoriesTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
category: {
|
|
9
|
+
type: string;
|
|
10
|
+
enum: string[];
|
|
11
|
+
description: string;
|
|
12
|
+
};
|
|
13
|
+
limit: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
stale_only: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare function handleMemories(indexer: Indexer, args: Record<string, unknown>): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const memoriesTool = {
|
|
2
|
+
name: "memories",
|
|
3
|
+
description: "List all memories for the current project. Shows memory health: staleness, confidence, access frequency.",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
category: {
|
|
8
|
+
type: "string",
|
|
9
|
+
enum: ["decision", "preference", "pattern", "context", "todo", "any"],
|
|
10
|
+
description: "Filter by category (default: 'any')",
|
|
11
|
+
},
|
|
12
|
+
limit: {
|
|
13
|
+
type: "number",
|
|
14
|
+
description: "Max memories to return (default: 50)",
|
|
15
|
+
},
|
|
16
|
+
stale_only: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
description: "Only show stale memories (default: false)",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export function handleMemories(indexer, args) {
|
|
24
|
+
const category = args.category || "any";
|
|
25
|
+
const limit = args.limit || 50;
|
|
26
|
+
const staleOnly = args.stale_only || false;
|
|
27
|
+
let memories;
|
|
28
|
+
if (staleOnly) {
|
|
29
|
+
memories = indexer.memoryStore.getStale();
|
|
30
|
+
}
|
|
31
|
+
else if (category !== "any") {
|
|
32
|
+
memories = indexer.memoryStore.getByCategory(category, limit);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
memories = indexer.memoryStore.getAll(limit);
|
|
36
|
+
}
|
|
37
|
+
if (memories.length === 0) {
|
|
38
|
+
return "No memories stored yet. Use the `remember` tool to save decisions, preferences, and patterns.";
|
|
39
|
+
}
|
|
40
|
+
const total = indexer.memoryStore.count();
|
|
41
|
+
const header = `## Memories (${memories.length}${memories.length < total ? ` of ${total}` : ""})\n`;
|
|
42
|
+
const rows = memories.map((m) => {
|
|
43
|
+
const tags = m.tags ? JSON.parse(m.tags).join(", ") : "";
|
|
44
|
+
const stale = m.is_stale ? " [STALE]" : "";
|
|
45
|
+
const age = formatAge(m.created_at);
|
|
46
|
+
return `- **#${m.id}** [${m.category}]${stale} ${m.content.slice(0, 120)}${m.content.length > 120 ? "..." : ""}\n _${age} ago | conf: ${m.confidence} | used: ${m.access_count}x${tags ? ` | ${tags}` : ""}_`;
|
|
47
|
+
});
|
|
48
|
+
return header + rows.join("\n\n");
|
|
49
|
+
}
|
|
50
|
+
function formatAge(timestamp) {
|
|
51
|
+
const ms = Date.now() - timestamp;
|
|
52
|
+
const mins = Math.floor(ms / 60000);
|
|
53
|
+
if (mins < 60)
|
|
54
|
+
return `${mins}m`;
|
|
55
|
+
const hours = Math.floor(mins / 60);
|
|
56
|
+
if (hours < 24)
|
|
57
|
+
return `${hours}h`;
|
|
58
|
+
const days = Math.floor(hours / 24);
|
|
59
|
+
return `${days}d`;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=memories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memories.js","sourceRoot":"","sources":["../../../../src/server/tools/memories.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,UAAU;IAChB,WAAW,EACT,0GAA0G;IAC5G,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC;gBACrE,WAAW,EAAE,qCAAqC;aACnD;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;YACD,UAAU,EAAE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Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const overviewTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
path: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
token_budget: {
|
|
13
|
+
type: string;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function handleOverview(indexer: Indexer, args: Record<string, unknown>): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { formatOverview } from "../../search/token-budget.js";
|
|
2
|
+
export const overviewTool = {
|
|
3
|
+
name: "overview",
|
|
4
|
+
description: "Get a structural overview of the codebase showing the most important files and their key symbols (functions, classes, types), ranked by structural importance (PageRank).",
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object",
|
|
7
|
+
properties: {
|
|
8
|
+
path: {
|
|
9
|
+
type: "string",
|
|
10
|
+
description: "Directory to overview (default: project root)",
|
|
11
|
+
},
|
|
12
|
+
token_budget: {
|
|
13
|
+
type: "number",
|
|
14
|
+
description: "Max tokens to return (default: 4000)",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export function handleOverview(indexer, args) {
|
|
20
|
+
const path = args.path;
|
|
21
|
+
const tokenBudget = args.token_budget || 4000;
|
|
22
|
+
const files = indexer.fileStore.getAll(); // already sorted by pagerank DESC
|
|
23
|
+
const entries = [];
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
if (path && !file.path.startsWith(path))
|
|
26
|
+
continue;
|
|
27
|
+
const chunks = indexer.chunkStore.getByFile(file.id);
|
|
28
|
+
entries.push({ file, chunks });
|
|
29
|
+
}
|
|
30
|
+
return formatOverview(entries, tokenBudget, path);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=overview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overview.js","sourceRoot":"","sources":["../../../../src/server/tools/overview.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,8BAA8B,CAAC;AAElF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,UAAU;IAChB,WAAW,EACT,2KAA2K;IAC7K,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+CAA+C;aAC7D;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;SACF;KACF;CACF,CAAC;AAEF,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,IAA6B;IAE7B,MAAM,IAAI,GAAG,IAAI,CAAC,IAA0B,CAAC;IAC7C,MAAM,WAAW,GAAI,IAAI,CAAC,YAAuB,IAAI,IAAI,CAAC;IAE1D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,kCAAkC;IAE5E,MAAM,OAAO,GAAoB,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QAClD,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const recallTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
query: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
category: {
|
|
13
|
+
type: string;
|
|
14
|
+
enum: string[];
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
limit: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
include_stale: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
required: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare function handleRecall(indexer: Indexer, args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { embed, cosineSimilarity } from "../../indexer/embedder.js";
|
|
2
|
+
import { checkStaleness } from "../../memory/staleness.js";
|
|
3
|
+
const RRF_K = 60;
|
|
4
|
+
export const recallTool = {
|
|
5
|
+
name: "recall",
|
|
6
|
+
description: "Search memories semantically. Finds past decisions, preferences, and patterns relevant to a query.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
query: {
|
|
11
|
+
type: "string",
|
|
12
|
+
description: "What to search for in memories",
|
|
13
|
+
},
|
|
14
|
+
category: {
|
|
15
|
+
type: "string",
|
|
16
|
+
enum: ["decision", "preference", "pattern", "context", "todo", "any"],
|
|
17
|
+
description: "Filter by category (default: 'any')",
|
|
18
|
+
},
|
|
19
|
+
limit: {
|
|
20
|
+
type: "number",
|
|
21
|
+
description: "Max memories to return (default: 10)",
|
|
22
|
+
},
|
|
23
|
+
include_stale: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "Include stale memories (default: false)",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ["query"],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export async function handleRecall(indexer, args) {
|
|
32
|
+
const query = args.query;
|
|
33
|
+
const category = args.category || "any";
|
|
34
|
+
const limit = args.limit || 10;
|
|
35
|
+
const includeStale = args.include_stale || false;
|
|
36
|
+
// Signal A: FTS text search
|
|
37
|
+
const ftsResults = indexer.memoryStore.searchFts(query, 30);
|
|
38
|
+
// Signal B: Vector similarity
|
|
39
|
+
const [queryVector] = await embed([query]);
|
|
40
|
+
const allEmbeddings = indexer.memoryEmbeddingStore.getAll();
|
|
41
|
+
const vectorScores = [];
|
|
42
|
+
for (const [memoryId, vec] of allEmbeddings) {
|
|
43
|
+
vectorScores.push({ memoryId, score: cosineSimilarity(queryVector, vec) });
|
|
44
|
+
}
|
|
45
|
+
vectorScores.sort((a, b) => b.score - a.score);
|
|
46
|
+
const topVector = vectorScores.slice(0, 30);
|
|
47
|
+
// RRF fusion
|
|
48
|
+
const rrfScores = new Map();
|
|
49
|
+
for (let rank = 0; rank < ftsResults.length; rank++) {
|
|
50
|
+
const id = ftsResults[rank].id;
|
|
51
|
+
rrfScores.set(id, (rrfScores.get(id) || 0) + 1 / (RRF_K + rank + 1));
|
|
52
|
+
}
|
|
53
|
+
for (let rank = 0; rank < topVector.length; rank++) {
|
|
54
|
+
const id = topVector[rank].memoryId;
|
|
55
|
+
rrfScores.set(id, (rrfScores.get(id) || 0) + 1 / (RRF_K + rank + 1));
|
|
56
|
+
}
|
|
57
|
+
// Score, filter, sort
|
|
58
|
+
const candidates = [];
|
|
59
|
+
for (const [memoryId, rrfScore] of rrfScores) {
|
|
60
|
+
const memory = indexer.memoryStore.getById(memoryId);
|
|
61
|
+
if (!memory)
|
|
62
|
+
continue;
|
|
63
|
+
if (category !== "any" && memory.category !== category)
|
|
64
|
+
continue;
|
|
65
|
+
// Staleness check (lazy)
|
|
66
|
+
const stale = checkStaleness(memory, indexer.fileStore, indexer.memoryStore);
|
|
67
|
+
if (stale && !includeStale)
|
|
68
|
+
continue;
|
|
69
|
+
// Boost by confidence and recency
|
|
70
|
+
const daysSinceAccess = (Date.now() - memory.last_accessed) / 86400000;
|
|
71
|
+
const recencyBoost = 1 / (1 + daysSinceAccess * 0.01);
|
|
72
|
+
const finalScore = rrfScore * memory.confidence * recencyBoost;
|
|
73
|
+
candidates.push({ memory, score: finalScore });
|
|
74
|
+
}
|
|
75
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
76
|
+
const results = candidates.slice(0, limit);
|
|
77
|
+
// Touch access on returned memories
|
|
78
|
+
for (const { memory } of results) {
|
|
79
|
+
indexer.memoryStore.touchAccess(memory.id);
|
|
80
|
+
}
|
|
81
|
+
if (results.length === 0) {
|
|
82
|
+
return "No memories found.";
|
|
83
|
+
}
|
|
84
|
+
// Format
|
|
85
|
+
return results
|
|
86
|
+
.map(({ memory, score }) => {
|
|
87
|
+
const tags = memory.tags ? JSON.parse(memory.tags).join(", ") : "";
|
|
88
|
+
const staleFlag = memory.is_stale ? " [STALE]" : "";
|
|
89
|
+
const git = memory.git_sha
|
|
90
|
+
? `${memory.git_branch || "?"}@${memory.git_sha.slice(0, 7)}`
|
|
91
|
+
: "";
|
|
92
|
+
const age = formatAge(memory.created_at);
|
|
93
|
+
return [
|
|
94
|
+
`### Memory #${memory.id} (${memory.category})${staleFlag}`,
|
|
95
|
+
memory.content,
|
|
96
|
+
`_${age} ago | confidence: ${memory.confidence} | accessed: ${memory.access_count}x${git ? ` | git: ${git}` : ""}${tags ? ` | tags: ${tags}` : ""}_`,
|
|
97
|
+
"",
|
|
98
|
+
].join("\n");
|
|
99
|
+
})
|
|
100
|
+
.join("\n");
|
|
101
|
+
}
|
|
102
|
+
function formatAge(timestamp) {
|
|
103
|
+
const ms = Date.now() - timestamp;
|
|
104
|
+
const mins = Math.floor(ms / 60000);
|
|
105
|
+
if (mins < 60)
|
|
106
|
+
return `${mins}m`;
|
|
107
|
+
const hours = Math.floor(mins / 60);
|
|
108
|
+
if (hours < 24)
|
|
109
|
+
return `${hours}h`;
|
|
110
|
+
const days = Math.floor(hours / 24);
|
|
111
|
+
return `${days}d`;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=recall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.js","sourceRoot":"","sources":["../../../../src/server/tools/recall.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,MAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,WAAW,EACT,oGAAoG;IACtG,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAC9C;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC;gBACrE,WAAW,EAAE,qCAAqC;aACnD;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;YACD,aAAa,EAAE;gBACb,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,yCAAyC;aACvD;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB;CACF,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAgB,EAChB,IAA6B;IAE7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAe,CAAC;IACnC,MAAM,QAAQ,GAAI,IAAI,CAAC,QAAmC,IAAI,KAAK,CAAC;IACpE,MAAM,KAAK,GAAI,IAAI,CAAC,KAAgB,IAAI,EAAE,CAAC;IAC3C,MAA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C,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG;YACpJ,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACf,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB;IAClC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IAClC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;IACpC,IAAI,IAAI,GAAG,EAAE;QAAE,OAAO,GAAG,IAAI,GAAG,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,GAAG,KAAK,GAAG,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,IAAI,GAAG,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Indexer } from "../../indexer/indexer.js";
|
|
2
|
+
export declare const rememberTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: {
|
|
8
|
+
content: {
|
|
9
|
+
type: string;
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
category: {
|
|
13
|
+
type: string;
|
|
14
|
+
enum: string[];
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
tags: {
|
|
18
|
+
type: string;
|
|
19
|
+
items: {
|
|
20
|
+
type: string;
|
|
21
|
+
};
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
related_files: {
|
|
25
|
+
type: string;
|
|
26
|
+
items: {
|
|
27
|
+
type: string;
|
|
28
|
+
};
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
confidence: {
|
|
32
|
+
type: string;
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
required: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare function handleRemember(indexer: Indexer, args: Record<string, unknown>): Promise<string>;
|