@dinoxx/dinox-cli 3.5.0 → 3.5.2
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/{bbc-SOUVA3A6.js → bbc-4TIRPEBV.js} +5 -5
- package/dist/chunks/{bohaishibei-TVAYDZ3S.js → bohaishibei-EX6INEG5.js} +2 -2
- package/dist/chunks/chunk-5CW5EUY2.js +51 -0
- package/dist/chunks/{chunk-7A5QISPG.js → chunk-5PEY5B37.js} +11 -1
- package/dist/chunks/{chunk-K3VX75DA.js → chunk-AN2ITAJN.js} +5 -3
- package/dist/chunks/{chunk-ZPE53YBS.js → chunk-DOSP6XQF.js} +8 -8
- package/dist/chunks/{chunk-QOKO7V6A.js → chunk-H5UR7S2R.js} +2 -2
- package/dist/chunks/{chunk-P23BS2ST.js → chunk-HMUFG5WK.js} +7 -7
- package/dist/chunks/{chunk-EPY4F7CC.js → chunk-M6FIMSYZ.js} +25 -25
- package/dist/chunks/{chunk-YERBRBQV.js → chunk-RNLNMEKF.js} +6 -6
- package/dist/chunks/{chunk-TDUVFINJ.js → chunk-TZLGLLK5.js} +20 -20
- package/dist/chunks/{chunk-D7QTW6N6.js → chunk-YNKFRBWM.js} +5 -5
- package/dist/chunks/{cookies-UUQZXH4R.js → cookies-ZP3VKFTD.js} +2 -2
- package/dist/chunks/{doubanGroup-Z22HXP4S.js → doubanGroup-LLHGOW7X.js} +10 -10
- package/dist/chunks/{ensure-PW3HZZSJ.js → ensure-47DNFVVW.js} +5 -5
- package/dist/chunks/{execute-DSHVATUX.js → execute-Y4DBR55R.js} +4 -4
- package/dist/chunks/{install-VBMWNPO6.js → install-KRIISHHQ.js} +7 -4
- package/dist/chunks/{jike-H5FM2OLZ.js → jike-W5D7DZYK.js} +5 -5
- package/dist/chunks/{mcp-OF7C72WL.js → mcp-OYA5MRME.js} +13 -8
- package/dist/chunks/{mcpServer-WURTU2CQ.js → mcpServer-XWTPPDHL.js} +9 -9
- package/dist/chunks/paths-LTGNGPAN.js +11 -0
- package/dist/chunks/{run-FUEARSZ2.js → run-4ZQDJIGP.js} +46 -46
- package/dist/chunks/{runCli-NSGPBNXJ.js → runCli-BYMX6VDC.js} +8 -8
- package/dist/chunks/runtimeRecord-GBZAJ7Q4.js +18 -0
- package/dist/chunks/{setup-EPCEVJVM.js → setup-5HZIQ4GV.js} +6 -6
- package/dist/chunks/{threads-P3QZA3KN.js → threads-MTSDJXGW.js} +5 -5
- package/dist/chunks/{web-SQX7IMO7.js → web-BTDVSI5Z.js} +5 -5
- package/dist/chunks/{weibo-A7RZJLAH.js → weibo-7UTH5JTP.js} +9 -9
- package/dist/chunks/{xiaoheihe-LCWXGLYD.js → xiaoheihe-AB5PNLWT.js} +2 -2
- package/dist/dinox.js +6 -6
- package/dist/dsh-plugin/lib/client.js +135 -135
- package/dist/dsh-plugin/lib/index.js +118 -25
- package/dist/dsh-plugin/package.json +2 -3
- package/dist/editor-ui/mcp-app.html +149 -149
- package/package.json +1 -1
- package/dist/dsh-plugin/runtime.json +0 -5
- package/dist/chunks/{bilibili-V4XVW33T.js → bilibili-JNZVAIRS.js} +7 -7
- package/dist/chunks/{chunk-MWVB6SDC.js → chunk-HLKHDPSU.js} +3 -3
- package/dist/chunks/{chunk-YFGDTC2F.js → chunk-O2AWYZW4.js} +3 -3
- package/dist/chunks/{chunk-YX4SIEVS.js → chunk-YLLVX4IU.js} +3 -3
- package/dist/chunks/{douyin-PIWFZHK7.js → douyin-XQCFVXTX.js} +3 -3
- package/dist/chunks/{instagram-4W4HCWJN.js → instagram-7MHMSJIU.js} +3 -3
- package/dist/chunks/{twitter-WNBOJELM.js → twitter-GPYVL35I.js} +3 -3
- package/dist/chunks/{wechat-WKYZGRG5.js → wechat-RSD3QNSJ.js} +3 -3
- package/dist/chunks/{xiaoyuzhou-OGIWFABL.js → xiaoyuzhou-JJMM3EUH.js} +3 -3
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
// src/integrations/dsh/host.ts
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync } from "node:fs";
|
|
4
|
+
import path3 from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
// src/editor/runtimeRecord.ts
|
|
3
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
+
import path2 from "node:path";
|
|
10
|
+
|
|
11
|
+
// src/config/paths.ts
|
|
12
|
+
import os from "node:os";
|
|
4
13
|
import path from "node:path";
|
|
5
|
-
|
|
14
|
+
function resolveConfigHome() {
|
|
15
|
+
if (process.env.DINOX_CONFIG_DIR) {
|
|
16
|
+
return process.env.DINOX_CONFIG_DIR;
|
|
17
|
+
}
|
|
18
|
+
if (process.platform === "win32") {
|
|
19
|
+
return process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming");
|
|
20
|
+
}
|
|
21
|
+
if (process.platform === "darwin") {
|
|
22
|
+
return path.join(os.homedir(), "Library", "Application Support");
|
|
23
|
+
}
|
|
24
|
+
return process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config");
|
|
25
|
+
}
|
|
26
|
+
function getConfigDir() {
|
|
27
|
+
return path.join(resolveConfigHome(), "dinox");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/editor/runtimeRecord.ts
|
|
31
|
+
var EDITOR_RUNTIME_FILE = "editor-runtime.json";
|
|
32
|
+
function editorRuntimeFile(configDir = getConfigDir()) {
|
|
33
|
+
return path2.join(configDir, EDITOR_RUNTIME_FILE);
|
|
34
|
+
}
|
|
35
|
+
function readEditorRuntime(file = editorRuntimeFile()) {
|
|
36
|
+
try {
|
|
37
|
+
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
38
|
+
const out = {};
|
|
39
|
+
if (typeof value.node === "string" && existsSync(value.node)) out.node = value.node;
|
|
40
|
+
if (typeof value.cli === "string" && existsSync(value.cli)) out.cli = value.cli;
|
|
41
|
+
return out;
|
|
42
|
+
} catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isPlainNode(versions = process.versions) {
|
|
47
|
+
return !("electron" in versions);
|
|
48
|
+
}
|
|
6
49
|
|
|
7
50
|
// src/integrations/dsh/mcpClient.ts
|
|
8
51
|
import { spawn } from "node:child_process";
|
|
@@ -19,14 +62,16 @@ var McpStdioClient = class {
|
|
|
19
62
|
failures = 0;
|
|
20
63
|
retryAt = 0;
|
|
21
64
|
closed = false;
|
|
65
|
+
childVersion = null;
|
|
22
66
|
async listTools() {
|
|
23
67
|
const result = await this.request("tools/list", {}, 3e4);
|
|
24
68
|
return result.tools ?? [];
|
|
25
69
|
}
|
|
70
|
+
/** `longPoll`: a read that waits for news; an update may cut it short (the caller polls again). */
|
|
26
71
|
async callTool(name2, args, options = {}) {
|
|
27
72
|
const params = { name: name2, arguments: args };
|
|
28
73
|
if (options.meta) params._meta = options.meta;
|
|
29
|
-
return await this.request("tools/call", params, options.timeoutMs ?? 4e4);
|
|
74
|
+
return await this.request("tools/call", params, options.timeoutMs ?? 4e4, options.longPoll);
|
|
30
75
|
}
|
|
31
76
|
close() {
|
|
32
77
|
this.closed = true;
|
|
@@ -35,9 +80,25 @@ var McpStdioClient = class {
|
|
|
35
80
|
this.child = null;
|
|
36
81
|
this.ready = null;
|
|
37
82
|
}
|
|
38
|
-
async request(method, params, timeoutMs) {
|
|
83
|
+
async request(method, params, timeoutMs, longPoll = false) {
|
|
84
|
+
this.replaceIfUpdated();
|
|
39
85
|
await this.connect();
|
|
40
|
-
return this.send(method, params, timeoutMs);
|
|
86
|
+
return this.send(method, params, timeoutMs, longPoll);
|
|
87
|
+
}
|
|
88
|
+
/** Stops a child that runs an older `dino` than the one on disk; the next request starts the new one. */
|
|
89
|
+
replaceIfUpdated() {
|
|
90
|
+
const child = this.child;
|
|
91
|
+
if (!child || !this.options.version || this.ready === null) return;
|
|
92
|
+
const now = this.options.version();
|
|
93
|
+
if (!now || now === this.childVersion) return;
|
|
94
|
+
for (const pending of this.pending.values()) if (!pending.longPoll) return;
|
|
95
|
+
const from = this.childVersion;
|
|
96
|
+
this.options.log?.(`dino was updated (${from ?? "unknown"} \u2192 ${now}); restarting dino editor mcp`);
|
|
97
|
+
this.child = null;
|
|
98
|
+
this.ready = null;
|
|
99
|
+
this.failAll(new Error("The Dinox editor restarted after an update"));
|
|
100
|
+
child.kill();
|
|
101
|
+
this.options.onRestart?.(from, now);
|
|
41
102
|
}
|
|
42
103
|
connect() {
|
|
43
104
|
if (this.closed) return Promise.reject(new Error("The Dinox editor connection closed"));
|
|
@@ -66,6 +127,7 @@ var McpStdioClient = class {
|
|
|
66
127
|
stdio: ["pipe", "pipe", "pipe"]
|
|
67
128
|
});
|
|
68
129
|
this.child = child;
|
|
130
|
+
this.childVersion = this.options.version?.() ?? null;
|
|
69
131
|
this.buffer = "";
|
|
70
132
|
child.stdout.setEncoding("utf8");
|
|
71
133
|
child.stdout.on("data", (chunk) => this.onData(chunk));
|
|
@@ -88,7 +150,7 @@ var McpStdioClient = class {
|
|
|
88
150
|
child.on("exit", (code, signal) => gone(`exited (${signal ?? code})`));
|
|
89
151
|
child.stdin.on("error", () => void 0);
|
|
90
152
|
}
|
|
91
|
-
send(method, params, timeoutMs) {
|
|
153
|
+
send(method, params, timeoutMs, longPoll = false) {
|
|
92
154
|
const child = this.child;
|
|
93
155
|
if (!child) return Promise.reject(new Error("The Dinox editor process is not running"));
|
|
94
156
|
const id = this.nextId++;
|
|
@@ -97,7 +159,7 @@ var McpStdioClient = class {
|
|
|
97
159
|
this.pending.delete(id);
|
|
98
160
|
reject(new Error(`The Dinox editor did not answer ${method} in time`));
|
|
99
161
|
}, timeoutMs);
|
|
100
|
-
this.pending.set(id, { resolve, reject, timer });
|
|
162
|
+
this.pending.set(id, { resolve, reject, timer, longPoll });
|
|
101
163
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
102
164
|
`);
|
|
103
165
|
});
|
|
@@ -183,40 +245,70 @@ var MAX_BODY = 8 * 1024 * 1024;
|
|
|
183
245
|
var MAX_UPLOAD_BODY = 511 * 1024 * 1024;
|
|
184
246
|
var UPLOAD_TIMEOUT_MS = 15 * 6e4;
|
|
185
247
|
var MAX_WAIT_MS = 25e3;
|
|
186
|
-
var
|
|
248
|
+
var METHOD_NAME = /^[A-Za-z]{1,40}$/;
|
|
249
|
+
var HOST_ONLY_METHODS = /* @__PURE__ */ new Set(["watchOpens"]);
|
|
187
250
|
var SESSION_META_KEY = "dinox.ai/editorSession";
|
|
188
|
-
function resolveRuntime(pluginLib =
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const node = env.DINOX_EDITOR_NODE || (recorded.node && existsSync(recorded.node) ? recorded.node : process.execPath);
|
|
196
|
-
const cli = env.DINOX_EDITOR_CLI || (recorded.cli && existsSync(recorded.cli) ? recorded.cli : fallbackCli);
|
|
251
|
+
function resolveRuntime(pluginLib = path3.dirname(fileURLToPath(import.meta.url)), env = process.env, recordFile = editorRuntimeFile(), versions = process.versions) {
|
|
252
|
+
const recorded = readEditorRuntime(recordFile);
|
|
253
|
+
const legacy = readEditorRuntime(path3.join(pluginLib, "..", "runtime.json"));
|
|
254
|
+
const adjacent = path3.resolve(pluginLib, "..", "..", "dinox.js");
|
|
255
|
+
const cli = env.DINOX_EDITOR_CLI || (existsSync2(adjacent) ? adjacent : recorded.cli ?? legacy.cli ?? adjacent);
|
|
256
|
+
const prefixNode = path3.resolve(path3.dirname(cli), "..", "..", "..", "..", "..", "bin", "node");
|
|
257
|
+
const node = env.DINOX_EDITOR_NODE || recorded.node || legacy.node || (isPlainNode(versions) ? process.execPath : existsSync2(prefixNode) ? prefixNode : "node");
|
|
197
258
|
return { node, cli };
|
|
198
259
|
}
|
|
199
260
|
var log = (message2) => console.error(`[dinox-editor] ${message2}`);
|
|
261
|
+
function cliVersionReader(cli) {
|
|
262
|
+
const file = path3.join(path3.dirname(cli), "..", "package.json");
|
|
263
|
+
let stamp = -1;
|
|
264
|
+
let version = null;
|
|
265
|
+
return () => {
|
|
266
|
+
try {
|
|
267
|
+
const mtime = statSync(file).mtimeMs;
|
|
268
|
+
if (mtime !== stamp) {
|
|
269
|
+
stamp = mtime;
|
|
270
|
+
const parsed = JSON.parse(readFileSync2(file, "utf8"));
|
|
271
|
+
version = typeof parsed.version === "string" ? parsed.version : null;
|
|
272
|
+
}
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
return version;
|
|
276
|
+
};
|
|
277
|
+
}
|
|
200
278
|
function apply(ctx, options = {}) {
|
|
201
279
|
const write = options.log ?? log;
|
|
280
|
+
let toolDisposers = [];
|
|
281
|
+
const disposeTools = () => {
|
|
282
|
+
for (const dispose of toolDisposers) dispose();
|
|
283
|
+
toolDisposers = [];
|
|
284
|
+
};
|
|
285
|
+
ctx.effect(() => disposeTools);
|
|
202
286
|
const client = options.client ?? (() => {
|
|
203
287
|
const runtime = resolveRuntime();
|
|
204
|
-
|
|
288
|
+
write(`starting ${runtime.cli} with ${runtime.node}`);
|
|
289
|
+
return new McpStdioClient({
|
|
290
|
+
command: runtime.node,
|
|
291
|
+
args: [runtime.cli, "editor", "mcp", "--session", "dsh"],
|
|
292
|
+
log: write,
|
|
293
|
+
version: cliVersionReader(runtime.cli),
|
|
294
|
+
onRestart: () => void retry(registerTools, write)
|
|
295
|
+
});
|
|
205
296
|
})();
|
|
206
297
|
ctx.effect(() => () => client.close());
|
|
207
|
-
const call = async (method, params, timeoutMs) => {
|
|
208
|
-
const result = await client.callTool("dinox_editor_rpc", { method, params }, { timeoutMs });
|
|
298
|
+
const call = async (method, params, timeoutMs, longPoll = false) => {
|
|
299
|
+
const result = await client.callTool("dinox_editor_rpc", { method, params }, { timeoutMs, longPoll });
|
|
209
300
|
if (result.isError) resultText(result);
|
|
210
301
|
return result.structuredContent?.value;
|
|
211
302
|
};
|
|
212
|
-
|
|
303
|
+
async function registerTools() {
|
|
213
304
|
const tools = await client.listTools();
|
|
305
|
+
disposeTools();
|
|
214
306
|
for (const tool of tools) {
|
|
215
307
|
if (isAppOnly(tool)) continue;
|
|
216
|
-
|
|
308
|
+
toolDisposers.push(ctx.tools.register(dshTool(tool, client)));
|
|
217
309
|
}
|
|
218
310
|
write(`registered ${tools.filter((tool) => !isAppOnly(tool)).length} editor tools`);
|
|
219
|
-
}
|
|
311
|
+
}
|
|
220
312
|
void retry(registerTools, write);
|
|
221
313
|
const debounce = options.contextDebounceMs ?? 1200;
|
|
222
314
|
const contexts = /* @__PURE__ */ new Map();
|
|
@@ -254,7 +346,7 @@ function apply(ctx, options = {}) {
|
|
|
254
346
|
const { value: body, size } = await readJson(req, action === "rpc" ? MAX_UPLOAD_BODY : MAX_BODY);
|
|
255
347
|
if (action === "opens") {
|
|
256
348
|
const waitMs2 = clampWait(body.waitMs);
|
|
257
|
-
const value2 = await call("watchOpens", { cursor: body.cursor, waitMs: waitMs2 }, waitMs2 + 15e3);
|
|
349
|
+
const value2 = await call("watchOpens", { cursor: body.cursor, waitMs: waitMs2 }, waitMs2 + 15e3, true);
|
|
258
350
|
const opens = value2.opens.filter((open) => open.session.startsWith(SESSION_PREFIX)).map((open) => ({ ...open, sessionId: open.session.slice(SESSION_PREFIX.length) }));
|
|
259
351
|
return send(res, 200, { value: { cursor: value2.cursor, opens } });
|
|
260
352
|
}
|
|
@@ -265,12 +357,12 @@ function apply(ctx, options = {}) {
|
|
|
265
357
|
return send(res, 200, { value: { ok: true } });
|
|
266
358
|
}
|
|
267
359
|
const method = String(body.method);
|
|
268
|
-
if (!
|
|
360
|
+
if (!METHOD_NAME.test(method) || HOST_ONLY_METHODS.has(method)) return send(res, 400, { error: { message: `Unknown editor method ${method}` } });
|
|
269
361
|
if (method !== "upload" && size > MAX_BODY) return send(res, 413, { error: { message: "Request body exceeds 8MB" } });
|
|
270
362
|
const params = body.params && typeof body.params === "object" && !Array.isArray(body.params) ? body.params : {};
|
|
271
363
|
const waitMs = method === "sync" ? clampWait(params.waitMs) : 0;
|
|
272
364
|
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);
|
|
365
|
+
const value = await call(method, forwarded, method === "sync" ? waitMs + 15e3 : method === "upload" ? UPLOAD_TIMEOUT_MS : 4e4, method === "sync" && waitMs > 0);
|
|
274
366
|
return send(res, 200, { value });
|
|
275
367
|
} catch (error) {
|
|
276
368
|
if (res.writableEnded) return;
|
|
@@ -372,6 +464,7 @@ export {
|
|
|
372
464
|
ROUTE,
|
|
373
465
|
allowedOrigin,
|
|
374
466
|
apply,
|
|
467
|
+
cliVersionReader,
|
|
375
468
|
inject,
|
|
376
469
|
name,
|
|
377
470
|
resolveRuntime
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dinox-editor-dsh",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Dinox note editor for DeepSeek Harness Desktop (built by @dinoxx/dinox-cli)",
|
|
6
6
|
"type": "module",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"lib/",
|
|
16
|
-
"cordis.patch.yml"
|
|
17
|
-
"runtime.json"
|
|
16
|
+
"cordis.patch.yml"
|
|
18
17
|
],
|
|
19
18
|
"dsh": {
|
|
20
19
|
"client": {
|