midnight-mcp 0.1.40 → 0.2.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.
Files changed (100) hide show
  1. package/README.md +34 -0
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +10764 -0
  4. package/dist/index.d.ts +205 -3
  5. package/dist/index.js +10722 -15
  6. package/package.json +16 -6
  7. package/dist/config/compact-version.d.ts +0 -183
  8. package/dist/config/compact-version.js +0 -423
  9. package/dist/db/index.d.ts +0 -3
  10. package/dist/db/index.js +0 -2
  11. package/dist/db/vectorStore.d.ts +0 -69
  12. package/dist/db/vectorStore.js +0 -196
  13. package/dist/pipeline/embeddings.d.ts +0 -25
  14. package/dist/pipeline/embeddings.js +0 -103
  15. package/dist/pipeline/github.d.ts +0 -84
  16. package/dist/pipeline/github.js +0 -399
  17. package/dist/pipeline/index.d.ts +0 -11
  18. package/dist/pipeline/index.js +0 -6
  19. package/dist/pipeline/indexer.d.ts +0 -41
  20. package/dist/pipeline/indexer.js +0 -254
  21. package/dist/pipeline/parser.d.ts +0 -46
  22. package/dist/pipeline/parser.js +0 -436
  23. package/dist/pipeline/releases.d.ts +0 -112
  24. package/dist/pipeline/releases.js +0 -298
  25. package/dist/pipeline/repository.d.ts +0 -372
  26. package/dist/pipeline/repository.js +0 -520
  27. package/dist/prompts/index.d.ts +0 -3
  28. package/dist/prompts/index.js +0 -2
  29. package/dist/prompts/templates.d.ts +0 -26
  30. package/dist/prompts/templates.js +0 -443
  31. package/dist/resources/code.d.ts +0 -15
  32. package/dist/resources/code.js +0 -122
  33. package/dist/resources/content/code-content.d.ts +0 -6
  34. package/dist/resources/content/code-content.js +0 -802
  35. package/dist/resources/content/docs-content.d.ts +0 -14
  36. package/dist/resources/content/docs-content.js +0 -1202
  37. package/dist/resources/content/index.d.ts +0 -6
  38. package/dist/resources/content/index.js +0 -6
  39. package/dist/resources/docs.d.ts +0 -15
  40. package/dist/resources/docs.js +0 -98
  41. package/dist/resources/index.d.ts +0 -6
  42. package/dist/resources/index.js +0 -13
  43. package/dist/resources/schemas.d.ts +0 -16
  44. package/dist/resources/schemas.js +0 -407
  45. package/dist/scripts/index-repos.d.ts +0 -12
  46. package/dist/scripts/index-repos.js +0 -53
  47. package/dist/server.d.ts +0 -43
  48. package/dist/server.js +0 -693
  49. package/dist/services/index.d.ts +0 -6
  50. package/dist/services/index.js +0 -6
  51. package/dist/services/sampling.d.ts +0 -62
  52. package/dist/services/sampling.js +0 -277
  53. package/dist/tools/analyze.d.ts +0 -106
  54. package/dist/tools/analyze.js +0 -431
  55. package/dist/tools/generation.d.ts +0 -9
  56. package/dist/tools/generation.js +0 -285
  57. package/dist/tools/health.d.ts +0 -120
  58. package/dist/tools/health.js +0 -362
  59. package/dist/tools/index.d.ts +0 -14
  60. package/dist/tools/index.js +0 -22
  61. package/dist/tools/meta.d.ts +0 -61
  62. package/dist/tools/meta.js +0 -282
  63. package/dist/tools/repository/constants.d.ts +0 -19
  64. package/dist/tools/repository/constants.js +0 -324
  65. package/dist/tools/repository/handlers.d.ts +0 -373
  66. package/dist/tools/repository/handlers.js +0 -724
  67. package/dist/tools/repository/index.d.ts +0 -9
  68. package/dist/tools/repository/index.js +0 -13
  69. package/dist/tools/repository/schemas.d.ts +0 -153
  70. package/dist/tools/repository/schemas.js +0 -106
  71. package/dist/tools/repository/tools.d.ts +0 -7
  72. package/dist/tools/repository/tools.js +0 -484
  73. package/dist/tools/repository/validation.d.ts +0 -106
  74. package/dist/tools/repository/validation.js +0 -820
  75. package/dist/tools/repository.d.ts +0 -6
  76. package/dist/tools/repository.js +0 -7
  77. package/dist/tools/search.d.ts +0 -76
  78. package/dist/tools/search.js +0 -423
  79. package/dist/types/index.d.ts +0 -2
  80. package/dist/types/index.js +0 -2
  81. package/dist/types/mcp.d.ts +0 -187
  82. package/dist/types/mcp.js +0 -6
  83. package/dist/utils/cache.d.ts +0 -77
  84. package/dist/utils/cache.js +0 -172
  85. package/dist/utils/config.d.ts +0 -70
  86. package/dist/utils/config.js +0 -294
  87. package/dist/utils/errors.d.ts +0 -111
  88. package/dist/utils/errors.js +0 -165
  89. package/dist/utils/health.d.ts +0 -29
  90. package/dist/utils/health.js +0 -132
  91. package/dist/utils/hosted-api.d.ts +0 -67
  92. package/dist/utils/hosted-api.js +0 -119
  93. package/dist/utils/index.d.ts +0 -16
  94. package/dist/utils/index.js +0 -15
  95. package/dist/utils/logger.d.ts +0 -48
  96. package/dist/utils/logger.js +0 -124
  97. package/dist/utils/rate-limit.d.ts +0 -61
  98. package/dist/utils/rate-limit.js +0 -148
  99. package/dist/utils/validation.d.ts +0 -52
  100. package/dist/utils/validation.js +0 -255
