midnight-mcp 0.0.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.
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +2 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/vectorStore.d.ts +66 -0
- package/dist/db/vectorStore.d.ts.map +1 -0
- package/dist/db/vectorStore.js +196 -0
- package/dist/db/vectorStore.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/pipeline/embeddings.d.ts +25 -0
- package/dist/pipeline/embeddings.d.ts.map +1 -0
- package/dist/pipeline/embeddings.js +103 -0
- package/dist/pipeline/embeddings.js.map +1 -0
- package/dist/pipeline/github.d.ts +67 -0
- package/dist/pipeline/github.d.ts.map +1 -0
- package/dist/pipeline/github.js +287 -0
- package/dist/pipeline/github.js.map +1 -0
- package/dist/pipeline/index.d.ts +11 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +6 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/indexer.d.ts +38 -0
- package/dist/pipeline/indexer.d.ts.map +1 -0
- package/dist/pipeline/indexer.js +222 -0
- package/dist/pipeline/indexer.js.map +1 -0
- package/dist/pipeline/parser.d.ts +46 -0
- package/dist/pipeline/parser.d.ts.map +1 -0
- package/dist/pipeline/parser.js +436 -0
- package/dist/pipeline/parser.js.map +1 -0
- package/dist/pipeline/releases.d.ts +112 -0
- package/dist/pipeline/releases.d.ts.map +1 -0
- package/dist/pipeline/releases.js +298 -0
- package/dist/pipeline/releases.js.map +1 -0
- package/dist/pipeline/repository.d.ts +372 -0
- package/dist/pipeline/repository.d.ts.map +1 -0
- package/dist/pipeline/repository.js +517 -0
- package/dist/pipeline/repository.js.map +1 -0
- package/dist/prompts/index.d.ts +3 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +2 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/templates.d.ts +26 -0
- package/dist/prompts/templates.d.ts.map +1 -0
- package/dist/prompts/templates.js +353 -0
- package/dist/prompts/templates.js.map +1 -0
- package/dist/resources/code.d.ts +16 -0
- package/dist/resources/code.d.ts.map +1 -0
- package/dist/resources/code.js +630 -0
- package/dist/resources/code.js.map +1 -0
- package/dist/resources/docs.d.ts +16 -0
- package/dist/resources/docs.d.ts.map +1 -0
- package/dist/resources/docs.js +989 -0
- package/dist/resources/docs.js.map +1 -0
- package/dist/resources/index.d.ts +6 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +13 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/schemas.d.ts +16 -0
- package/dist/resources/schemas.d.ts.map +1 -0
- package/dist/resources/schemas.js +407 -0
- package/dist/resources/schemas.js.map +1 -0
- package/dist/scripts/index-repos.d.ts +12 -0
- package/dist/scripts/index-repos.d.ts.map +1 -0
- package/dist/scripts/index-repos.js +53 -0
- package/dist/scripts/index-repos.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +231 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/analyze.d.ts +140 -0
- package/dist/tools/analyze.d.ts.map +1 -0
- package/dist/tools/analyze.js +270 -0
- package/dist/tools/analyze.js.map +1 -0
- package/dist/tools/index.d.ts +392 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/repository.d.ts +537 -0
- package/dist/tools/repository.d.ts.map +1 -0
- package/dist/tools/repository.js +654 -0
- package/dist/tools/repository.js.map +1 -0
- package/dist/tools/search.d.ts +204 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +210 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/utils/config.d.ts +66 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +161 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +43 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { githubClient } from "../pipeline/index.js";
|
|
3
|
+
import { releaseTracker } from "../pipeline/releases.js";
|
|
4
|
+
import { logger, DEFAULT_REPOSITORIES } from "../utils/index.js";
|
|
5
|
+
// Schema definitions
|
|
6
|
+
export const GetFileInputSchema = z.object({
|
|
7
|
+
repo: z
|
|
8
|
+
.string()
|
|
9
|
+
.describe("Repository name (e.g., 'compact', 'midnight-js', 'example-counter')"),
|
|
10
|
+
path: z.string().describe("File path within repository"),
|
|
11
|
+
ref: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Branch, tag, or commit SHA (default: main)"),
|
|
15
|
+
});
|
|
16
|
+
export const ListExamplesInputSchema = z.object({
|
|
17
|
+
category: z
|
|
18
|
+
.enum(["counter", "bboard", "token", "voting", "all"])
|
|
19
|
+
.optional()
|
|
20
|
+
.default("all")
|
|
21
|
+
.describe("Filter by example type"),
|
|
22
|
+
});
|
|
23
|
+
export const GetLatestUpdatesInputSchema = z.object({
|
|
24
|
+
since: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("ISO date to fetch updates from (default: last 7 days)"),
|
|
28
|
+
repos: z
|
|
29
|
+
.array(z.string())
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Specific repos to check (default: all configured repos)"),
|
|
32
|
+
});
|
|
33
|
+
export const GetVersionInfoInputSchema = z.object({
|
|
34
|
+
repo: z.string().describe("Repository name (e.g., 'compact', 'midnight-js')"),
|
|
35
|
+
});
|
|
36
|
+
export const CheckBreakingChangesInputSchema = z.object({
|
|
37
|
+
repo: z.string().describe("Repository name (e.g., 'compact', 'midnight-js')"),
|
|
38
|
+
currentVersion: z
|
|
39
|
+
.string()
|
|
40
|
+
.describe("Version you're currently using (e.g., 'v1.0.0', '0.5.2')"),
|
|
41
|
+
});
|
|
42
|
+
export const GetMigrationGuideInputSchema = z.object({
|
|
43
|
+
repo: z.string().describe("Repository name (e.g., 'compact', 'midnight-js')"),
|
|
44
|
+
fromVersion: z.string().describe("Version you're migrating from"),
|
|
45
|
+
toVersion: z
|
|
46
|
+
.string()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe("Target version (default: latest stable)"),
|
|
49
|
+
});
|
|
50
|
+
export const GetFileAtVersionInputSchema = z.object({
|
|
51
|
+
repo: z.string().describe("Repository name (e.g., 'compact', 'midnight-js')"),
|
|
52
|
+
path: z.string().describe("File path within repository"),
|
|
53
|
+
version: z
|
|
54
|
+
.string()
|
|
55
|
+
.describe("Version tag (e.g., 'v1.0.0') or branch (e.g., 'main')"),
|
|
56
|
+
});
|
|
57
|
+
export const CompareSyntaxInputSchema = z.object({
|
|
58
|
+
repo: z.string().describe("Repository name (e.g., 'compact')"),
|
|
59
|
+
path: z.string().describe("File path to compare"),
|
|
60
|
+
oldVersion: z.string().describe("Old version tag (e.g., 'v0.9.0')"),
|
|
61
|
+
newVersion: z
|
|
62
|
+
.string()
|
|
63
|
+
.optional()
|
|
64
|
+
.describe("New version tag (default: latest)"),
|
|
65
|
+
});
|
|
66
|
+
export const GetLatestSyntaxInputSchema = z.object({
|
|
67
|
+
repo: z
|
|
68
|
+
.string()
|
|
69
|
+
.default("compact")
|
|
70
|
+
.describe("Repository name (default: 'compact')"),
|
|
71
|
+
});
|
|
72
|
+
// Repository name mapping
|
|
73
|
+
const REPO_ALIASES = {
|
|
74
|
+
// Core Language & SDK
|
|
75
|
+
compact: { owner: "midnightntwrk", repo: "compact" },
|
|
76
|
+
"midnight-js": { owner: "midnightntwrk", repo: "midnight-js" },
|
|
77
|
+
js: { owner: "midnightntwrk", repo: "midnight-js" },
|
|
78
|
+
sdk: { owner: "midnightntwrk", repo: "midnight-js" },
|
|
79
|
+
// Documentation
|
|
80
|
+
docs: { owner: "midnightntwrk", repo: "midnight-docs" },
|
|
81
|
+
"midnight-docs": { owner: "midnightntwrk", repo: "midnight-docs" },
|
|
82
|
+
// Example DApps
|
|
83
|
+
"example-counter": { owner: "midnightntwrk", repo: "example-counter" },
|
|
84
|
+
counter: { owner: "midnightntwrk", repo: "example-counter" },
|
|
85
|
+
"example-bboard": { owner: "midnightntwrk", repo: "example-bboard" },
|
|
86
|
+
bboard: { owner: "midnightntwrk", repo: "example-bboard" },
|
|
87
|
+
"example-dex": { owner: "midnightntwrk", repo: "example-dex" },
|
|
88
|
+
dex: { owner: "midnightntwrk", repo: "example-dex" },
|
|
89
|
+
// Developer Tools
|
|
90
|
+
"create-mn-app": { owner: "midnightntwrk", repo: "create-mn-app" },
|
|
91
|
+
"midnight-wallet": { owner: "midnightntwrk", repo: "midnight-wallet" },
|
|
92
|
+
wallet: { owner: "midnightntwrk", repo: "midnight-wallet" },
|
|
93
|
+
// Infrastructure
|
|
94
|
+
"midnight-indexer": { owner: "midnightntwrk", repo: "midnight-indexer" },
|
|
95
|
+
indexer: { owner: "midnightntwrk", repo: "midnight-indexer" },
|
|
96
|
+
"midnight-node-docker": {
|
|
97
|
+
owner: "midnightntwrk",
|
|
98
|
+
repo: "midnight-node-docker",
|
|
99
|
+
},
|
|
100
|
+
node: { owner: "midnightntwrk", repo: "midnight-node-docker" },
|
|
101
|
+
// APIs & Connectors
|
|
102
|
+
"midnight-dapp-connector-api": {
|
|
103
|
+
owner: "midnightntwrk",
|
|
104
|
+
repo: "midnight-dapp-connector-api",
|
|
105
|
+
},
|
|
106
|
+
connector: { owner: "midnightntwrk", repo: "midnight-dapp-connector-api" },
|
|
107
|
+
// Tooling
|
|
108
|
+
"compact-tree-sitter": {
|
|
109
|
+
owner: "midnightntwrk",
|
|
110
|
+
repo: "compact-tree-sitter",
|
|
111
|
+
},
|
|
112
|
+
// Community
|
|
113
|
+
"midnight-awesome-dapps": {
|
|
114
|
+
owner: "midnightntwrk",
|
|
115
|
+
repo: "midnight-awesome-dapps",
|
|
116
|
+
},
|
|
117
|
+
awesome: { owner: "midnightntwrk", repo: "midnight-awesome-dapps" },
|
|
118
|
+
"contributor-hub": { owner: "midnightntwrk", repo: "contributor-hub" },
|
|
119
|
+
// Partner Libraries (OpenZeppelin)
|
|
120
|
+
"compact-contracts": { owner: "OpenZeppelin", repo: "compact-contracts" },
|
|
121
|
+
openzeppelin: { owner: "OpenZeppelin", repo: "compact-contracts" },
|
|
122
|
+
oz: { owner: "OpenZeppelin", repo: "compact-contracts" },
|
|
123
|
+
};
|
|
124
|
+
const EXAMPLES = [
|
|
125
|
+
{
|
|
126
|
+
name: "Counter",
|
|
127
|
+
repository: "midnightntwrk/example-counter",
|
|
128
|
+
description: "Simple counter contract demonstrating basic Compact concepts. Perfect for learning ledger state, circuits, and witnesses.",
|
|
129
|
+
category: "counter",
|
|
130
|
+
complexity: "beginner",
|
|
131
|
+
mainFile: "contract/src/counter.compact",
|
|
132
|
+
features: [
|
|
133
|
+
"Ledger state management",
|
|
134
|
+
"Basic circuit definition",
|
|
135
|
+
"Counter increment/decrement",
|
|
136
|
+
"TypeScript integration",
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "Bulletin Board",
|
|
141
|
+
repository: "midnightntwrk/example-bboard",
|
|
142
|
+
description: "Full DApp example with CLI and React UI. Demonstrates posting messages with privacy features.",
|
|
143
|
+
category: "bboard",
|
|
144
|
+
complexity: "intermediate",
|
|
145
|
+
mainFile: "contract/src/bboard.compact",
|
|
146
|
+
features: [
|
|
147
|
+
"Private messaging",
|
|
148
|
+
"React frontend",
|
|
149
|
+
"CLI interface",
|
|
150
|
+
"Wallet integration",
|
|
151
|
+
"Disclose operations",
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "DEX (Decentralized Exchange)",
|
|
156
|
+
repository: "midnightntwrk/example-dex",
|
|
157
|
+
description: "Advanced DApp example showing token swaps and liquidity pools with privacy-preserving transactions.",
|
|
158
|
+
category: "dex",
|
|
159
|
+
complexity: "advanced",
|
|
160
|
+
mainFile: "contract/src/dex.compact",
|
|
161
|
+
features: [
|
|
162
|
+
"Token swaps",
|
|
163
|
+
"Liquidity pools",
|
|
164
|
+
"Privacy-preserving trades",
|
|
165
|
+
"Price calculations",
|
|
166
|
+
"Advanced state management",
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
/**
|
|
171
|
+
* Resolve repository name alias to owner/repo
|
|
172
|
+
*/
|
|
173
|
+
function resolveRepo(repoName) {
|
|
174
|
+
const normalized = repoName.toLowerCase().replace(/^midnightntwrk\//, "");
|
|
175
|
+
const alias = REPO_ALIASES[normalized];
|
|
176
|
+
if (alias)
|
|
177
|
+
return alias;
|
|
178
|
+
// Try to find in configured repos
|
|
179
|
+
for (const config of DEFAULT_REPOSITORIES) {
|
|
180
|
+
if (config.repo.toLowerCase() === normalized) {
|
|
181
|
+
return { owner: config.owner, repo: config.repo };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Assume it's a full org/repo name
|
|
185
|
+
if (repoName.includes("/")) {
|
|
186
|
+
const [owner, repo] = repoName.split("/");
|
|
187
|
+
return { owner, repo };
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Retrieve a specific file from Midnight repositories
|
|
193
|
+
*/
|
|
194
|
+
export async function getFile(input) {
|
|
195
|
+
logger.debug("Getting file", { repo: input.repo, path: input.path });
|
|
196
|
+
const repoInfo = resolveRepo(input.repo);
|
|
197
|
+
if (!repoInfo) {
|
|
198
|
+
return {
|
|
199
|
+
error: `Unknown repository: ${input.repo}`,
|
|
200
|
+
suggestion: `Valid repositories: ${Object.keys(REPO_ALIASES).join(", ")}`,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const file = await githubClient.getFileContent(repoInfo.owner, repoInfo.repo, input.path, input.ref);
|
|
204
|
+
if (!file) {
|
|
205
|
+
return {
|
|
206
|
+
error: `File not found: ${input.path}`,
|
|
207
|
+
repository: `${repoInfo.owner}/${repoInfo.repo}`,
|
|
208
|
+
suggestion: "Check the file path and try again. Use midnight:list-examples to see available example files.",
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
content: file.content,
|
|
213
|
+
path: file.path,
|
|
214
|
+
repository: `${repoInfo.owner}/${repoInfo.repo}`,
|
|
215
|
+
sha: file.sha,
|
|
216
|
+
size: file.size,
|
|
217
|
+
url: `https://github.com/${repoInfo.owner}/${repoInfo.repo}/blob/${input.ref || "main"}/${file.path}`,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* List available example contracts and DApps
|
|
222
|
+
*/
|
|
223
|
+
export async function listExamples(input) {
|
|
224
|
+
logger.debug("Listing examples", { category: input.category });
|
|
225
|
+
let filteredExamples = EXAMPLES;
|
|
226
|
+
if (input.category !== "all") {
|
|
227
|
+
filteredExamples = EXAMPLES.filter((e) => e.category === input.category);
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
examples: filteredExamples.map((e) => ({
|
|
231
|
+
name: e.name,
|
|
232
|
+
repository: e.repository,
|
|
233
|
+
description: e.description,
|
|
234
|
+
complexity: e.complexity,
|
|
235
|
+
mainFile: e.mainFile,
|
|
236
|
+
features: e.features,
|
|
237
|
+
githubUrl: `https://github.com/${e.repository}`,
|
|
238
|
+
})),
|
|
239
|
+
totalCount: filteredExamples.length,
|
|
240
|
+
categories: [...new Set(EXAMPLES.map((e) => e.category))],
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Retrieve recent changes across Midnight repositories
|
|
245
|
+
*/
|
|
246
|
+
export async function getLatestUpdates(input) {
|
|
247
|
+
logger.debug("Getting latest updates", input);
|
|
248
|
+
// Default to last 7 days
|
|
249
|
+
const since = input.since || new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
|
|
250
|
+
const repos = input.repos?.map(resolveRepo).filter(Boolean) ||
|
|
251
|
+
DEFAULT_REPOSITORIES.map((r) => ({ owner: r.owner, repo: r.repo }));
|
|
252
|
+
const updates = [];
|
|
253
|
+
for (const repo of repos) {
|
|
254
|
+
if (!repo)
|
|
255
|
+
continue;
|
|
256
|
+
const commits = await githubClient.getRecentCommits(repo.owner, repo.repo, since, 10);
|
|
257
|
+
if (commits.length > 0) {
|
|
258
|
+
updates.push({
|
|
259
|
+
repository: `${repo.owner}/${repo.repo}`,
|
|
260
|
+
commits,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Sort by most recent commit
|
|
265
|
+
updates.sort((a, b) => {
|
|
266
|
+
const aDate = a.commits[0]?.date || "";
|
|
267
|
+
const bDate = b.commits[0]?.date || "";
|
|
268
|
+
return bDate.localeCompare(aDate);
|
|
269
|
+
});
|
|
270
|
+
// Generate summary
|
|
271
|
+
const totalCommits = updates.reduce((sum, u) => sum + u.commits.length, 0);
|
|
272
|
+
const activeRepos = updates.filter((u) => u.commits.length > 0).length;
|
|
273
|
+
return {
|
|
274
|
+
summary: {
|
|
275
|
+
since,
|
|
276
|
+
totalCommits,
|
|
277
|
+
activeRepositories: activeRepos,
|
|
278
|
+
checkedRepositories: repos.length,
|
|
279
|
+
},
|
|
280
|
+
updates: updates.map((u) => ({
|
|
281
|
+
repository: u.repository,
|
|
282
|
+
commitCount: u.commits.length,
|
|
283
|
+
latestCommit: u.commits[0]
|
|
284
|
+
? {
|
|
285
|
+
message: u.commits[0].message.split("\n")[0], // First line only
|
|
286
|
+
date: u.commits[0].date,
|
|
287
|
+
author: u.commits[0].author,
|
|
288
|
+
url: u.commits[0].url,
|
|
289
|
+
}
|
|
290
|
+
: null,
|
|
291
|
+
recentCommits: u.commits.slice(0, 5).map((c) => ({
|
|
292
|
+
message: c.message.split("\n")[0],
|
|
293
|
+
date: c.date,
|
|
294
|
+
sha: c.sha.substring(0, 7),
|
|
295
|
+
})),
|
|
296
|
+
})),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Get version and release info for a repository
|
|
301
|
+
*/
|
|
302
|
+
export async function getVersionInfo(input) {
|
|
303
|
+
logger.debug("Getting version info", input);
|
|
304
|
+
const resolved = resolveRepo(input.repo);
|
|
305
|
+
if (!resolved) {
|
|
306
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
307
|
+
}
|
|
308
|
+
const versionInfo = await releaseTracker.getVersionInfo(resolved.owner, resolved.repo);
|
|
309
|
+
return {
|
|
310
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
311
|
+
latestVersion: versionInfo.latestRelease?.tag || "No releases found",
|
|
312
|
+
latestStableVersion: versionInfo.latestStableRelease?.tag || "No stable releases",
|
|
313
|
+
publishedAt: versionInfo.latestRelease?.publishedAt || null,
|
|
314
|
+
releaseNotes: versionInfo.latestRelease?.body || null,
|
|
315
|
+
recentReleases: versionInfo.recentReleases.slice(0, 5).map((r) => ({
|
|
316
|
+
version: r.tag,
|
|
317
|
+
date: r.publishedAt.split("T")[0],
|
|
318
|
+
isPrerelease: r.isPrerelease,
|
|
319
|
+
url: r.url,
|
|
320
|
+
})),
|
|
321
|
+
recentBreakingChanges: versionInfo.changelog
|
|
322
|
+
.slice(0, 3)
|
|
323
|
+
.flatMap((c) => c.changes.breaking)
|
|
324
|
+
.slice(0, 10),
|
|
325
|
+
versionContext: releaseTracker.getVersionContext(versionInfo),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Check for breaking changes since a specific version
|
|
330
|
+
*/
|
|
331
|
+
export async function checkBreakingChanges(input) {
|
|
332
|
+
logger.debug("Checking breaking changes", input);
|
|
333
|
+
const resolved = resolveRepo(input.repo);
|
|
334
|
+
if (!resolved) {
|
|
335
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
336
|
+
}
|
|
337
|
+
const outdatedInfo = await releaseTracker.isOutdated(resolved.owner, resolved.repo, input.currentVersion);
|
|
338
|
+
const breakingChanges = await releaseTracker.getBreakingChangesSince(resolved.owner, resolved.repo, input.currentVersion);
|
|
339
|
+
return {
|
|
340
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
341
|
+
currentVersion: input.currentVersion,
|
|
342
|
+
latestVersion: outdatedInfo.latestVersion,
|
|
343
|
+
isOutdated: outdatedInfo.isOutdated,
|
|
344
|
+
versionsBehind: outdatedInfo.versionsBehind,
|
|
345
|
+
hasBreakingChanges: outdatedInfo.hasBreakingChanges,
|
|
346
|
+
breakingChanges: breakingChanges,
|
|
347
|
+
recommendation: outdatedInfo.hasBreakingChanges
|
|
348
|
+
? `⚠️ Breaking changes detected! Review the ${breakingChanges.length} breaking change(s) before upgrading.`
|
|
349
|
+
: outdatedInfo.isOutdated
|
|
350
|
+
? `✅ Safe to upgrade. No breaking changes detected since ${input.currentVersion}.`
|
|
351
|
+
: `✅ You're on the latest version.`,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Get migration guide between versions
|
|
356
|
+
*/
|
|
357
|
+
export async function getMigrationGuide(input) {
|
|
358
|
+
logger.debug("Getting migration guide", input);
|
|
359
|
+
const resolved = resolveRepo(input.repo);
|
|
360
|
+
if (!resolved) {
|
|
361
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
362
|
+
}
|
|
363
|
+
const guide = await releaseTracker.getMigrationGuide(resolved.owner, resolved.repo, input.fromVersion, input.toVersion);
|
|
364
|
+
return {
|
|
365
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
366
|
+
from: guide.from,
|
|
367
|
+
to: guide.to,
|
|
368
|
+
summary: {
|
|
369
|
+
breakingChangesCount: guide.breakingChanges.length,
|
|
370
|
+
deprecationsCount: guide.deprecations.length,
|
|
371
|
+
newFeaturesCount: guide.newFeatures.length,
|
|
372
|
+
},
|
|
373
|
+
breakingChanges: guide.breakingChanges,
|
|
374
|
+
deprecations: guide.deprecations,
|
|
375
|
+
newFeatures: guide.newFeatures,
|
|
376
|
+
migrationSteps: guide.migrationSteps,
|
|
377
|
+
migrationDifficulty: guide.breakingChanges.length === 0
|
|
378
|
+
? "Easy - No breaking changes"
|
|
379
|
+
: guide.breakingChanges.length <= 3
|
|
380
|
+
? "Moderate - Few breaking changes"
|
|
381
|
+
: "Complex - Multiple breaking changes, plan carefully",
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Get a file at a specific version - critical for version-accurate recommendations
|
|
386
|
+
*/
|
|
387
|
+
export async function getFileAtVersion(input) {
|
|
388
|
+
logger.debug("Getting file at version", input);
|
|
389
|
+
const resolved = resolveRepo(input.repo);
|
|
390
|
+
if (!resolved) {
|
|
391
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
392
|
+
}
|
|
393
|
+
const result = await releaseTracker.getFileAtVersion(resolved.owner, resolved.repo, input.path, input.version);
|
|
394
|
+
if (!result) {
|
|
395
|
+
throw new Error(`File not found: ${input.path} at version ${input.version} in ${input.repo}`);
|
|
396
|
+
}
|
|
397
|
+
return {
|
|
398
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
399
|
+
path: input.path,
|
|
400
|
+
version: result.version,
|
|
401
|
+
content: result.content,
|
|
402
|
+
note: `This is the exact content at version ${result.version}. Use this as the source of truth for syntax and API at this version.`,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Compare syntax between two versions - shows what changed
|
|
407
|
+
*/
|
|
408
|
+
export async function compareSyntax(input) {
|
|
409
|
+
logger.debug("Comparing syntax between versions", input);
|
|
410
|
+
const resolved = resolveRepo(input.repo);
|
|
411
|
+
if (!resolved) {
|
|
412
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
413
|
+
}
|
|
414
|
+
// If no newVersion specified, get latest
|
|
415
|
+
let newVersion = input.newVersion;
|
|
416
|
+
if (!newVersion) {
|
|
417
|
+
const versionInfo = await releaseTracker.getVersionInfo(resolved.owner, resolved.repo);
|
|
418
|
+
newVersion =
|
|
419
|
+
versionInfo.latestStableRelease?.tag ||
|
|
420
|
+
versionInfo.latestRelease?.tag ||
|
|
421
|
+
"main";
|
|
422
|
+
}
|
|
423
|
+
const comparison = await releaseTracker.compareSyntax(resolved.owner, resolved.repo, input.path, input.oldVersion, newVersion);
|
|
424
|
+
return {
|
|
425
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
426
|
+
path: input.path,
|
|
427
|
+
oldVersion: comparison.oldVersion,
|
|
428
|
+
newVersion: comparison.newVersion,
|
|
429
|
+
hasDifferences: comparison.hasDifferences,
|
|
430
|
+
oldContent: comparison.oldContent,
|
|
431
|
+
newContent: comparison.newContent,
|
|
432
|
+
recommendation: comparison.hasDifferences
|
|
433
|
+
? `⚠️ This file has changed between ${comparison.oldVersion} and ${comparison.newVersion}. Review the differences before using code patterns from the old version.`
|
|
434
|
+
: `✅ No changes in this file between versions.`,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Get the latest syntax reference for Compact language
|
|
439
|
+
* This is the source of truth for writing valid, compilable contracts
|
|
440
|
+
*/
|
|
441
|
+
export async function getLatestSyntax(input) {
|
|
442
|
+
logger.debug("Getting latest syntax reference", input);
|
|
443
|
+
const resolved = resolveRepo(input.repo);
|
|
444
|
+
if (!resolved) {
|
|
445
|
+
throw new Error(`Unknown repository: ${input.repo}. Available: ${Object.keys(REPO_ALIASES).join(", ")}`);
|
|
446
|
+
}
|
|
447
|
+
const reference = await releaseTracker.getLatestSyntaxReference(resolved.owner, resolved.repo);
|
|
448
|
+
if (!reference || reference.syntaxFiles.length === 0) {
|
|
449
|
+
// Fallback: get example contracts as syntax reference
|
|
450
|
+
const versionInfo = await releaseTracker.getVersionInfo(resolved.owner, resolved.repo);
|
|
451
|
+
const version = versionInfo.latestStableRelease?.tag || "main";
|
|
452
|
+
return {
|
|
453
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
454
|
+
version,
|
|
455
|
+
warning: "No grammar documentation found. Use example contracts as reference.",
|
|
456
|
+
syntaxFiles: [],
|
|
457
|
+
examplePaths: ["examples/", "test/", "contracts/"],
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
repository: `${resolved.owner}/${resolved.repo}`,
|
|
462
|
+
version: reference.version,
|
|
463
|
+
syntaxFiles: reference.syntaxFiles.map((f) => ({
|
|
464
|
+
path: f.path,
|
|
465
|
+
content: f.content,
|
|
466
|
+
})),
|
|
467
|
+
note: `This is the authoritative syntax reference at version ${reference.version}. Use this to ensure contracts are compilable.`,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
// Tool definitions for MCP
|
|
471
|
+
export const repositoryTools = [
|
|
472
|
+
{
|
|
473
|
+
name: "midnight-get-file",
|
|
474
|
+
description: "Retrieve a specific file from Midnight repositories. Use repository aliases like 'compact', 'midnight-js', 'counter', or 'bboard' for convenience.",
|
|
475
|
+
inputSchema: {
|
|
476
|
+
type: "object",
|
|
477
|
+
properties: {
|
|
478
|
+
repo: {
|
|
479
|
+
type: "string",
|
|
480
|
+
description: "Repository name (e.g., 'compact', 'midnight-js', 'example-counter')",
|
|
481
|
+
},
|
|
482
|
+
path: {
|
|
483
|
+
type: "string",
|
|
484
|
+
description: "File path within repository",
|
|
485
|
+
},
|
|
486
|
+
ref: {
|
|
487
|
+
type: "string",
|
|
488
|
+
description: "Branch, tag, or commit SHA (default: main)",
|
|
489
|
+
},
|
|
490
|
+
},
|
|
491
|
+
required: ["repo", "path"],
|
|
492
|
+
},
|
|
493
|
+
handler: getFile,
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
name: "midnight-list-examples",
|
|
497
|
+
description: "List available Midnight example contracts and DApps with descriptions, complexity ratings, and key features.",
|
|
498
|
+
inputSchema: {
|
|
499
|
+
type: "object",
|
|
500
|
+
properties: {
|
|
501
|
+
category: {
|
|
502
|
+
type: "string",
|
|
503
|
+
enum: ["counter", "bboard", "token", "voting", "all"],
|
|
504
|
+
description: "Filter by example type (default: all)",
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
required: [],
|
|
508
|
+
},
|
|
509
|
+
handler: listExamples,
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
name: "midnight-get-latest-updates",
|
|
513
|
+
description: "Retrieve recent changes and commits across Midnight repositories. Useful for staying up-to-date with the latest developments.",
|
|
514
|
+
inputSchema: {
|
|
515
|
+
type: "object",
|
|
516
|
+
properties: {
|
|
517
|
+
since: {
|
|
518
|
+
type: "string",
|
|
519
|
+
description: "ISO date to fetch updates from (default: last 7 days)",
|
|
520
|
+
},
|
|
521
|
+
repos: {
|
|
522
|
+
type: "array",
|
|
523
|
+
items: { type: "string" },
|
|
524
|
+
description: "Specific repos to check (default: all configured repos)",
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
required: [],
|
|
528
|
+
},
|
|
529
|
+
handler: getLatestUpdates,
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "midnight-get-version-info",
|
|
533
|
+
description: "Get the latest version, release notes, and recent breaking changes for a Midnight repository. Use this to ensure you're working with the latest implementation.",
|
|
534
|
+
inputSchema: {
|
|
535
|
+
type: "object",
|
|
536
|
+
properties: {
|
|
537
|
+
repo: {
|
|
538
|
+
type: "string",
|
|
539
|
+
description: "Repository name (e.g., 'compact', 'midnight-js', 'sdk')",
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
required: ["repo"],
|
|
543
|
+
},
|
|
544
|
+
handler: getVersionInfo,
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: "midnight-check-breaking-changes",
|
|
548
|
+
description: "Check if there are breaking changes between your current version and the latest release. Essential before upgrading dependencies.",
|
|
549
|
+
inputSchema: {
|
|
550
|
+
type: "object",
|
|
551
|
+
properties: {
|
|
552
|
+
repo: {
|
|
553
|
+
type: "string",
|
|
554
|
+
description: "Repository name (e.g., 'compact', 'midnight-js')",
|
|
555
|
+
},
|
|
556
|
+
currentVersion: {
|
|
557
|
+
type: "string",
|
|
558
|
+
description: "Version you're currently using (e.g., 'v1.0.0', '0.5.2')",
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
required: ["repo", "currentVersion"],
|
|
562
|
+
},
|
|
563
|
+
handler: checkBreakingChanges,
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: "midnight-get-migration-guide",
|
|
567
|
+
description: "Get a detailed migration guide for upgrading between versions, including all breaking changes, deprecations, and recommended steps.",
|
|
568
|
+
inputSchema: {
|
|
569
|
+
type: "object",
|
|
570
|
+
properties: {
|
|
571
|
+
repo: {
|
|
572
|
+
type: "string",
|
|
573
|
+
description: "Repository name (e.g., 'compact', 'midnight-js')",
|
|
574
|
+
},
|
|
575
|
+
fromVersion: {
|
|
576
|
+
type: "string",
|
|
577
|
+
description: "Version you're migrating from",
|
|
578
|
+
},
|
|
579
|
+
toVersion: {
|
|
580
|
+
type: "string",
|
|
581
|
+
description: "Target version (default: latest stable)",
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
required: ["repo", "fromVersion"],
|
|
585
|
+
},
|
|
586
|
+
handler: getMigrationGuide,
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
name: "midnight-get-file-at-version",
|
|
590
|
+
description: "Get the exact content of a file at a specific version. CRITICAL: Use this to ensure code recommendations match the user's version. Always prefer this over get-file when version accuracy matters.",
|
|
591
|
+
inputSchema: {
|
|
592
|
+
type: "object",
|
|
593
|
+
properties: {
|
|
594
|
+
repo: {
|
|
595
|
+
type: "string",
|
|
596
|
+
description: "Repository name (e.g., 'compact', 'midnight-js')",
|
|
597
|
+
},
|
|
598
|
+
path: {
|
|
599
|
+
type: "string",
|
|
600
|
+
description: "File path within repository",
|
|
601
|
+
},
|
|
602
|
+
version: {
|
|
603
|
+
type: "string",
|
|
604
|
+
description: "Version tag (e.g., 'v1.0.0') or branch (e.g., 'main')",
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
required: ["repo", "path", "version"],
|
|
608
|
+
},
|
|
609
|
+
handler: getFileAtVersion,
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: "midnight-compare-syntax",
|
|
613
|
+
description: "Compare a file between two versions to see what changed. Use this before recommending code patterns to ensure they work with the user's version.",
|
|
614
|
+
inputSchema: {
|
|
615
|
+
type: "object",
|
|
616
|
+
properties: {
|
|
617
|
+
repo: {
|
|
618
|
+
type: "string",
|
|
619
|
+
description: "Repository name (e.g., 'compact')",
|
|
620
|
+
},
|
|
621
|
+
path: {
|
|
622
|
+
type: "string",
|
|
623
|
+
description: "File path to compare",
|
|
624
|
+
},
|
|
625
|
+
oldVersion: {
|
|
626
|
+
type: "string",
|
|
627
|
+
description: "Old version tag (e.g., 'v0.9.0')",
|
|
628
|
+
},
|
|
629
|
+
newVersion: {
|
|
630
|
+
type: "string",
|
|
631
|
+
description: "New version tag (default: latest stable)",
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
required: ["repo", "path", "oldVersion"],
|
|
635
|
+
},
|
|
636
|
+
handler: compareSyntax,
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
name: "midnight-get-latest-syntax",
|
|
640
|
+
description: "Get the authoritative syntax reference for Compact language at the latest version. Use this as the source of truth when writing or reviewing contracts to ensure they compile.",
|
|
641
|
+
inputSchema: {
|
|
642
|
+
type: "object",
|
|
643
|
+
properties: {
|
|
644
|
+
repo: {
|
|
645
|
+
type: "string",
|
|
646
|
+
description: "Repository name (default: 'compact')",
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
required: [],
|
|
650
|
+
},
|
|
651
|
+
handler: getLatestSyntax,
|
|
652
|
+
},
|
|
653
|
+
];
|
|
654
|
+
//# sourceMappingURL=repository.js.map
|