stellavault 0.4.0 → 0.4.1

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.
@@ -0,0 +1,34 @@
1
+ import type { SearchEngine } from '../../search/index.js';
2
+ export declare function createGenerateDraftTool(searchEngine: SearchEngine, vaultPath: string): {
3
+ name: string;
4
+ description: string;
5
+ inputSchema: {
6
+ type: "object";
7
+ properties: {
8
+ topic: {
9
+ type: string;
10
+ description: string;
11
+ };
12
+ format: {
13
+ type: string;
14
+ enum: string[];
15
+ description: string;
16
+ };
17
+ maxSources: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ };
22
+ };
23
+ handler: (args: {
24
+ topic?: string;
25
+ format?: string;
26
+ maxSources?: number;
27
+ }) => Promise<{
28
+ content: {
29
+ type: "text";
30
+ text: string;
31
+ }[];
32
+ }>;
33
+ };
34
+ //# sourceMappingURL=generate-draft.d.ts.map
@@ -0,0 +1,120 @@
1
+ // MCP Tool: generate-draft — Claude Code에서 직접 초안 생성
2
+ // Claude가 vault 컨텍스트를 받아 직접 글을 쓰도록 구조화된 재료를 반환
3
+ // 비용: $0 (이미 Claude Code 세션 안)
4
+ import { scanRawDirectory, extractConcepts } from '../../intelligence/wiki-compiler.js';
5
+ import { loadConfig, DEFAULT_FOLDERS } from '../../config.js';
6
+ import { resolve } from 'node:path';
7
+ import { existsSync } from 'node:fs';
8
+ export function createGenerateDraftTool(searchEngine, vaultPath) {
9
+ return {
10
+ name: 'generate-draft',
11
+ description: 'Gather knowledge from your vault to write a draft. Returns structured context (notes, concepts, excerpts) so you can compose a blog post, report, or outline. Use this when the user asks you to "write a draft", "blog post from my notes", or "summarize my knowledge about X".',
12
+ inputSchema: {
13
+ type: 'object',
14
+ properties: {
15
+ topic: {
16
+ type: 'string',
17
+ description: 'Topic or keyword to focus on. Leave empty for all knowledge.',
18
+ },
19
+ format: {
20
+ type: 'string',
21
+ enum: ['blog', 'report', 'outline'],
22
+ description: 'Desired output format (default: blog)',
23
+ },
24
+ maxSources: {
25
+ type: 'number',
26
+ description: 'Maximum number of source documents to include (default: 10)',
27
+ },
28
+ },
29
+ },
30
+ handler: async (args) => {
31
+ const { topic, format = 'blog', maxSources = 10 } = args;
32
+ const config = loadConfig();
33
+ const folders = config.folders ?? DEFAULT_FOLDERS;
34
+ // 1. 토픽 기반 검색 (있으면)
35
+ let searchResults = [];
36
+ if (topic) {
37
+ const results = await searchEngine.search({ query: topic, limit: maxSources });
38
+ searchResults = results.map(r => ({
39
+ title: r.document?.title ?? 'Untitled',
40
+ content: r.chunk?.content ?? '',
41
+ filePath: r.document?.filePath ?? '',
42
+ score: r.score ?? 0,
43
+ }));
44
+ }
45
+ // 2. vault 전체 스캔 (검색 결과가 부족하면)
46
+ const allDocs = [];
47
+ for (const dir of [folders.fleeting, folders.literature, folders.permanent, folders.wiki]) {
48
+ const fullDir = resolve(vaultPath, dir);
49
+ if (existsSync(fullDir)) {
50
+ const docs = scanRawDirectory(fullDir);
51
+ allDocs.push(...docs);
52
+ }
53
+ }
54
+ // 토픽 필터
55
+ const relevantDocs = topic
56
+ ? allDocs.filter(d => d.title.toLowerCase().includes(topic.toLowerCase()) ||
57
+ d.tags.some(t => t.toLowerCase().includes(topic.toLowerCase())) ||
58
+ d.content.toLowerCase().includes(topic.toLowerCase()))
59
+ : allDocs;
60
+ // 3. 개념 추출
61
+ const concepts = extractConcepts(relevantDocs.length > 0 ? relevantDocs : allDocs);
62
+ const topConcepts = [...concepts.entries()]
63
+ .sort((a, b) => b[1].length - a[1].length)
64
+ .slice(0, 8)
65
+ .map(([name, docs]) => ({ name, documentCount: docs.length }));
66
+ // 4. 발췌 준비
67
+ const excerpts = (searchResults.length > 0 ? searchResults : relevantDocs.slice(0, maxSources))
68
+ .map(doc => {
69
+ const body = doc.content
70
+ .replace(/^---[\s\S]*?---\n?/, '') // frontmatter 제거
71
+ .replace(/^#+\s+.+\n/m, '') // 첫 heading 제거
72
+ .trim()
73
+ .slice(0, 500);
74
+ return {
75
+ title: doc.title,
76
+ excerpt: body,
77
+ filePath: doc.filePath,
78
+ };
79
+ })
80
+ .filter(e => e.excerpt.length > 20);
81
+ // 5. 구조화된 컨텍스트 반환
82
+ const context = {
83
+ topic: topic ?? 'All Knowledge',
84
+ format,
85
+ totalDocuments: relevantDocs.length || allDocs.length,
86
+ concepts: topConcepts,
87
+ sources: excerpts,
88
+ instruction: `Use the sources above to write a ${format}. Rules:
89
+ - Only use information from the provided sources
90
+ - Cite sources using [[title]] wikilink format
91
+ - Write in the same language as the source material
92
+ - Add your analysis connecting ideas across sources
93
+ - Format: ${format === 'blog' ? 'Engaging blog post with intro, body sections, conclusion' : format === 'report' ? 'Formal report with executive summary, sections, conclusion' : 'Hierarchical outline with numbered sections'}`,
94
+ };
95
+ const text = `# Draft Context: ${context.topic}
96
+
97
+ ## Format: ${format}
98
+ ## Sources: ${context.totalDocuments} documents, ${excerpts.length} excerpts
99
+
100
+ ## Key Concepts
101
+ ${topConcepts.map(c => `- **${c.name}** (${c.documentCount} documents)`).join('\n')}
102
+
103
+ ## Source Excerpts
104
+
105
+ ${excerpts.map(e => `### ${e.title}
106
+ > ${e.excerpt}
107
+ `).join('\n')}
108
+
109
+ ## Instructions
110
+ ${context.instruction}
111
+
112
+ ---
113
+ Please write the ${format} draft based on the context above. Save the result to the vault's _drafts/ folder.`;
114
+ return {
115
+ content: [{ type: 'text', text }],
116
+ };
117
+ },
118
+ };
119
+ }
120
+ //# sourceMappingURL=generate-draft.js.map
@@ -13,6 +13,14 @@
13
13
  "./intelligence/youtube-extractor": {
14
14
  "import": "./dist/intelligence/youtube-extractor.js",
15
15
  "types": "./dist/intelligence/youtube-extractor.d.ts"
16
+ },
17
+ "./intelligence/file-extractors": {
18
+ "import": "./dist/intelligence/file-extractors.js",
19
+ "types": "./dist/intelligence/file-extractors.d.ts"
20
+ },
21
+ "./intelligence/draft-generator": {
22
+ "import": "./dist/intelligence/draft-generator.js",
23
+ "types": "./dist/intelligence/draft-generator.d.ts"
16
24
  }
17
25
  },
18
26
  "scripts": {
@@ -30,7 +38,9 @@
30
38
  "vitest": "^3.0.0"
31
39
  },
32
40
  "dependencies": {
41
+ "@anthropic-ai/sdk": "^0.82.0",
33
42
  "@modelcontextprotocol/sdk": "^1.28.0",
43
+ "@types/multer": "^2.1.0",
34
44
  "@xenova/transformers": "^2.17.2",
35
45
  "b4a": "^1.8.0",
36
46
  "better-sqlite3": "^12.8.0",
@@ -39,6 +49,11 @@
39
49
  "express": "^5.2.1",
40
50
  "gray-matter": "^4.0.3",
41
51
  "hyperswarm": "^4.17.0",
42
- "sqlite-vec": "^0.1.7"
52
+ "mammoth": "^1.12.0",
53
+ "multer": "^2.1.1",
54
+ "officeparser": "^6.0.7",
55
+ "sqlite-vec": "^0.1.7",
56
+ "unpdf": "^1.4.0",
57
+ "xlsx": "^0.18.5"
43
58
  }
44
59
  }
Binary file