@@ -1,69 +0,0 @@
1
- export interface CodeDocument {
2
- id: string;
3
- content: string;
4
- embedding?: number[];
5
- metadata: {
6
- repository: string;
7
- filePath: string;
8
- language: string;
9
- startLine: number;
10
- endLine: number;
11
- codeType: string;
12
- codeName: string;
13
- isPublic: boolean;
14
- repoVersion?: string;
15
- pragmaVersion?: string;
16
- indexedAt?: string;
17
- };
18
- }
19
- export interface SearchResult {
20
- id: string;
21
- content: string;
22
- score: number;
23
- metadata: CodeDocument["metadata"];
24
- }
25
- export interface SearchFilter {
26
- repository?: string;
27
- language?: string;
28
- codeType?: string;
29
- isPublic?: boolean;
30
- }
31
- declare class VectorStore {
32
- private client;
33
- private collection;
34
- private collectionName;
35
- private initialized;
36
- /**
37
- * Initialize the vector store connection
38
- */
39
- initialize(): Promise<void>;
40
- /**
41
- * Add documents to the vector store
42
- */
43
- addDocuments(documents: CodeDocument[]): Promise<void>;
44
- /**
45
- * Search for similar documents
46
- */
47
- search(query: string, limit?: number, filter?: SearchFilter): Promise<SearchResult[]>;
48
- /**
49
- * Delete documents by file path
50
- */
51
- deleteByPath(repository: string, filePath: string): Promise<void>;
52
- /**
53
- * Delete all documents for a repository
54
- */
55
- deleteRepository(repository: string): Promise<void>;
56
- /**
57
- * Get collection statistics
58
- */
59
- getStats(): Promise<{
60
- count: number;
61
- }>;
62
- /**
63
- * Clear all data from the collection
64
- */
65
- clear(): Promise<void>;
66
- }
67
- export declare const vectorStore: VectorStore;
68
- export {};
69
- //# sourceMappingURL=vectorStore.d.ts.map
@@ -1,196 +0,0 @@
1
- import { ChromaClient } from "chromadb";
2
- import { config, logger } from "../utils/index.js";
3
- import { embeddingGenerator } from "../pipeline/embeddings.js";
4
- class VectorStore {
5
- client = null;
6
- collection = null;
7
- collectionName = "midnight-code";
8
- initialized = false;
9
- /**
10
- * Initialize the vector store connection
11
- */
12
- async initialize() {
13
- if (this.initialized)
14
- return;
15
- try {
16
- this.client = new ChromaClient({
17
- path: config.chromaUrl,
18
- });
19
- // Get or create the collection
20
- this.collection = await this.client.getOrCreateCollection({
21
- name: this.collectionName,
22
- metadata: {
23
- description: "Midnight blockchain code and documentation",
24
- },
25
- });
26
- this.initialized = true;
27
- logger.info("Vector store initialized successfully");
28
- }
29
- catch (error) {
30
- logger.error("Failed to initialize vector store", {
31
- error: String(error),
32
- });
33
- // Continue without vector store - use fallback search
34
- logger.warn("Vector store unavailable, using in-memory fallback");
35
- }
36
- }
37
- /**
38
- * Add documents to the vector store
39
- */
40
- async addDocuments(documents) {
41
- if (!this.collection) {
42
- logger.warn("Vector store not initialized, skipping document storage");
43
- return;
44
- }
45
- try {
46
- const ids = documents.map((d) => d.id);
47
- const embeddings = documents.map((d) => d.embedding);
48
- const metadatas = documents.map((d) => ({
49
- repository: d.metadata.repository,
50
- filePath: d.metadata.filePath,
51
- language: d.metadata.language,
52
- startLine: d.metadata.startLine,
53
- endLine: d.metadata.endLine,
54
- codeType: d.metadata.codeType,
55
- codeName: d.metadata.codeName,
56
- isPublic: d.metadata.isPublic,
57
- }));
58
- const documentContents = documents.map((d) => d.content);
59
- await this.collection.add({
60
- ids,
61
- embeddings,
62
- metadatas,
63
- documents: documentContents,
64
- });
65
- logger.debug(`Added ${documents.length} documents to vector store`);
66
- }
67
- catch (error) {
68
- logger.error("Failed to add documents to vector store", {
69
- error: String(error),
70
- });
71
- throw error;
72
- }
73
- }
74
- /**
75
- * Search for similar documents
76
- */
77
- async search(query, limit = 10, filter) {
78
- if (!this.collection) {
79
- logger.warn("Vector store not initialized, returning empty results");
80
- return [];
81
- }
82
- try {
83
- // Generate embedding for the query
84
- const queryEmbedding = await embeddingGenerator.generateEmbedding(query);
85
- // Build where filter
86
- const whereFilter = {};
87
- if (filter?.repository) {
88
- whereFilter.repository = filter.repository;
89
- }
90
- if (filter?.language) {
91
- whereFilter.language = filter.language;
92
- }
93
- if (filter?.codeType) {
94
- whereFilter.codeType = filter.codeType;
95
- }
96
- if (filter?.isPublic !== undefined) {
97
- whereFilter.isPublic = filter.isPublic;
98
- }
99
- const results = await this.collection.query({
100
- queryEmbeddings: [queryEmbedding.embedding],
101
- nResults: limit,
102
- where: Object.keys(whereFilter).length > 0 ? whereFilter : undefined,
103
- });
104
- // Format results
105
- const searchResults = [];
106
- if (results.ids[0] && results.documents[0] && results.metadatas[0]) {
107
- for (let i = 0; i < results.ids[0].length; i++) {
108
- const metadata = results.metadatas[0][i];
109
- searchResults.push({
110
- id: results.ids[0][i],
111
- content: results.documents[0][i] || "",
112
- score: results.distances ? 1 - (results.distances[0][i] || 0) : 0,
113
- metadata,
114
- });
115
- }
116
- }
117
- return searchResults;
118
- }
119
- catch (error) {
120
- logger.error("Search failed", { error: String(error) });
121
- return [];
122
- }
123
- }
124
- /**
125
- * Delete documents by file path
126
- */
127
- async deleteByPath(repository, filePath) {
128
- if (!this.collection)
129
- return;
130
- try {
131
- await this.collection.delete({
132
- where: {
133
- repository,
134
- filePath,
135
- },
136
- });
137
- logger.debug(`Deleted documents for ${repository}:${filePath}`);
138
- }
139
- catch (error) {
140
- logger.error("Failed to delete documents", { error: String(error) });
141
- }
142
- }
143
- /**
144
- * Delete all documents for a repository
145
- */
146
- async deleteRepository(repository) {
147
- if (!this.collection)
148
- return;
149
- try {
150
- await this.collection.delete({
151
- where: { repository },
152
- });
153
- logger.info(`Deleted all documents for repository ${repository}`);
154
- }
155
- catch (error) {
156
- logger.error("Failed to delete repository documents", {
157
- error: String(error),
158
- });
159
- }
160
- }
161
- /**
162
- * Get collection statistics
163
- */
164
- async getStats() {
165
- if (!this.collection) {
166
- return { count: 0 };
167
- }
168
- try {
169
- const count = await this.collection.count();
170
- return { count };
171
- }
172
- catch (error) {
173
- logger.error("Failed to get stats", { error: String(error) });
174
- return { count: 0 };
175
- }
176
- }
177
- /**
178
- * Clear all data from the collection
179
- */
180
- async clear() {
181
- if (!this.client)
182
- return;
183
- try {
184
- await this.client.deleteCollection({ name: this.collectionName });
185
- this.collection = await this.client.getOrCreateCollection({
186
- name: this.collectionName,
187
- });
188
- logger.info("Vector store cleared");
189
- }
190
- catch (error) {
191
- logger.error("Failed to clear vector store", { error: String(error) });
192
- }
193
- }
194
- }
195
- export const vectorStore = new VectorStore();
196
- //# sourceMappingURL=vectorStore.js.map
@@ -1,25 +0,0 @@
1
- export interface EmbeddingResult {
2
- text: string;
3
- embedding: number[];
4
- model: string;
5
- tokenCount?: number;
6
- }
7
- export declare class EmbeddingGenerator {
8
- private openai;
9
- private model;
10
- constructor();
11
- /**
12
- * Generate embeddings for a single text
13
- */
14
- generateEmbedding(text: string): Promise<EmbeddingResult>;
15
- /**
16
- * Generate embeddings for multiple texts in batch
17
- */
18
- generateEmbeddings(texts: string[]): Promise<EmbeddingResult[]>;
19
- /**
20
- * Calculate cosine similarity between two embeddings
21
- */
22
- cosineSimilarity(a: number[], b: number[]): number;
23
- }
24
- export declare const embeddingGenerator: EmbeddingGenerator;
25
- //# sourceMappingURL=embeddings.d.ts.map
@@ -1,103 +0,0 @@
1
- import OpenAI from "openai";
2
- import { config, logger } from "../utils/index.js";
3
- export class EmbeddingGenerator {
4
- openai = null;
5
- model;
6
- constructor() {
7
- this.model = config.embeddingModel;
8
- if (config.openaiApiKey) {
9
- this.openai = new OpenAI({
10
- apiKey: config.openaiApiKey,
11
- });
12
- }
13
- }
14
- /**
15
- * Generate embeddings for a single text
16
- */
17
- async generateEmbedding(text) {
18
- if (!this.openai) {
19
- // Return a dummy embedding for testing without API key
20
- logger.warn("No OpenAI API key configured, using dummy embeddings");
21
- return {
22
- text,
23
- embedding: new Array(1536).fill(0).map(() => Math.random() - 0.5),
24
- model: "dummy",
25
- };
26
- }
27
- try {
28
- const response = await this.openai.embeddings.create({
29
- model: this.model,
30
- input: text,
31
- });
32
- return {
33
- text,
34
- embedding: response.data[0].embedding,
35
- model: this.model,
36
- tokenCount: response.usage?.total_tokens,
37
- };
38
- }
39
- catch (error) {
40
- logger.error("Failed to generate embedding", { error: String(error) });
41
- throw error;
42
- }
43
- }
44
- /**
45
- * Generate embeddings for multiple texts in batch
46
- */
47
- async generateEmbeddings(texts) {
48
- if (!this.openai) {
49
- logger.warn("No OpenAI API key configured, using dummy embeddings");
50
- return texts.map((text) => ({
51
- text,
52
- embedding: new Array(1536).fill(0).map(() => Math.random() - 0.5),
53
- model: "dummy",
54
- }));
55
- }
56
- try {
57
- // OpenAI allows up to 2048 inputs per request
58
- const batchSize = 100;
59
- const results = [];
60
- for (let i = 0; i < texts.length; i += batchSize) {
61
- const batch = texts.slice(i, i + batchSize);
62
- logger.debug(`Generating embeddings for batch ${i / batchSize + 1}`);
63
- const response = await this.openai.embeddings.create({
64
- model: this.model,
65
- input: batch,
66
- });
67
- for (let j = 0; j < batch.length; j++) {
68
- results.push({
69
- text: batch[j],
70
- embedding: response.data[j].embedding,
71
- model: this.model,
72
- });
73
- }
74
- }
75
- return results;
76
- }
77
- catch (error) {
78
- logger.error("Failed to generate batch embeddings", {
79
- error: String(error),
80
- });
81
- throw error;
82
- }
83
- }
84
- /**
85
- * Calculate cosine similarity between two embeddings
86
- */
87
- cosineSimilarity(a, b) {
88
- if (a.length !== b.length) {
89
- throw new Error("Embeddings must have the same length");
90
- }
91
- let dotProduct = 0;
92
- let normA = 0;
93
- let normB = 0;
94
- for (let i = 0; i < a.length; i++) {
95
- dotProduct += a[i] * b[i];
96
- normA += a[i] * a[i];
97
- normB += b[i] * b[i];
98
- }
99
- return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
100
- }
101
- }
102
- export const embeddingGenerator = new EmbeddingGenerator();
103
- //# sourceMappingURL=embeddings.js.map
@@ -1,84 +0,0 @@
1
- import { RepositoryConfig, getRateLimitStatus } from "../utils/index.js";
2
- export interface GitHubFile {
3
- path: string;
4
- content: string;
5
- sha: string;
6
- size: number;
7
- encoding: string;
8
- }
9
- export interface GitHubCommit {
10
- sha: string;
11
- message: string;
12
- author: string;
13
- date: string;
14
- url: string;
15
- }
16
- export interface RepositoryInfo {
17
- owner: string;
18
- repo: string;
19
- branch: string;
20
- lastCommit: GitHubCommit | null;
21
- fileCount: number;
22
- }
23
- export declare class GitHubClient {
24
- private octokit;
25
- private fileCache;
26
- private treeCache;
27
- private repoInfoCache;
28
- constructor(token?: string);
29
- /**
30
- * Get repository information
31
- */
32
- getRepositoryInfo(owner: string, repo: string): Promise<RepositoryInfo>;
33
- /**
34
- * Get file content from a repository
35
- */
36
- getFileContent(owner: string, repo: string, path: string, ref?: string): Promise<GitHubFile | null>;
37
- /**
38
- * Get repository tree (list of all files)
39
- */
40
- getRepositoryTree(owner: string, repo: string, ref?: string): Promise<string[]>;
41
- /**
42
- * Filter files by patterns
43
- */
44
- filterFilesByPatterns(files: string[], patterns: string[], exclude: string[]): string[];
45
- /**
46
- * Fetch all files from a repository matching patterns
47
- */
48
- fetchRepositoryFiles(repoConfig: RepositoryConfig): Promise<GitHubFile[]>;
49
- /**
50
- * Get recent commits
51
- */
52
- getRecentCommits(owner: string, repo: string, since?: string, perPage?: number): Promise<GitHubCommit[]>;
53
- /**
54
- * Get files changed in recent commits
55
- */
56
- getChangedFiles(owner: string, repo: string, since: string): Promise<string[]>;
57
- /**
58
- * Search code in repositories
59
- */
60
- searchCode(query: string, owner?: string, repo?: string, language?: string): Promise<Array<{
61
- path: string;
62
- repository: string;
63
- url: string;
64
- }>>;
65
- /**
66
- * Get current rate limit status from GitHub API
67
- */
68
- getRateLimit(): Promise<{
69
- limit: number;
70
- remaining: number;
71
- reset: Date;
72
- used: number;
73
- }>;
74
- /**
75
- * Check if it's safe to make API requests
76
- */
77
- checkRateLimit(): {
78
- proceed: boolean;
79
- reason?: string;
80
- status: ReturnType<typeof getRateLimitStatus>;
81
- };
82
- }
83
- export declare const githubClient: GitHubClient;
84
- //# sourceMappingURL=github.d.ts.map