@dinoxx/dinox-cli 3.4.0 → 3.5.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/dist/chunks/{chunk-62T3W35C.js → chunk-2WWLGTAU.js} +2 -2
- package/dist/chunks/{chunk-T7FAMGXX.js → chunk-6IZ3X5JD.js} +1 -1
- package/dist/chunks/{chunk-SD3ZE2DK.js → chunk-DAAFMTWB.js} +2 -2
- package/dist/chunks/{chunk-VIWFJRN7.js → chunk-QAH7TABU.js} +176 -32
- package/dist/chunks/{chunk-MDRD6FX5.js → chunk-QT4ENEZI.js} +11 -11
- package/dist/chunks/{chunk-OOYOA25J.js → chunk-XS7NHAXR.js} +2 -2
- package/dist/chunks/{ensure-MCRPOLJB.js → ensure-N3OQUDZR.js} +3 -3
- package/dist/chunks/{execute-4OIOIVML.js → execute-KKPBFABB.js} +2 -2
- package/dist/chunks/{mcp-G54XTPLN.js → mcp-YGMXLQEU.js} +4 -3
- package/dist/chunks/{mcpServer-63HXCNLX.js → mcpServer-3V6BVYYT.js} +7 -7
- package/dist/chunks/{run-QGJNZSF4.js → run-FCVNSKGO.js} +3 -3
- package/dist/chunks/{runCli-G4OGL7FZ.js → runCli-KZ3EAIQT.js} +6 -6
- package/dist/dinox.js +4 -4
- package/dist/dsh-plugin/lib/client.js +230 -230
- package/dist/dsh-plugin/lib/index.js +67 -16
- package/dist/dsh-plugin/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +2 -2
- package/dist/editor-ui/mcp-app.html +267 -267
- package/package.json +11 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/integrations/dsh/host.ts
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
@@ -19,14 +19,16 @@ var McpStdioClient = class {
|
|
|
19
19
|
failures = 0;
|
|
20
20
|
retryAt = 0;
|
|
21
21
|
closed = false;
|
|
22
|
+
childVersion = null;
|
|
22
23
|
async listTools() {
|
|
23
24
|
const result = await this.request("tools/list", {}, 3e4);
|
|
24
25
|
return result.tools ?? [];
|
|
25
26
|
}
|
|
27
|
+
/** `longPoll`: a read that waits for news; an update may cut it short (the caller polls again). */
|
|
26
28
|
async callTool(name2, args, options = {}) {
|
|
27
29
|
const params = { name: name2, arguments: args };
|
|
28
30
|
if (options.meta) params._meta = options.meta;
|
|
29
|
-
return await this.request("tools/call", params, options.timeoutMs ?? 4e4);
|
|
31
|
+
return await this.request("tools/call", params, options.timeoutMs ?? 4e4, options.longPoll);
|
|
30
32
|
}
|
|
31
33
|
close() {
|
|
32
34
|
this.closed = true;
|
|
@@ -35,9 +37,25 @@ var McpStdioClient = class {
|
|
|
35
37
|
this.child = null;
|
|
36
38
|
this.ready = null;
|
|
37
39
|
}
|
|
38
|
-
async request(method, params, timeoutMs) {
|
|
40
|
+
async request(method, params, timeoutMs, longPoll = false) {
|
|
41
|
+
this.replaceIfUpdated();
|
|
39
42
|
await this.connect();
|
|
40
|
-
return this.send(method, params, timeoutMs);
|
|
43
|
+
return this.send(method, params, timeoutMs, longPoll);
|
|
44
|
+
}
|
|
45
|
+
/** Stops a child that runs an older `dino` than the one on disk; the next request starts the new one. */
|
|
46
|
+
replaceIfUpdated() {
|
|
47
|
+
const child = this.child;
|
|
48
|
+
if (!child || !this.options.version || this.ready === null) return;
|
|
49
|
+
const now = this.options.version();
|
|
50
|
+
if (!now || now === this.childVersion) return;
|
|
51
|
+
for (const pending of this.pending.values()) if (!pending.longPoll) return;
|
|
52
|
+
const from = this.childVersion;
|
|
53
|
+
this.options.log?.(`dino was updated (${from ?? "unknown"} \u2192 ${now}); restarting dino editor mcp`);
|
|
54
|
+
this.child = null;
|
|
55
|
+
this.ready = null;
|
|
56
|
+
this.failAll(new Error("The Dinox editor restarted after an update"));
|
|
57
|
+
child.kill();
|
|
58
|
+
this.options.onRestart?.(from, now);
|
|
41
59
|
}
|
|
42
60
|
connect() {
|
|
43
61
|
if (this.closed) return Promise.reject(new Error("The Dinox editor connection closed"));
|
|
@@ -66,6 +84,7 @@ var McpStdioClient = class {
|
|
|
66
84
|
stdio: ["pipe", "pipe", "pipe"]
|
|
67
85
|
});
|
|
68
86
|
this.child = child;
|
|
87
|
+
this.childVersion = this.options.version?.() ?? null;
|
|
69
88
|
this.buffer = "";
|
|
70
89
|
child.stdout.setEncoding("utf8");
|
|
71
90
|
child.stdout.on("data", (chunk) => this.onData(chunk));
|
|
@@ -88,7 +107,7 @@ var McpStdioClient = class {
|
|
|
88
107
|
child.on("exit", (code, signal) => gone(`exited (${signal ?? code})`));
|
|
89
108
|
child.stdin.on("error", () => void 0);
|
|
90
109
|
}
|
|
91
|
-
send(method, params, timeoutMs) {
|
|
110
|
+
send(method, params, timeoutMs, longPoll = false) {
|
|
92
111
|
const child = this.child;
|
|
93
112
|
if (!child) return Promise.reject(new Error("The Dinox editor process is not running"));
|
|
94
113
|
const id = this.nextId++;
|
|
@@ -97,7 +116,7 @@ var McpStdioClient = class {
|
|
|
97
116
|
this.pending.delete(id);
|
|
98
117
|
reject(new Error(`The Dinox editor did not answer ${method} in time`));
|
|
99
118
|
}, timeoutMs);
|
|
100
|
-
this.pending.set(id, { resolve, reject, timer });
|
|
119
|
+
this.pending.set(id, { resolve, reject, timer, longPoll });
|
|
101
120
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
102
121
|
`);
|
|
103
122
|
});
|
|
@@ -183,7 +202,8 @@ var MAX_BODY = 8 * 1024 * 1024;
|
|
|
183
202
|
var MAX_UPLOAD_BODY = 511 * 1024 * 1024;
|
|
184
203
|
var UPLOAD_TIMEOUT_MS = 15 * 6e4;
|
|
185
204
|
var MAX_WAIT_MS = 25e3;
|
|
186
|
-
var
|
|
205
|
+
var METHOD_NAME = /^[A-Za-z]{1,40}$/;
|
|
206
|
+
var HOST_ONLY_METHODS = /* @__PURE__ */ new Set(["watchOpens"]);
|
|
187
207
|
var SESSION_META_KEY = "dinox.ai/editorSession";
|
|
188
208
|
function resolveRuntime(pluginLib = path.dirname(fileURLToPath(import.meta.url)), env = process.env) {
|
|
189
209
|
const fallbackCli = path.resolve(pluginLib, "..", "..", "dinox.js");
|
|
@@ -197,26 +217,56 @@ function resolveRuntime(pluginLib = path.dirname(fileURLToPath(import.meta.url))
|
|
|
197
217
|
return { node, cli };
|
|
198
218
|
}
|
|
199
219
|
var log = (message2) => console.error(`[dinox-editor] ${message2}`);
|
|
220
|
+
function cliVersionReader(cli) {
|
|
221
|
+
const file = path.join(path.dirname(cli), "..", "package.json");
|
|
222
|
+
let stamp = -1;
|
|
223
|
+
let version = null;
|
|
224
|
+
return () => {
|
|
225
|
+
try {
|
|
226
|
+
const mtime = statSync(file).mtimeMs;
|
|
227
|
+
if (mtime !== stamp) {
|
|
228
|
+
stamp = mtime;
|
|
229
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
230
|
+
version = typeof parsed.version === "string" ? parsed.version : null;
|
|
231
|
+
}
|
|
232
|
+
} catch {
|
|
233
|
+
}
|
|
234
|
+
return version;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
200
237
|
function apply(ctx, options = {}) {
|
|
201
238
|
const write = options.log ?? log;
|
|
239
|
+
let toolDisposers = [];
|
|
240
|
+
const disposeTools = () => {
|
|
241
|
+
for (const dispose of toolDisposers) dispose();
|
|
242
|
+
toolDisposers = [];
|
|
243
|
+
};
|
|
244
|
+
ctx.effect(() => disposeTools);
|
|
202
245
|
const client = options.client ?? (() => {
|
|
203
246
|
const runtime = resolveRuntime();
|
|
204
|
-
return new McpStdioClient({
|
|
247
|
+
return new McpStdioClient({
|
|
248
|
+
command: runtime.node,
|
|
249
|
+
args: [runtime.cli, "editor", "mcp", "--session", "dsh"],
|
|
250
|
+
log: write,
|
|
251
|
+
version: cliVersionReader(runtime.cli),
|
|
252
|
+
onRestart: () => void retry(registerTools, write)
|
|
253
|
+
});
|
|
205
254
|
})();
|
|
206
255
|
ctx.effect(() => () => client.close());
|
|
207
|
-
const call = async (method, params, timeoutMs) => {
|
|
208
|
-
const result = await client.callTool("dinox_editor_rpc", { method, params }, { timeoutMs });
|
|
256
|
+
const call = async (method, params, timeoutMs, longPoll = false) => {
|
|
257
|
+
const result = await client.callTool("dinox_editor_rpc", { method, params }, { timeoutMs, longPoll });
|
|
209
258
|
if (result.isError) resultText(result);
|
|
210
259
|
return result.structuredContent?.value;
|
|
211
260
|
};
|
|
212
|
-
|
|
261
|
+
async function registerTools() {
|
|
213
262
|
const tools = await client.listTools();
|
|
263
|
+
disposeTools();
|
|
214
264
|
for (const tool of tools) {
|
|
215
265
|
if (isAppOnly(tool)) continue;
|
|
216
|
-
|
|
266
|
+
toolDisposers.push(ctx.tools.register(dshTool(tool, client)));
|
|
217
267
|
}
|
|
218
268
|
write(`registered ${tools.filter((tool) => !isAppOnly(tool)).length} editor tools`);
|
|
219
|
-
}
|
|
269
|
+
}
|
|
220
270
|
void retry(registerTools, write);
|
|
221
271
|
const debounce = options.contextDebounceMs ?? 1200;
|
|
222
272
|
const contexts = /* @__PURE__ */ new Map();
|
|
@@ -254,7 +304,7 @@ function apply(ctx, options = {}) {
|
|
|
254
304
|
const { value: body, size } = await readJson(req, action === "rpc" ? MAX_UPLOAD_BODY : MAX_BODY);
|
|
255
305
|
if (action === "opens") {
|
|
256
306
|
const waitMs2 = clampWait(body.waitMs);
|
|
257
|
-
const value2 = await call("watchOpens", { cursor: body.cursor, waitMs: waitMs2 }, waitMs2 + 15e3);
|
|
307
|
+
const value2 = await call("watchOpens", { cursor: body.cursor, waitMs: waitMs2 }, waitMs2 + 15e3, true);
|
|
258
308
|
const opens = value2.opens.filter((open) => open.session.startsWith(SESSION_PREFIX)).map((open) => ({ ...open, sessionId: open.session.slice(SESSION_PREFIX.length) }));
|
|
259
309
|
return send(res, 200, { value: { cursor: value2.cursor, opens } });
|
|
260
310
|
}
|
|
@@ -265,12 +315,12 @@ function apply(ctx, options = {}) {
|
|
|
265
315
|
return send(res, 200, { value: { ok: true } });
|
|
266
316
|
}
|
|
267
317
|
const method = String(body.method);
|
|
268
|
-
if (!
|
|
318
|
+
if (!METHOD_NAME.test(method) || HOST_ONLY_METHODS.has(method)) return send(res, 400, { error: { message: `Unknown editor method ${method}` } });
|
|
269
319
|
if (method !== "upload" && size > MAX_BODY) return send(res, 413, { error: { message: "Request body exceeds 8MB" } });
|
|
270
320
|
const params = body.params && typeof body.params === "object" && !Array.isArray(body.params) ? body.params : {};
|
|
271
321
|
const waitMs = method === "sync" ? clampWait(params.waitMs) : 0;
|
|
272
322
|
const forwarded = { ...params, session: SESSION_PREFIX + sessionId, ...method === "sync" ? { waitMs } : {} };
|
|
273
|
-
const value = await call(method, forwarded, method === "sync" ? waitMs + 15e3 : method === "upload" ? UPLOAD_TIMEOUT_MS : 4e4);
|
|
323
|
+
const value = await call(method, forwarded, method === "sync" ? waitMs + 15e3 : method === "upload" ? UPLOAD_TIMEOUT_MS : 4e4, method === "sync" && waitMs > 0);
|
|
274
324
|
return send(res, 200, { value });
|
|
275
325
|
} catch (error) {
|
|
276
326
|
if (res.writableEnded) return;
|
|
@@ -372,6 +422,7 @@ export {
|
|
|
372
422
|
ROUTE,
|
|
373
423
|
allowedOrigin,
|
|
374
424
|
apply,
|
|
425
|
+
cliVersionReader,
|
|
375
426
|
inject,
|
|
376
427
|
name,
|
|
377
428
|
resolveRuntime
|