@hanhnd/agent-kit 1.0.32 → 1.0.33
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/dist/cli/commands/cli-digest-pending.test.js +111 -0
- package/dist/cli/commands/cli-memory.test.js +34 -0
- package/dist/cli/{memory.js → commands/memory.js} +24 -11
- package/dist/cli/index.js +2 -2
- package/dist/{utils → cli/utils}/args.d.ts +2 -1
- package/dist/{kit-cli.js → cli.js} +342 -58
- package/dist/{tools/config.d.ts → core/config/index.d.ts} +2 -7
- package/dist/{tools/config.js → core/config/index.js} +2 -13
- package/dist/core/handoffs/index.d.ts +16 -0
- package/dist/{tools/handoffs.js → core/handoffs/index.js} +3 -3
- package/dist/{tools/security.d.ts → core/security/index.d.ts} +0 -19
- package/dist/{tools/security.js → core/security/index.js} +3 -76
- package/dist/entrypoints/cli.js +11 -0
- package/dist/entrypoints/server.js +37 -0
- package/dist/{tools → mcp}/agent.js +1 -1
- package/dist/{tools → mcp}/core.d.ts +1 -1
- package/dist/{tools → mcp}/core.js +2 -2
- package/dist/{tools → mcp}/integration.js +3 -3
- package/dist/mcp/memory.d.ts +15 -0
- package/dist/{tools → mcp}/memory.js +15 -13
- package/dist/{kit-server.js → server.js} +80 -70
- package/dist/services/digest/background.d.ts +11 -0
- package/dist/services/digest/background.js +258 -0
- package/dist/{memory → services}/digest/constants.d.ts +4 -1
- package/dist/{memory → services}/digest/constants.js +6 -2
- package/dist/services/digest/digest-background.test.js +206 -0
- package/dist/{tools/__tests__ → services/digest}/digest-init.test.js +4 -3
- package/dist/{memory/__tests__ → services/digest}/digest-llama-local.test.js +1 -13
- package/dist/{memory/__tests__ → services/digest}/digest-pending.test.js +39 -11
- package/dist/{memory/__tests__ → services/digest}/digest-processor.test.js +5 -7
- package/dist/{memory → services}/digest/files.d.ts +0 -1
- package/dist/{memory → services}/digest/files.js +2 -2
- package/dist/services/digest/model-registry.d.ts +2 -0
- package/dist/{memory → services}/digest/model-registry.js +9 -8
- package/dist/services/digest/processor.d.ts +13 -0
- package/dist/{memory → services}/digest/processor.js +48 -31
- package/dist/services/digest/providers/llama-local.d.ts +2 -0
- package/dist/{memory → services}/digest/providers/llama-local.js +3 -4
- package/dist/{memory → services}/digest/types.d.ts +34 -2
- package/dist/services/digest/types.js +6 -0
- package/dist/{memory → services}/digest/worker.d.ts +0 -1
- package/dist/{memory → services}/digest/worker.js +2 -2
- package/dist/{utils → services/integration}/credentials.js +1 -1
- package/dist/{utils/parser.js → services/integration/parser/adf.js} +1 -0
- package/dist/{memory → services/memory}/chunker.d.ts +0 -2
- package/dist/{memory → services/memory}/chunker.js +3 -3
- package/dist/{memory/__tests__ → services/memory}/chunker.test.js +1 -34
- package/dist/{memory → services/memory}/constants.d.ts +1 -1
- package/dist/{memory → services/memory}/constants.js +2 -1
- package/dist/{memory → services/memory}/embedder.d.ts +2 -2
- package/dist/{memory → services/memory}/embedder.js +5 -5
- package/dist/services/memory/embedder.test.js +13 -0
- package/dist/{memory → services/memory}/indexer.d.ts +2 -1
- package/dist/{memory → services/memory}/indexer.js +1 -1
- package/dist/{memory/__tests__ → services/memory}/indexer.test.js +4 -3
- package/dist/{tools/__tests__ → services/memory}/memory.test.js +54 -13
- package/dist/{memory/__tests__ → services/memory}/store.test.js +3 -2
- package/dist/{memory → services/memory}/types.d.ts +7 -2
- package/dist/services/memory/types.js +6 -0
- package/dist/utils/files.d.ts +0 -1
- package/dist/utils/files.js +1 -1
- package/dist/{memory/__tests__/lockfile.test.js → utils/files.test.js} +14 -14
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/json.d.ts +0 -1
- package/dist/utils/json.js +0 -10
- package/dist/utils/paths.d.ts +0 -1
- package/dist/utils/paths.js +1 -1
- package/package.json +6 -6
- package/dist/memory/__tests__/digest-worker.test.js +0 -46
- package/dist/memory/__tests__/embedder.test.js +0 -14
- package/dist/memory/digest/model-registry.d.ts +0 -6
- package/dist/memory/digest/processor.d.ts +0 -7
- package/dist/memory/digest/providers/llama-local.d.ts +0 -7
- package/dist/memory/digest/types.js +0 -1
- package/dist/memory/types.js +0 -1
- package/dist/tools/__tests__/cli-digest-pending.test.js +0 -51
- package/dist/tools/__tests__/cli-memory.test.js +0 -22
- package/dist/tools/handoffs.d.ts +0 -22
- package/dist/tools/memory.d.ts +0 -16
- /package/dist/{tools/__tests__ → cli/commands}/cli-digest-pending.test.d.ts +0 -0
- /package/dist/{tools/__tests__ → cli/commands}/cli-memory.test.d.ts +0 -0
- /package/dist/cli/{memory.d.ts → commands/memory.d.ts} +0 -0
- /package/dist/{utils → cli/utils}/args.js +0 -0
- /package/dist/{kit-cli.d.ts → entrypoints/cli.d.ts} +0 -0
- /package/dist/{kit-server.d.ts → entrypoints/server.d.ts} +0 -0
- /package/dist/{tools → mcp}/agent.d.ts +0 -0
- /package/dist/{tools → mcp}/integration.d.ts +0 -0
- /package/dist/{memory/__tests__/chunker.test.d.ts → services/digest/digest-background.test.d.ts} +0 -0
- /package/dist/{tools/__tests__ → services/digest}/digest-init.test.d.ts +0 -0
- /package/dist/{memory/__tests__ → services/digest}/digest-llama-local.test.d.ts +0 -0
- /package/dist/{memory/__tests__ → services/digest}/digest-pending.test.d.ts +0 -0
- /package/dist/{memory/__tests__ → services/digest}/digest-processor.test.d.ts +0 -0
- /package/dist/{utils → services/integration}/credentials.d.ts +0 -0
- /package/dist/{utils/parser.d.ts → services/integration/parser/adf.d.ts} +0 -0
- /package/dist/{memory/__tests__/digest-worker.test.d.ts → services/memory/chunker.test.d.ts} +0 -0
- /package/dist/{memory/__tests__ → services/memory}/embedder.test.d.ts +0 -0
- /package/dist/{memory → services/memory}/index.d.ts +0 -0
- /package/dist/{memory → services/memory}/index.js +0 -0
- /package/dist/{memory/__tests__ → services/memory}/indexer.test.d.ts +0 -0
- /package/dist/{tools/__tests__ → services/memory}/memory.test.d.ts +0 -0
- /package/dist/{memory → services/memory}/store.d.ts +0 -0
- /package/dist/{memory → services/memory}/store.js +0 -0
- /package/dist/{memory/__tests__ → services/memory}/store.test.d.ts +0 -0
- /package/dist/{memory/__tests__/lockfile.test.d.ts → utils/files.test.d.ts} +0 -0
- /package/dist/{__tests__/temp-dir.d.ts → utils/temp-dir.test.d.ts} +0 -0
- /package/dist/{__tests__/temp-dir.js → utils/temp-dir.test.js} +0 -0
|
@@ -12,7 +12,7 @@ const TICKET_ID_PATTERN = /\b[A-Z][A-Z0-9]+-\d+\b/;
|
|
|
12
12
|
function findTicketId(value) {
|
|
13
13
|
return value.match(TICKET_ID_PATTERN)?.[0].toLowerCase() ?? null;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
function sanitizeFeatureSlug(value) {
|
|
16
16
|
return value
|
|
17
17
|
.replace(/[^a-zA-Z0-9-_]/g, '-')
|
|
18
18
|
.replace(/-+/g, '-')
|
|
@@ -26,13 +26,13 @@ function contentSlugCandidate(content) {
|
|
|
26
26
|
.find((line) => line.length > 0);
|
|
27
27
|
return heading ?? content.replace(/\s+/g, ' ').trim().slice(0, 80);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
function normalizeHandoffType(type) {
|
|
30
30
|
if (!HANDOFF_TYPES.includes(type)) {
|
|
31
31
|
throw new Error(`Unsupported handoff type: ${type}`);
|
|
32
32
|
}
|
|
33
33
|
return type;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
function deriveFeatureSlug(input) {
|
|
36
36
|
const requestedTicketSlug = findTicketId(input.requestedSlug);
|
|
37
37
|
if (requestedTicketSlug)
|
|
38
38
|
return requestedTicketSlug;
|
|
@@ -18,26 +18,7 @@ export declare function sanitize(input: string): string;
|
|
|
18
18
|
* Uses stricter path.sep check to prevent prefix matching flaws.
|
|
19
19
|
*/
|
|
20
20
|
export declare function validatePath(filePath: string, baseDir?: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Safe git command execution using execFileSync
|
|
23
|
-
* Includes stderr in error message for better debugging
|
|
24
|
-
*
|
|
25
|
-
* @param timeout Default from GEMINI_KIT_GIT_TIMEOUT env var or 30s
|
|
26
|
-
*/
|
|
27
|
-
export declare function safeGit(args: string[], options?: {
|
|
28
|
-
timeout?: number;
|
|
29
|
-
cwd?: string;
|
|
30
|
-
}): string;
|
|
31
|
-
/**
|
|
32
|
-
* Check if a command exists (cross-platform)
|
|
33
|
-
* Uses 'where' on Windows, 'which' on macOS/Linux
|
|
34
|
-
*/
|
|
35
21
|
export declare function commandExists(cmd: string): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Async file finder - non-blocking for large repos
|
|
38
|
-
* Uses queue-based approach to prevent stack overflow on deep directories
|
|
39
|
-
*/
|
|
40
|
-
export declare function findFilesAsync(dir: string, extensions: string[], maxFiles: number, excludeDirs?: string[]): Promise<string[]>;
|
|
41
22
|
/**
|
|
42
23
|
* Sanitize output text by redacting sensitive tokens (API keys, etc.)
|
|
43
24
|
*/
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
* Exported utilities for safe command execution
|
|
4
4
|
*/
|
|
5
5
|
import { execFileSync } from 'child_process';
|
|
6
|
-
import * as fs from 'fs';
|
|
7
6
|
import * as path from 'path';
|
|
8
|
-
import { getWorkspaceRoot } from '
|
|
9
|
-
import { FORBIDDEN_DIRS, FORBIDDEN_FILES, FORBIDDEN_PATTERNS } from '
|
|
7
|
+
import { getWorkspaceRoot } from '../../utils/utils.js';
|
|
8
|
+
import { FORBIDDEN_DIRS, FORBIDDEN_FILES, FORBIDDEN_PATTERNS } from '../config/index.js';
|
|
10
9
|
/**
|
|
11
10
|
* Sanitize string for safe use with execFileSync
|
|
12
11
|
* Only removes dangerous shell operators - safe chars like !?#* are allowed
|
|
@@ -52,42 +51,6 @@ export function validatePath(filePath, baseDir = process.cwd()) {
|
|
|
52
51
|
}
|
|
53
52
|
return resolved;
|
|
54
53
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Extract stderr from error for better logging
|
|
57
|
-
*/
|
|
58
|
-
function extractStderr(error) {
|
|
59
|
-
if (error && typeof error === 'object' && 'stderr' in error) {
|
|
60
|
-
return String(error.stderr);
|
|
61
|
-
}
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
64
|
-
// Configurable timeouts via environment variables
|
|
65
|
-
const GIT_TIMEOUT = parseInt(process.env.GEMINI_KIT_GIT_TIMEOUT || '30000', 10);
|
|
66
|
-
/**
|
|
67
|
-
* Safe git command execution using execFileSync
|
|
68
|
-
* Includes stderr in error message for better debugging
|
|
69
|
-
*
|
|
70
|
-
* @param timeout Default from GEMINI_KIT_GIT_TIMEOUT env var or 30s
|
|
71
|
-
*/
|
|
72
|
-
export function safeGit(args, options) {
|
|
73
|
-
try {
|
|
74
|
-
return execFileSync('git', args, {
|
|
75
|
-
encoding: 'utf8',
|
|
76
|
-
timeout: options?.timeout || GIT_TIMEOUT,
|
|
77
|
-
cwd: options?.cwd || getWorkspaceRoot(),
|
|
78
|
-
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
const stderr = extractStderr(error);
|
|
83
|
-
const baseMsg = error instanceof Error ? error.message : String(error);
|
|
84
|
-
throw new Error(`Git command failed: ${baseMsg}${stderr ? `\nDetails: ${stderr}` : ''}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check if a command exists (cross-platform)
|
|
89
|
-
* Uses 'where' on Windows, 'which' on macOS/Linux
|
|
90
|
-
*/
|
|
91
54
|
export function commandExists(cmd) {
|
|
92
55
|
try {
|
|
93
56
|
const checkCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
@@ -103,42 +66,6 @@ export function commandExists(cmd) {
|
|
|
103
66
|
return false;
|
|
104
67
|
}
|
|
105
68
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Async file finder - non-blocking for large repos
|
|
108
|
-
* Uses queue-based approach to prevent stack overflow on deep directories
|
|
109
|
-
*/
|
|
110
|
-
export async function findFilesAsync(dir, extensions, maxFiles, excludeDirs = ['node_modules', '.git', 'dist', 'build', 'coverage']) {
|
|
111
|
-
const results = [];
|
|
112
|
-
// Use queue instead of recursion to prevent stack overflow
|
|
113
|
-
const queue = [{ fullPath: dir, relativePath: '' }];
|
|
114
|
-
while (queue.length > 0 && results.length < maxFiles) {
|
|
115
|
-
const current = queue.shift();
|
|
116
|
-
let entries;
|
|
117
|
-
try {
|
|
118
|
-
entries = await fs.promises.readdir(current.fullPath, { withFileTypes: true });
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
continue; // Skip directories we can't read
|
|
122
|
-
}
|
|
123
|
-
for (const entry of entries) {
|
|
124
|
-
if (results.length >= maxFiles)
|
|
125
|
-
break;
|
|
126
|
-
const entryFullPath = path.join(current.fullPath, entry.name);
|
|
127
|
-
const entryRelPath = current.relativePath ? path.join(current.relativePath, entry.name) : entry.name;
|
|
128
|
-
if (entry.isDirectory()) {
|
|
129
|
-
if (!excludeDirs.includes(entry.name)) {
|
|
130
|
-
queue.push({ fullPath: entryFullPath, relativePath: entryRelPath });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (entry.isFile()) {
|
|
134
|
-
if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
135
|
-
results.push(entryRelPath);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return results;
|
|
141
|
-
}
|
|
142
69
|
/**
|
|
143
70
|
* Sanitize output text by redacting sensitive tokens (API keys, etc.)
|
|
144
71
|
*/
|
|
@@ -148,7 +75,7 @@ export function sanitizeOutput(text) {
|
|
|
148
75
|
/SK-[A-Za-z0-9]{40,}/g, // OpenAI keys
|
|
149
76
|
/AKIA[0-9A-Z]{16}/g, // AWS access keys
|
|
150
77
|
/xox[baprs]-[A-Za-z0-9-]{10,}/g, // Slack tokens
|
|
151
|
-
/[Aa]tlassian[_
|
|
78
|
+
/[Aa]tlassian[_-]?[Aa][Pp][Ii][_-]?[Tt]oken[^\s]*\s*[:=]\s*\S+/g, // Atlassian token patterns
|
|
152
79
|
];
|
|
153
80
|
let sanitized = text;
|
|
154
81
|
for (const pattern of SECRET_PATTERNS) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { runAgentKitCli } from '../cli/index.js';
|
|
3
|
+
try {
|
|
4
|
+
const exitCode = await runAgentKitCli(process.argv.slice(2), process.env);
|
|
5
|
+
process.exit(exitCode);
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
9
|
+
process.stderr.write('[agent-kit] CLI error: ' + message + '\n');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Agent-Kit MCP Server
|
|
4
|
+
* Provides custom tools for agent orchestration
|
|
5
|
+
*
|
|
6
|
+
* Modular architecture - tools split into separate modules
|
|
7
|
+
*/
|
|
8
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
9
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
10
|
+
import { registerCoreTools } from '../mcp/core.js';
|
|
11
|
+
import { registerAgentTools } from '../mcp/agent.js';
|
|
12
|
+
import { registerIntegrationTools } from '../mcp/integration.js';
|
|
13
|
+
import { loadProjectSettings } from '../core/config/index.js';
|
|
14
|
+
import { registerMemoryTools } from '../mcp/memory.js';
|
|
15
|
+
import { getWorkspaceRoot } from '../utils/utils.js';
|
|
16
|
+
const server = new McpServer({
|
|
17
|
+
name: 'kit-agents',
|
|
18
|
+
version: '1.0.0',
|
|
19
|
+
});
|
|
20
|
+
// ═══════════════════════════════════════════════════════════════
|
|
21
|
+
// REGISTER MODULAR TOOLS
|
|
22
|
+
// ═══════════════════════════════════════════════════════════════
|
|
23
|
+
registerIntegrationTools(server);
|
|
24
|
+
registerCoreTools(server);
|
|
25
|
+
registerAgentTools(server);
|
|
26
|
+
const workspaceRoot = getWorkspaceRoot();
|
|
27
|
+
const settings = loadProjectSettings(workspaceRoot);
|
|
28
|
+
const memoryIndexer = registerMemoryTools(server, settings, workspaceRoot);
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════
|
|
30
|
+
// START SERVER
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════
|
|
32
|
+
const transport = new StdioServerTransport();
|
|
33
|
+
await server.connect(transport);
|
|
34
|
+
// Fire-and-forget startup indexing — must run after server.connect
|
|
35
|
+
if (memoryIndexer) {
|
|
36
|
+
void memoryIndexer.startupIndex();
|
|
37
|
+
}
|
|
@@ -8,7 +8,7 @@ import * as fs from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
import { getWorkspaceRoot, mcpJson, mcpText } from '../utils/utils.js';
|
|
11
|
-
import { commandExists, sanitizeOutput, validatePath } from '
|
|
11
|
+
import { commandExists, sanitizeOutput, validatePath } from '../core/security/index.js';
|
|
12
12
|
// Configurable timeout via environment variable (default: 5 minutes)
|
|
13
13
|
const AGENT_TIMEOUT = parseInt(process.env.KIT_AGENT_TIMEOUT || '300000', 10);
|
|
14
14
|
const jobRegistry = new Map();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Core Tools - Extension info and handoff persistence
|
|
3
3
|
*/
|
|
4
4
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
-
import { DEFAULT_EXTENSIONS } from '
|
|
5
|
+
import { DEFAULT_EXTENSIONS } from '../core/config/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* Register core tools with MCP server
|
|
8
8
|
*/
|
|
@@ -5,8 +5,8 @@ import * as fs from 'fs';
|
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { getWorkspaceRoot, mcpText } from '../utils/utils.js';
|
|
8
|
-
import { DEFAULT_EXTENSIONS } from '
|
|
9
|
-
import { HANDOFF_TYPES, resolveHandoffPath } from '
|
|
8
|
+
import { DEFAULT_EXTENSIONS } from '../core/config/index.js';
|
|
9
|
+
import { HANDOFF_TYPES, resolveHandoffPath } from '../core/handoffs/index.js';
|
|
10
10
|
/**
|
|
11
11
|
* Register core tools with MCP server
|
|
12
12
|
*/
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { writeFileSync } from 'fs';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { getCredential } from '../
|
|
7
|
+
import { getCredential } from '../services/integration/credentials.js';
|
|
8
8
|
import { mcpText } from '../utils/utils.js';
|
|
9
|
-
import { adfToMarkdown } from '../
|
|
10
|
-
import { sanitize } from '
|
|
9
|
+
import { adfToMarkdown } from '../services/integration/parser/adf.js';
|
|
10
|
+
import { sanitize } from '../core/security/index.js';
|
|
11
11
|
// Zod schema for Bitbucket PR REST API response
|
|
12
12
|
const BitbucketPrSchema = z.object({
|
|
13
13
|
id: z.number(),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { MemoryIndexer } from '../services/memory/indexer.js';
|
|
3
|
+
import { MemoryStore } from '../services/memory/store.js';
|
|
4
|
+
import type { MemoryConfig } from '../services/memory/types.js';
|
|
5
|
+
import { type ProjectSettings } from '../core/config/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the memory subsystem and registers all memory tools.
|
|
8
|
+
* Returns the MemoryIndexer so the caller can fire startupIndex() after server.connect().
|
|
9
|
+
* Returns null when memory is disabled (settings.memory.enabled !== true).
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerMemoryTools(server: McpServer, settings: ProjectSettings, workspaceRoot: string, overrides?: {
|
|
12
|
+
indexer?: MemoryIndexer;
|
|
13
|
+
store?: MemoryStore;
|
|
14
|
+
config?: MemoryConfig;
|
|
15
|
+
}): MemoryIndexer | null;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Embedder } from '../memory/embedder.js';
|
|
4
|
-
import { MemoryIndexer } from '../memory/indexer.js';
|
|
5
|
-
import { MemoryStore } from '../memory/store.js';
|
|
6
|
-
import { initializeConversationDigestModel } from '../
|
|
7
|
-
import { DEFAULT_DIGEST_MODEL_ID } from '../
|
|
3
|
+
import { Embedder } from '../services/memory/embedder.js';
|
|
4
|
+
import { MemoryIndexer } from '../services/memory/indexer.js';
|
|
5
|
+
import { MemoryStore } from '../services/memory/store.js';
|
|
6
|
+
import { initializeConversationDigestModel } from '../services/digest/processor.js';
|
|
7
|
+
import { DEFAULT_DIGEST_MODEL_ID } from '../services/digest/constants.js';
|
|
8
8
|
import { mcpJson, mcpText } from '../utils/utils.js';
|
|
9
|
-
import { loadProjectSettings, resolveConversationDigestConfig, resolveMemoryConfig, } from '
|
|
9
|
+
import { loadProjectSettings, resolveConversationDigestConfig, resolveMemoryConfig, } from '../core/config/index.js';
|
|
10
10
|
/**
|
|
11
11
|
* Registers tool handlers onto an already-constructed indexer/store pair.
|
|
12
|
-
* Exported for unit testing with mocks.
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
function registerMemoryToolHandlers(server, indexer, store, config, workspaceRoot = process.cwd()) {
|
|
15
14
|
server.tool('kit_memory_search', 'Search persistent memory for context relevant to the current question. Returns semantically relevant results using hybrid dense+BM25+RRF search.', {
|
|
16
15
|
query: z.string().min(1).describe('Search query'),
|
|
17
16
|
top_k: z.number().int().positive().optional().describe('Number of results to return'),
|
|
@@ -89,13 +88,16 @@ export function registerMemoryToolHandlers(server, indexer, store, config, works
|
|
|
89
88
|
* Returns the MemoryIndexer so the caller can fire startupIndex() after server.connect().
|
|
90
89
|
* Returns null when memory is disabled (settings.memory.enabled !== true).
|
|
91
90
|
*/
|
|
92
|
-
export function registerMemoryTools(server, settings, workspaceRoot) {
|
|
91
|
+
export function registerMemoryTools(server, settings, workspaceRoot, overrides) {
|
|
93
92
|
if (settings.memory?.enabled !== true)
|
|
94
93
|
return null;
|
|
95
|
-
const config = resolveMemoryConfig(settings, workspaceRoot);
|
|
96
|
-
const store = new MemoryStore(path.join(config.wikiDir, 'index.db'), config);
|
|
97
|
-
const
|
|
98
|
-
|
|
94
|
+
const config = overrides?.config ?? resolveMemoryConfig(settings, workspaceRoot);
|
|
95
|
+
const store = overrides?.store ?? new MemoryStore(path.join(config.wikiDir, 'index.db'), config);
|
|
96
|
+
const indexer = overrides?.indexer ??
|
|
97
|
+
(() => {
|
|
98
|
+
const embedder = new Embedder(config.embeddingModel);
|
|
99
|
+
return new MemoryIndexer(store, embedder, config);
|
|
100
|
+
})();
|
|
99
101
|
registerMemoryToolHandlers(server, indexer, store, config, workspaceRoot);
|
|
100
102
|
return indexer;
|
|
101
103
|
}
|