@adhisang/minecraft-modding-mcp 2.0.0 → 2.1.0
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/CHANGELOG.md +44 -0
- package/README.md +109 -29
- package/dist/cli.js +31 -4
- package/dist/compat-stdio-transport.d.ts +2 -7
- package/dist/compat-stdio-transport.js +12 -154
- package/dist/index.js +392 -33
- package/dist/json-rpc-framing.d.ts +22 -0
- package/dist/json-rpc-framing.js +168 -0
- package/dist/mapping-pipeline-service.js +9 -1
- package/dist/mapping-service.d.ts +9 -0
- package/dist/mapping-service.js +183 -60
- package/dist/minecraft-explorer-service.d.ts +0 -1
- package/dist/minecraft-explorer-service.js +119 -23
- package/dist/mixin-validator.d.ts +24 -2
- package/dist/mixin-validator.js +223 -98
- package/dist/mod-decompile-service.d.ts +5 -0
- package/dist/mod-decompile-service.js +40 -5
- package/dist/mod-remap-service.js +142 -30
- package/dist/path-resolver.js +41 -4
- package/dist/registry-service.d.ts +10 -1
- package/dist/registry-service.js +154 -22
- package/dist/search-hit-accumulator.js +23 -2
- package/dist/source-jar-reader.js +16 -2
- package/dist/source-resolver.js +6 -7
- package/dist/source-service.d.ts +42 -4
- package/dist/source-service.js +781 -127
- package/dist/stdio-supervisor.d.ts +46 -0
- package/dist/stdio-supervisor.js +349 -0
- package/dist/storage/files-repo.d.ts +3 -9
- package/dist/storage/files-repo.js +66 -43
- package/dist/symbols/symbol-extractor.js +6 -4
- package/dist/tool-execution-gate.d.ts +15 -0
- package/dist/tool-execution-gate.js +58 -0
- package/dist/version-diff-service.js +10 -5
- package/dist/version-service.js +7 -2
- package/dist/workspace-mapping-service.js +12 -0
- package/package.json +1 -1
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import {
|
|
3
|
-
function findHeaderBoundary(buffer) {
|
|
4
|
-
const crlfBoundary = buffer.indexOf("\r\n\r\n");
|
|
5
|
-
if (crlfBoundary !== -1) {
|
|
6
|
-
return { index: crlfBoundary, delimiterBytes: 4 };
|
|
7
|
-
}
|
|
8
|
-
const lfBoundary = buffer.indexOf("\n\n");
|
|
9
|
-
if (lfBoundary !== -1) {
|
|
10
|
-
return { index: lfBoundary, delimiterBytes: 2 };
|
|
11
|
-
}
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
function parseJsonRpcMessage(json) {
|
|
15
|
-
return JSONRPCMessageSchema.parse(JSON.parse(json));
|
|
16
|
-
}
|
|
2
|
+
import { JsonRpcFrameReader, encodeJsonRpcMessage } from "./json-rpc-framing.js";
|
|
17
3
|
function asError(value) {
|
|
18
4
|
return value instanceof Error ? value : new Error(String(value));
|
|
19
5
|
}
|
|
20
6
|
export class CompatStdioServerTransport {
|
|
21
7
|
stdin;
|
|
22
8
|
stdout;
|
|
9
|
+
frameReader = new JsonRpcFrameReader();
|
|
23
10
|
started = false;
|
|
24
11
|
closed = false;
|
|
25
|
-
mode = "unknown";
|
|
26
|
-
buffer = Buffer.alloc(0);
|
|
27
12
|
onclose;
|
|
28
13
|
onerror;
|
|
29
14
|
onmessage;
|
|
@@ -43,10 +28,7 @@ export class CompatStdioServerTransport {
|
|
|
43
28
|
this.stdin.resume();
|
|
44
29
|
}
|
|
45
30
|
async send(message) {
|
|
46
|
-
const
|
|
47
|
-
const frame = this.mode === "content-length"
|
|
48
|
-
? `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n${json}`
|
|
49
|
-
: `${json}\n`;
|
|
31
|
+
const frame = encodeJsonRpcMessage(message, this.frameReader.currentMode === "content-length" ? "content-length" : "line");
|
|
50
32
|
await new Promise((resolve) => {
|
|
51
33
|
if (this.stdout.write(frame)) {
|
|
52
34
|
resolve();
|
|
@@ -63,15 +45,18 @@ export class CompatStdioServerTransport {
|
|
|
63
45
|
if (this.stdin.listenerCount("data") === 0) {
|
|
64
46
|
this.stdin.pause();
|
|
65
47
|
}
|
|
66
|
-
this.
|
|
48
|
+
this.frameReader.clear();
|
|
67
49
|
this.emitCloseOnce();
|
|
68
50
|
}
|
|
69
51
|
handleData = (chunk) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
this.frameReader.processChunk(chunk, {
|
|
53
|
+
onFrame: ({ message }) => {
|
|
54
|
+
this.onmessage?.(message);
|
|
55
|
+
},
|
|
56
|
+
onError: (error) => {
|
|
57
|
+
this.onerror?.(error);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
75
60
|
};
|
|
76
61
|
handleStreamError = (error) => {
|
|
77
62
|
this.onerror?.(error);
|
|
@@ -86,132 +71,5 @@ export class CompatStdioServerTransport {
|
|
|
86
71
|
this.closed = true;
|
|
87
72
|
this.onclose?.();
|
|
88
73
|
}
|
|
89
|
-
processReadBuffer() {
|
|
90
|
-
while (true) {
|
|
91
|
-
try {
|
|
92
|
-
if (this.mode === "unknown") {
|
|
93
|
-
const detected = this.detectMode();
|
|
94
|
-
if (!detected) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
this.mode = detected;
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const modeBefore = this.mode;
|
|
101
|
-
const message = this.mode === "content-length"
|
|
102
|
-
? this.readContentLengthMessage()
|
|
103
|
-
: this.readLineDelimitedMessage();
|
|
104
|
-
if (!message) {
|
|
105
|
-
// readLineDelimitedMessage may switch mode to "content-length"
|
|
106
|
-
// mid-stream; retry with the new parser instead of stopping.
|
|
107
|
-
if (this.mode !== modeBefore) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.onmessage?.(message);
|
|
113
|
-
}
|
|
114
|
-
catch (caughtError) {
|
|
115
|
-
this.onerror?.(asError(caughtError));
|
|
116
|
-
this.mode = "unknown";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
detectMode() {
|
|
121
|
-
// Skip blank leading lines that some clients may emit.
|
|
122
|
-
while (this.buffer.length > 0) {
|
|
123
|
-
if (this.buffer[0] === 0x0a) {
|
|
124
|
-
this.buffer = this.buffer.subarray(1);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (this.buffer.length >= 2 && this.buffer[0] === 0x0d && this.buffer[1] === 0x0a) {
|
|
128
|
-
this.buffer = this.buffer.subarray(2);
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
if (this.buffer.length === 0) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
const prefix = this.buffer
|
|
137
|
-
.subarray(0, Math.min(this.buffer.length, 32))
|
|
138
|
-
.toString("utf8")
|
|
139
|
-
.toLowerCase();
|
|
140
|
-
if (prefix.startsWith("content-length")) {
|
|
141
|
-
return "content-length";
|
|
142
|
-
}
|
|
143
|
-
const firstNewline = this.buffer.indexOf(0x0a);
|
|
144
|
-
if (firstNewline === -1) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
const firstLine = this.buffer.subarray(0, firstNewline).toString("utf8").replace(/\r$/, "");
|
|
148
|
-
if (/^\s*content-length\s*:/i.test(firstLine)) {
|
|
149
|
-
return "content-length";
|
|
150
|
-
}
|
|
151
|
-
return "line";
|
|
152
|
-
}
|
|
153
|
-
readLineDelimitedMessage() {
|
|
154
|
-
while (true) {
|
|
155
|
-
const newlineIndex = this.buffer.indexOf(0x0a);
|
|
156
|
-
if (newlineIndex === -1) {
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
const line = this.buffer.subarray(0, newlineIndex).toString("utf8").replace(/\r$/, "");
|
|
160
|
-
this.buffer = this.buffer.subarray(newlineIndex + 1);
|
|
161
|
-
if (line.trim().length === 0) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (/^\s*content-length\s*:/i.test(line)) {
|
|
165
|
-
// Reconstruct the header with the correct line ending so that
|
|
166
|
-
// findHeaderBoundary can locate \r\n\r\n or \n\n reliably.
|
|
167
|
-
const sep = this.buffer.length > 0 && this.buffer[0] === 0x0d ? "\r\n" : "\n";
|
|
168
|
-
this.buffer = Buffer.concat([Buffer.from(`${line}${sep}`, "utf8"), this.buffer]);
|
|
169
|
-
this.mode = "content-length";
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
return parseJsonRpcMessage(line);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
readContentLengthMessage() {
|
|
176
|
-
const headerBoundary = findHeaderBoundary(this.buffer);
|
|
177
|
-
if (!headerBoundary) {
|
|
178
|
-
return undefined;
|
|
179
|
-
}
|
|
180
|
-
const headersRaw = this.buffer.subarray(0, headerBoundary.index).toString("utf8");
|
|
181
|
-
const headerLines = headersRaw
|
|
182
|
-
.split(/\r?\n/)
|
|
183
|
-
.map((line) => line.trim())
|
|
184
|
-
.filter((line) => line.length > 0);
|
|
185
|
-
let contentLength;
|
|
186
|
-
for (const headerLine of headerLines) {
|
|
187
|
-
const separatorIndex = headerLine.indexOf(":");
|
|
188
|
-
if (separatorIndex === -1) {
|
|
189
|
-
this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
|
|
190
|
-
throw new Error(`Malformed header line: ${headerLine}`);
|
|
191
|
-
}
|
|
192
|
-
const headerName = headerLine.slice(0, separatorIndex).trim().toLowerCase();
|
|
193
|
-
const headerValue = headerLine.slice(separatorIndex + 1).trim();
|
|
194
|
-
if (headerName === "content-length") {
|
|
195
|
-
const parsed = Number.parseInt(headerValue, 10);
|
|
196
|
-
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
197
|
-
this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
|
|
198
|
-
throw new Error(`Invalid Content-Length header value: ${headerValue}`);
|
|
199
|
-
}
|
|
200
|
-
contentLength = parsed;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (contentLength === undefined) {
|
|
204
|
-
this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
|
|
205
|
-
throw new Error("Missing Content-Length header.");
|
|
206
|
-
}
|
|
207
|
-
const messageStart = headerBoundary.index + headerBoundary.delimiterBytes;
|
|
208
|
-
const frameEnd = messageStart + contentLength;
|
|
209
|
-
if (this.buffer.length < frameEnd) {
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
const body = this.buffer.subarray(messageStart, frameEnd).toString("utf8");
|
|
213
|
-
this.buffer = this.buffer.subarray(frameEnd);
|
|
214
|
-
return parseJsonRpcMessage(body);
|
|
215
|
-
}
|
|
216
74
|
}
|
|
217
75
|
//# sourceMappingURL=compat-stdio-transport.js.map
|