Skip to content

Commit 1e69f79

Browse files
committed
Fix: hanging when query memory
1 parent 134d0d4 commit 1e69f79

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

packages/cli/src/commands/skill.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function registerSkillCommand(program: Command): void {
3737
if (skills.length === 0) {
3838
ui.warning('No skills installed in this project.');
3939
ui.info('Install a skill with: ai-devkit skill add <registry>/<repo> <skill-name>');
40-
process.exit(0);
40+
return;
4141
}
4242

4343
ui.text('Installed Skills:', { breakline: true });
@@ -53,7 +53,6 @@ export function registerSkillCommand(program: Command): void {
5353
});
5454

5555
ui.text(`Total: ${skills.length} skill(s)`, { breakline: true });
56-
process.exit(0);
5756
} catch (error: any) {
5857
ui.error(`Failed to list skills: ${error.message}`);
5958
process.exit(1);

packages/memory/src/api.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { storeKnowledge } from './handlers/store';
22
import { searchKnowledge } from './handlers/search';
3+
import { closeDatabase } from './database';
34
import type { StoreKnowledgeInput, SearchKnowledgeInput, StoreKnowledgeResult, SearchKnowledgeResult } from './types';
45

56
export { storeKnowledge, searchKnowledge };
@@ -21,23 +22,31 @@ export interface MemorySearchOptions {
2122
}
2223

2324
export function memoryStoreCommand(options: MemoryStoreOptions): StoreKnowledgeResult {
24-
const input: StoreKnowledgeInput = {
25-
title: options.title,
26-
content: options.content,
27-
tags: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
28-
scope: options.scope,
29-
};
25+
try {
26+
const input: StoreKnowledgeInput = {
27+
title: options.title,
28+
content: options.content,
29+
tags: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
30+
scope: options.scope,
31+
};
3032

31-
return storeKnowledge(input);
33+
return storeKnowledge(input);
34+
} finally {
35+
closeDatabase();
36+
}
3237
}
3338

3439
export function memorySearchCommand(options: MemorySearchOptions): SearchKnowledgeResult {
35-
const input: SearchKnowledgeInput = {
36-
query: options.query,
37-
contextTags: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
38-
scope: options.scope,
39-
limit: options.limit,
40-
};
40+
try {
41+
const input: SearchKnowledgeInput = {
42+
query: options.query,
43+
contextTags: options.tags ? options.tags.split(',').map(t => t.trim()) : undefined,
44+
scope: options.scope,
45+
limit: options.limit,
46+
};
4147

42-
return searchKnowledge(input);
48+
return searchKnowledge(input);
49+
} finally {
50+
closeDatabase();
51+
}
4352
}

packages/memory/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { runServer } from './server';
44

55
export * from './api';
66

7-
runServer().catch((error: Error) => {
8-
console.error('Failed to start server:', error);
9-
process.exit(1);
10-
});
7+
// Only start MCP server when this file is run directly as a binary
8+
// Not when imported as a library (e.g., by CLI commands)
9+
if (require.main === module) {
10+
runServer().catch((error: Error) => {
11+
console.error('Failed to start server:', error);
12+
process.exit(1);
13+
});
14+
}

0 commit comments

Comments
 (0)