@dinoxx/dinox-cli 2.17.0 → 2.18.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/dist/cli.js +2 -0
- package/dist/commands/editor/index.d.ts +4 -0
- package/dist/commands/editor/index.js +155 -0
- package/dist/commands/notes/contentPatch.d.ts +23 -0
- package/dist/commands/notes/contentPatch.js +37 -0
- package/dist/commands/schema/renderSkills.js +1 -0
- package/dist/commands/schema/spec.js +2 -0
- package/dist/daemon/server.d.ts +2 -1
- package/dist/daemon/server.js +22 -2
- package/dist/dsh-plugin/cordis.patch.yml +3 -0
- package/dist/dsh-plugin/lib/client.js +2145 -0
- package/dist/dsh-plugin/lib/index.js +369 -0
- package/dist/dsh-plugin/package.json +32 -0
- package/dist/dsh-plugin/runtime.json +5 -0
- package/dist/editor/anchor.d.ts +46 -0
- package/dist/editor/anchor.js +129 -0
- package/dist/editor/blockIds.d.ts +21 -0
- package/dist/editor/blockIds.js +51 -0
- package/dist/editor/blocks.d.ts +47 -0
- package/dist/editor/blocks.js +236 -0
- package/dist/editor/compat.d.ts +32 -0
- package/dist/editor/compat.js +392 -0
- package/dist/editor/daemon.d.ts +10 -0
- package/dist/editor/daemon.js +56 -0
- package/dist/editor/document.d.ts +74 -0
- package/dist/editor/document.js +88 -0
- package/dist/editor/i18n.d.ts +23 -0
- package/dist/editor/i18n.js +61 -0
- package/dist/editor/install.d.ts +72 -0
- package/dist/editor/install.js +239 -0
- package/dist/editor/mcp.d.ts +22 -0
- package/dist/editor/mcp.js +222 -0
- package/dist/editor/meta.d.ts +70 -0
- package/dist/editor/meta.js +163 -0
- package/dist/editor/paths.d.ts +2 -0
- package/dist/editor/paths.js +13 -0
- package/dist/editor/persistence.d.ts +4 -0
- package/dist/editor/persistence.js +35 -0
- package/dist/editor/saveGuard.d.ts +9 -0
- package/dist/editor/saveGuard.js +38 -0
- package/dist/editor/schema.d.ts +14 -0
- package/dist/editor/schema.js +38 -0
- package/dist/editor/service.d.ts +326 -0
- package/dist/editor/service.js +1007 -0
- package/dist/editor-ui/mcp-app.html +765 -0
- package/dist/gateway/adapters/acp.d.ts +8 -0
- package/dist/gateway/adapters/acp.js +38 -2
- package/dist/gateway/agentTaskHost.d.ts +9 -3
- package/dist/gateway/agentTaskHost.js +45 -25
- package/dist/gateway/config.js +2 -2
- package/dist/gateway/deviceHost.d.ts +1 -1
- package/dist/gateway/deviceHost.js +8 -4
- package/dist/gateway/mcpCommandTools.d.ts +1 -1
- package/dist/gateway/mcpCommandTools.js +2 -2
- package/dist/gateway/processTree.d.ts +15 -0
- package/dist/gateway/processTree.js +60 -0
- package/dist/gateway/protocol.js +2 -1
- package/dist/gateway/service.d.ts +1 -1
- package/dist/gateway/service.js +2 -1
- package/dist/gateway/taskJournal.d.ts +14 -0
- package/dist/gateway/taskJournal.js +47 -0
- package/dist/gateway/threadStore.d.ts +7 -1
- package/dist/gateway/threadStore.js +14 -3
- package/dist/gateway/types.d.ts +7 -3
- package/dist/gateway/types.js +3 -1
- package/dist/integrations/dsh/host.d.ts +53 -0
- package/dist/integrations/dsh/host.js +237 -0
- package/dist/integrations/dsh/mcpClient.d.ts +66 -0
- package/dist/integrations/dsh/mcpClient.js +192 -0
- package/dist/utils/errorCodes.d.ts +28 -0
- package/dist/utils/errorCodes.js +7 -0
- package/dist/vendor/electron/shared/remote-device-agent.d.ts +2 -0
- package/package.json +9 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { McpStdioClient } from './mcpClient.js';
|
|
3
|
+
/**
|
|
4
|
+
* Host half of the Dinox editor plugin for DeepSeek Harness (dsh) Desktop.
|
|
5
|
+
*
|
|
6
|
+
* It is only an adapter: a long-lived `dino editor mcp` child owns nothing but
|
|
7
|
+
* the connection to the daemon, which owns every editor session. This plugin
|
|
8
|
+
* - registers the editor's model tools as dsh tools, keyed by the calling
|
|
9
|
+
* agent's session (`dsh:<sessionId>`);
|
|
10
|
+
* - serves `/dinox-editor/*` for the sidebar tab (same-origin JSON only);
|
|
11
|
+
* - queues the user's selection as context for the agent's next step.
|
|
12
|
+
*
|
|
13
|
+
* It imports Node built-ins only: the profile cannot resolve our dependencies.
|
|
14
|
+
*/
|
|
15
|
+
export declare const name = "dinox-editor";
|
|
16
|
+
export declare const inject: string[];
|
|
17
|
+
export declare const ROUTE = "/dinox-editor";
|
|
18
|
+
type Disposer = () => void;
|
|
19
|
+
/** The slice of the Cordis context this plugin uses (verified against dsh 0.2.1-rc.5). */
|
|
20
|
+
export type DshContext = {
|
|
21
|
+
effect(callback: () => Disposer | void): unknown;
|
|
22
|
+
tools: {
|
|
23
|
+
register(definition: Record<string, unknown>): Disposer;
|
|
24
|
+
};
|
|
25
|
+
webServer: {
|
|
26
|
+
register(route: {
|
|
27
|
+
kind: 'prefix' | 'exact';
|
|
28
|
+
path: string;
|
|
29
|
+
handler: (req: IncomingMessage, res: ServerResponse) => unknown;
|
|
30
|
+
}): Disposer;
|
|
31
|
+
};
|
|
32
|
+
agents: {
|
|
33
|
+
get(sessionId: string): {
|
|
34
|
+
inject(message: unknown): unknown;
|
|
35
|
+
} | undefined;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type HostOptions = {
|
|
39
|
+
/** Overrides the `dino editor mcp` command (tests). */
|
|
40
|
+
client?: Pick<McpStdioClient, 'listTools' | 'callTool' | 'close'>;
|
|
41
|
+
/** Debounce before a changed selection is queued for the agent. */
|
|
42
|
+
contextDebounceMs?: number;
|
|
43
|
+
log?: (message: string) => void;
|
|
44
|
+
};
|
|
45
|
+
type Runtime = {
|
|
46
|
+
node: string;
|
|
47
|
+
cli: string;
|
|
48
|
+
};
|
|
49
|
+
/** Where `dino` lives: recorded by the build / `dino editor install dsh`, else next to this plugin. */
|
|
50
|
+
export declare function resolveRuntime(pluginLib?: string, env?: NodeJS.ProcessEnv): Runtime;
|
|
51
|
+
export declare function apply(ctx: DshContext, options?: HostOptions): void;
|
|
52
|
+
export declare function allowedOrigin(req: Pick<IncomingMessage, 'headers'>): boolean;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { McpStdioClient, resultText, toDshSchema } from './mcpClient.js';
|
|
6
|
+
/**
|
|
7
|
+
* Host half of the Dinox editor plugin for DeepSeek Harness (dsh) Desktop.
|
|
8
|
+
*
|
|
9
|
+
* It is only an adapter: a long-lived `dino editor mcp` child owns nothing but
|
|
10
|
+
* the connection to the daemon, which owns every editor session. This plugin
|
|
11
|
+
* - registers the editor's model tools as dsh tools, keyed by the calling
|
|
12
|
+
* agent's session (`dsh:<sessionId>`);
|
|
13
|
+
* - serves `/dinox-editor/*` for the sidebar tab (same-origin JSON only);
|
|
14
|
+
* - queues the user's selection as context for the agent's next step.
|
|
15
|
+
*
|
|
16
|
+
* It imports Node built-ins only: the profile cannot resolve our dependencies.
|
|
17
|
+
*/
|
|
18
|
+
export const name = 'dinox-editor';
|
|
19
|
+
export const inject = ['tools', 'webServer', 'agents'];
|
|
20
|
+
export const ROUTE = '/dinox-editor';
|
|
21
|
+
const SESSION_PREFIX = 'dsh:';
|
|
22
|
+
const MAX_BODY = 8 * 1024 * 1024;
|
|
23
|
+
const MAX_WAIT_MS = 25_000;
|
|
24
|
+
const UI_METHODS = new Set(['sync', 'save', 'resolve', 'search', 'open', 'log', 'catalog', 'updateMeta']);
|
|
25
|
+
const SESSION_META_KEY = 'dinox.ai/editorSession';
|
|
26
|
+
/** Where `dino` lives: recorded by the build / `dino editor install dsh`, else next to this plugin. */
|
|
27
|
+
export function resolveRuntime(pluginLib = path.dirname(fileURLToPath(import.meta.url)), env = process.env) {
|
|
28
|
+
const fallbackCli = path.resolve(pluginLib, '..', '..', 'dinox.js');
|
|
29
|
+
let recorded = {};
|
|
30
|
+
try {
|
|
31
|
+
recorded = JSON.parse(readFileSync(path.join(pluginLib, '..', 'runtime.json'), 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Missing or unreadable: use the defaults.
|
|
35
|
+
}
|
|
36
|
+
const node = env.DINOX_EDITOR_NODE || (recorded.node && existsSync(recorded.node) ? recorded.node : process.execPath);
|
|
37
|
+
const cli = env.DINOX_EDITOR_CLI || (recorded.cli && existsSync(recorded.cli) ? recorded.cli : fallbackCli);
|
|
38
|
+
return { node, cli };
|
|
39
|
+
}
|
|
40
|
+
const log = (message) => console.error(`[dinox-editor] ${message}`);
|
|
41
|
+
export function apply(ctx, options = {}) {
|
|
42
|
+
const write = options.log ?? log;
|
|
43
|
+
const client = options.client ?? (() => {
|
|
44
|
+
const runtime = resolveRuntime();
|
|
45
|
+
return new McpStdioClient({ command: runtime.node, args: [runtime.cli, 'editor', 'mcp', '--session', 'dsh'], log: write });
|
|
46
|
+
})();
|
|
47
|
+
ctx.effect(() => () => client.close());
|
|
48
|
+
const call = async (method, params, timeoutMs) => {
|
|
49
|
+
const result = await client.callTool('dinox_editor_rpc', { method, params }, { timeoutMs });
|
|
50
|
+
if (result.isError)
|
|
51
|
+
resultText(result);
|
|
52
|
+
return result.structuredContent?.value;
|
|
53
|
+
};
|
|
54
|
+
// ---- model tools: whatever `dino editor mcp` offers the model ---------------------------
|
|
55
|
+
const registerTools = async () => {
|
|
56
|
+
const tools = await client.listTools();
|
|
57
|
+
for (const tool of tools) {
|
|
58
|
+
if (isAppOnly(tool))
|
|
59
|
+
continue;
|
|
60
|
+
ctx.effect(() => ctx.tools.register(dshTool(tool, client)));
|
|
61
|
+
}
|
|
62
|
+
write(`registered ${tools.filter(tool => !isAppOnly(tool)).length} editor tools`);
|
|
63
|
+
};
|
|
64
|
+
void retry(registerTools, write);
|
|
65
|
+
// ---- selection context -----------------------------------------------------------------
|
|
66
|
+
const debounce = options.contextDebounceMs ?? 1200;
|
|
67
|
+
const contexts = new Map();
|
|
68
|
+
const queueContext = (sessionId, text) => {
|
|
69
|
+
const entry = contexts.get(sessionId) ?? { timer: null, last: '' };
|
|
70
|
+
contexts.set(sessionId, entry);
|
|
71
|
+
if (entry.timer)
|
|
72
|
+
clearTimeout(entry.timer);
|
|
73
|
+
entry.timer = setTimeout(() => {
|
|
74
|
+
entry.timer = null;
|
|
75
|
+
// agent.inject appends a message (it does not replace like MCP Apps'
|
|
76
|
+
// model context), so only a changed selection is worth a message.
|
|
77
|
+
if (text === entry.last)
|
|
78
|
+
return;
|
|
79
|
+
entry.last = text;
|
|
80
|
+
const agent = ctx.agents.get(sessionId);
|
|
81
|
+
if (!agent)
|
|
82
|
+
return;
|
|
83
|
+
void Promise.resolve(agent.inject(contextMessage(text))).catch((error) => write(`context not delivered: ${message(error)}`));
|
|
84
|
+
}, debounce);
|
|
85
|
+
};
|
|
86
|
+
ctx.effect(() => () => {
|
|
87
|
+
for (const entry of contexts.values())
|
|
88
|
+
if (entry.timer)
|
|
89
|
+
clearTimeout(entry.timer);
|
|
90
|
+
});
|
|
91
|
+
// ---- routes for the sidebar tab ----------------------------------------------------------
|
|
92
|
+
ctx.effect(() => ctx.webServer.register({
|
|
93
|
+
kind: 'prefix',
|
|
94
|
+
path: ROUTE,
|
|
95
|
+
handler: async (req, res) => {
|
|
96
|
+
try {
|
|
97
|
+
const action = new URL(req.url ?? '/', 'http://dsh.invalid').pathname.slice(ROUTE.length + 1);
|
|
98
|
+
if (action !== 'rpc' && action !== 'opens' && action !== 'context')
|
|
99
|
+
return send(res, 404, { error: { message: 'Unknown route' } });
|
|
100
|
+
if (req.method !== 'POST') {
|
|
101
|
+
res.setHeader('Allow', 'POST');
|
|
102
|
+
return send(res, 405, { error: { message: 'Method not allowed' } });
|
|
103
|
+
}
|
|
104
|
+
// Only the Desktop page itself (custom scheme, or the host's own origin) may call in.
|
|
105
|
+
if (!allowedOrigin(req))
|
|
106
|
+
return send(res, 403, { error: { message: 'Cross-origin request refused' } });
|
|
107
|
+
if (!String(req.headers['content-type'] ?? '').toLowerCase().startsWith('application/json')) {
|
|
108
|
+
return send(res, 415, { error: { message: 'Expected application/json' } });
|
|
109
|
+
}
|
|
110
|
+
const body = await readJson(req);
|
|
111
|
+
if (action === 'opens') {
|
|
112
|
+
const waitMs = clampWait(body.waitMs);
|
|
113
|
+
const value = await call('watchOpens', { cursor: body.cursor, waitMs }, waitMs + 15_000);
|
|
114
|
+
const opens = value.opens
|
|
115
|
+
.filter(open => open.session.startsWith(SESSION_PREFIX))
|
|
116
|
+
.map(open => ({ ...open, sessionId: open.session.slice(SESSION_PREFIX.length) }));
|
|
117
|
+
return send(res, 200, { value: { cursor: value.cursor, opens } });
|
|
118
|
+
}
|
|
119
|
+
const sessionId = typeof body.sessionId === 'string' && body.sessionId ? body.sessionId : null;
|
|
120
|
+
if (!sessionId)
|
|
121
|
+
return send(res, 400, { error: { message: 'sessionId is required' } });
|
|
122
|
+
if (action === 'context') {
|
|
123
|
+
if (typeof body.text === 'string')
|
|
124
|
+
queueContext(sessionId, body.text.slice(0, 4000));
|
|
125
|
+
return send(res, 200, { value: { ok: true } });
|
|
126
|
+
}
|
|
127
|
+
const method = String(body.method);
|
|
128
|
+
if (!UI_METHODS.has(method))
|
|
129
|
+
return send(res, 400, { error: { message: `Unknown editor method ${method}` } });
|
|
130
|
+
const params = body.params && typeof body.params === 'object' && !Array.isArray(body.params) ? body.params : {};
|
|
131
|
+
const waitMs = method === 'sync' ? clampWait(params.waitMs) : 0;
|
|
132
|
+
// The tab can only reach its own session.
|
|
133
|
+
const forwarded = { ...params, session: SESSION_PREFIX + sessionId, ...(method === 'sync' ? { waitMs } : {}) };
|
|
134
|
+
const value = await call(method, forwarded, method === 'sync' ? waitMs + 15_000 : 40_000);
|
|
135
|
+
return send(res, 200, { value });
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (res.writableEnded)
|
|
139
|
+
return;
|
|
140
|
+
const status = error.status ?? 502;
|
|
141
|
+
send(res, status, { error: { message: message(error) } });
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
function isAppOnly(tool) {
|
|
147
|
+
const visibility = tool._meta?.ui?.visibility;
|
|
148
|
+
return Array.isArray(visibility) && !visibility.includes('model');
|
|
149
|
+
}
|
|
150
|
+
function dshTool(tool, client) {
|
|
151
|
+
return {
|
|
152
|
+
name: tool.name,
|
|
153
|
+
description: `${tool.description ?? ''} The note opens in the Dinox tab of the right sidebar.`.trim(),
|
|
154
|
+
parameters: toDshSchema(tool.inputSchema),
|
|
155
|
+
timeoutMs: 45_000,
|
|
156
|
+
output: {
|
|
157
|
+
schema: { type: 'object', additionalProperties: true },
|
|
158
|
+
render: (_args, value) => [{ type: 'text', text: value?.text ?? '' }],
|
|
159
|
+
},
|
|
160
|
+
execute: async (args, exec) => {
|
|
161
|
+
const sessionId = exec?.agent?.session?.id;
|
|
162
|
+
if (typeof sessionId !== 'string' || !sessionId)
|
|
163
|
+
throw new Error('This tool needs an agent session');
|
|
164
|
+
const result = await client.callTool(tool.name, args ?? {}, { meta: { [SESSION_META_KEY]: SESSION_PREFIX + sessionId } });
|
|
165
|
+
return { text: resultText(result) };
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** A queued user-role message with the exact shape dsh 0.2.1-rc.5 expects (deeply frozen). */
|
|
170
|
+
function contextMessage(text) {
|
|
171
|
+
const body = `[Dinox editor] ${text}`;
|
|
172
|
+
return Object.freeze({
|
|
173
|
+
id: randomUUID(),
|
|
174
|
+
role: 'user',
|
|
175
|
+
source: Object.freeze({ kind: 'cordis-host-runner' }),
|
|
176
|
+
content: Object.freeze([Object.freeze({ type: 'text', text: body })]),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async function retry(task, write) {
|
|
180
|
+
for (let attempt = 1;; attempt++) {
|
|
181
|
+
try {
|
|
182
|
+
await task();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
write(`editor tools unavailable (${message(error)}); retrying`);
|
|
187
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(60_000, 1000 * 2 ** attempt)));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export function allowedOrigin(req) {
|
|
192
|
+
const origin = req.headers.origin;
|
|
193
|
+
// Requests without Origin are same-origin GET-like fetches or the Electron forwarder.
|
|
194
|
+
if (!origin)
|
|
195
|
+
return true;
|
|
196
|
+
if (origin === 'dsh-app://app')
|
|
197
|
+
return true;
|
|
198
|
+
try {
|
|
199
|
+
return new URL(origin).host === req.headers.host;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function clampWait(value) {
|
|
206
|
+
return Math.max(0, Math.min(MAX_WAIT_MS, Number(value) || 0));
|
|
207
|
+
}
|
|
208
|
+
async function readJson(req) {
|
|
209
|
+
const chunks = [];
|
|
210
|
+
let size = 0;
|
|
211
|
+
for await (const chunk of req) {
|
|
212
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
213
|
+
size += buffer.length;
|
|
214
|
+
if (size > MAX_BODY)
|
|
215
|
+
throw Object.assign(new Error('Request body exceeds 8MB'), { status: 413 });
|
|
216
|
+
chunks.push(buffer);
|
|
217
|
+
}
|
|
218
|
+
let value;
|
|
219
|
+
try {
|
|
220
|
+
value = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
throw Object.assign(new Error('Request body is not JSON'), { status: 400 });
|
|
224
|
+
}
|
|
225
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
226
|
+
throw Object.assign(new Error('Expected a JSON object'), { status: 400 });
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
function send(res, status, value) {
|
|
230
|
+
res.statusCode = status;
|
|
231
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
232
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
233
|
+
res.end(JSON.stringify(value));
|
|
234
|
+
}
|
|
235
|
+
function message(error) {
|
|
236
|
+
return error instanceof Error ? error.message : String(error);
|
|
237
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* A minimal MCP client over stdio (newline-delimited JSON-RPC) for the dsh
|
|
4
|
+
* plugin's long-lived `dino editor mcp` child. It is bundled into the plugin,
|
|
5
|
+
* which must not import anything but Node built-ins: the dsh Desktop profile
|
|
6
|
+
* cannot resolve our dependencies.
|
|
7
|
+
*
|
|
8
|
+
* The child is started lazily, restarted with backoff after it exits, and a
|
|
9
|
+
* request in flight when it dies fails (never re-sent: it may have been a write).
|
|
10
|
+
*/
|
|
11
|
+
export type McpTool = {
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
inputSchema?: Record<string, unknown>;
|
|
15
|
+
_meta?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
export type McpToolResult = {
|
|
18
|
+
content?: Array<{
|
|
19
|
+
type: string;
|
|
20
|
+
text?: string;
|
|
21
|
+
}>;
|
|
22
|
+
structuredContent?: Record<string, unknown>;
|
|
23
|
+
isError?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type McpClientOptions = {
|
|
26
|
+
command: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
env?: NodeJS.ProcessEnv;
|
|
29
|
+
log?: (message: string) => void;
|
|
30
|
+
/** Delay before the n-th consecutive restart (default: 0.5s doubling up to 30s). */
|
|
31
|
+
backoffMs?: (attempt: number) => number;
|
|
32
|
+
spawnProcess?: typeof spawn;
|
|
33
|
+
};
|
|
34
|
+
export declare class McpStdioClient {
|
|
35
|
+
private readonly options;
|
|
36
|
+
private child;
|
|
37
|
+
private ready;
|
|
38
|
+
private nextId;
|
|
39
|
+
private pending;
|
|
40
|
+
private buffer;
|
|
41
|
+
private failures;
|
|
42
|
+
private retryAt;
|
|
43
|
+
private closed;
|
|
44
|
+
constructor(options: McpClientOptions);
|
|
45
|
+
listTools(): Promise<McpTool[]>;
|
|
46
|
+
callTool(name: string, args: Record<string, unknown>, options?: {
|
|
47
|
+
meta?: Record<string, unknown>;
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
}): Promise<McpToolResult>;
|
|
50
|
+
close(): void;
|
|
51
|
+
private request;
|
|
52
|
+
private connect;
|
|
53
|
+
private start;
|
|
54
|
+
private send;
|
|
55
|
+
private notify;
|
|
56
|
+
private onData;
|
|
57
|
+
private failAll;
|
|
58
|
+
}
|
|
59
|
+
/** Text of a tool result, or its error as an exception. */
|
|
60
|
+
export declare function resultText(result: McpToolResult): string;
|
|
61
|
+
/**
|
|
62
|
+
* dsh tools accept a strict JSON Schema subset (type, oneOf, properties,
|
|
63
|
+
* required, additionalProperties, items, enum, const + annotations) and reject
|
|
64
|
+
* anything else. The MCP server still validates the full schema.
|
|
65
|
+
*/
|
|
66
|
+
export declare function toDshSchema(schema: unknown): Record<string, unknown>;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
const PROTOCOL_VERSION = '2025-06-18';
|
|
3
|
+
export class McpStdioClient {
|
|
4
|
+
options;
|
|
5
|
+
child = null;
|
|
6
|
+
ready = null;
|
|
7
|
+
nextId = 1;
|
|
8
|
+
pending = new Map();
|
|
9
|
+
buffer = '';
|
|
10
|
+
failures = 0;
|
|
11
|
+
retryAt = 0;
|
|
12
|
+
closed = false;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
async listTools() {
|
|
17
|
+
const result = await this.request('tools/list', {}, 30_000);
|
|
18
|
+
return result.tools ?? [];
|
|
19
|
+
}
|
|
20
|
+
async callTool(name, args, options = {}) {
|
|
21
|
+
const params = { name, arguments: args };
|
|
22
|
+
if (options.meta)
|
|
23
|
+
params._meta = options.meta;
|
|
24
|
+
return await this.request('tools/call', params, options.timeoutMs ?? 40_000);
|
|
25
|
+
}
|
|
26
|
+
close() {
|
|
27
|
+
this.closed = true;
|
|
28
|
+
this.failAll(new Error('The Dinox editor connection closed'));
|
|
29
|
+
this.child?.kill();
|
|
30
|
+
this.child = null;
|
|
31
|
+
this.ready = null;
|
|
32
|
+
}
|
|
33
|
+
async request(method, params, timeoutMs) {
|
|
34
|
+
await this.connect();
|
|
35
|
+
return this.send(method, params, timeoutMs);
|
|
36
|
+
}
|
|
37
|
+
connect() {
|
|
38
|
+
if (this.closed)
|
|
39
|
+
return Promise.reject(new Error('The Dinox editor connection closed'));
|
|
40
|
+
if (this.ready)
|
|
41
|
+
return this.ready;
|
|
42
|
+
const wait = Math.max(0, this.retryAt - Date.now());
|
|
43
|
+
this.ready = (async () => {
|
|
44
|
+
if (wait)
|
|
45
|
+
await new Promise(resolve => setTimeout(resolve, wait));
|
|
46
|
+
this.start();
|
|
47
|
+
await this.send('initialize', {
|
|
48
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
49
|
+
capabilities: {},
|
|
50
|
+
clientInfo: { name: 'dinox-dsh-editor', version: '1' },
|
|
51
|
+
}, 30_000);
|
|
52
|
+
this.notify('notifications/initialized');
|
|
53
|
+
this.failures = 0;
|
|
54
|
+
})();
|
|
55
|
+
this.ready.catch(() => { this.ready = null; });
|
|
56
|
+
return this.ready;
|
|
57
|
+
}
|
|
58
|
+
start() {
|
|
59
|
+
const spawnProcess = this.options.spawnProcess ?? spawn;
|
|
60
|
+
const child = spawnProcess(this.options.command, this.options.args, {
|
|
61
|
+
env: this.options.env ?? process.env,
|
|
62
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
63
|
+
});
|
|
64
|
+
this.child = child;
|
|
65
|
+
this.buffer = '';
|
|
66
|
+
child.stdout.setEncoding('utf8');
|
|
67
|
+
child.stdout.on('data', (chunk) => this.onData(chunk));
|
|
68
|
+
child.stderr.setEncoding('utf8');
|
|
69
|
+
child.stderr.on('data', (chunk) => {
|
|
70
|
+
const text = chunk.trim();
|
|
71
|
+
if (text)
|
|
72
|
+
this.options.log?.(text.slice(0, 2000));
|
|
73
|
+
});
|
|
74
|
+
const gone = (reason) => {
|
|
75
|
+
if (this.child !== child)
|
|
76
|
+
return;
|
|
77
|
+
this.child = null;
|
|
78
|
+
this.ready = null;
|
|
79
|
+
this.failures++;
|
|
80
|
+
const backoff = this.options.backoffMs ?? (attempt => Math.min(30_000, 500 * 2 ** (attempt - 1)));
|
|
81
|
+
this.retryAt = Date.now() + backoff(this.failures);
|
|
82
|
+
this.failAll(new Error(`The Dinox editor process ${reason}`));
|
|
83
|
+
if (!this.closed)
|
|
84
|
+
this.options.log?.(`dino editor mcp ${reason}; restarting on next use`);
|
|
85
|
+
};
|
|
86
|
+
child.on('error', error => gone(`could not start (${error.message})`));
|
|
87
|
+
child.on('exit', (code, signal) => gone(`exited (${signal ?? code})`));
|
|
88
|
+
child.stdin.on('error', () => undefined);
|
|
89
|
+
}
|
|
90
|
+
send(method, params, timeoutMs) {
|
|
91
|
+
const child = this.child;
|
|
92
|
+
if (!child)
|
|
93
|
+
return Promise.reject(new Error('The Dinox editor process is not running'));
|
|
94
|
+
const id = this.nextId++;
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const timer = setTimeout(() => {
|
|
97
|
+
this.pending.delete(id);
|
|
98
|
+
reject(new Error(`The Dinox editor did not answer ${method} in time`));
|
|
99
|
+
}, timeoutMs);
|
|
100
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
101
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
notify(method) {
|
|
105
|
+
this.child?.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method })}\n`);
|
|
106
|
+
}
|
|
107
|
+
onData(chunk) {
|
|
108
|
+
this.buffer += chunk;
|
|
109
|
+
let newline;
|
|
110
|
+
while ((newline = this.buffer.indexOf('\n')) >= 0) {
|
|
111
|
+
const line = this.buffer.slice(0, newline).trim();
|
|
112
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
113
|
+
if (!line)
|
|
114
|
+
continue;
|
|
115
|
+
let message;
|
|
116
|
+
try {
|
|
117
|
+
message = JSON.parse(line);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
this.options.log?.(`ignored a non-JSON line from dino editor mcp (${line.length} chars)`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (typeof message.method === 'string') {
|
|
124
|
+
// Server-to-client requests (ping, ...): answer so the server never waits on us.
|
|
125
|
+
if (message.id !== undefined) {
|
|
126
|
+
const result = message.method === 'ping' ? {} : undefined;
|
|
127
|
+
const reply = result ? { jsonrpc: '2.0', id: message.id, result } : { jsonrpc: '2.0', id: message.id, error: { code: -32601, message: 'Method not found' } };
|
|
128
|
+
this.child?.stdin.write(`${JSON.stringify(reply)}\n`);
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const pending = typeof message.id === 'number' ? this.pending.get(message.id) : undefined;
|
|
133
|
+
if (!pending)
|
|
134
|
+
continue;
|
|
135
|
+
this.pending.delete(message.id);
|
|
136
|
+
clearTimeout(pending.timer);
|
|
137
|
+
if (message.error)
|
|
138
|
+
pending.reject(new Error(message.error.message || 'The Dinox editor request failed'));
|
|
139
|
+
else
|
|
140
|
+
pending.resolve(message.result);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
failAll(error) {
|
|
144
|
+
for (const [id, pending] of this.pending) {
|
|
145
|
+
clearTimeout(pending.timer);
|
|
146
|
+
pending.reject(error);
|
|
147
|
+
this.pending.delete(id);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Text of a tool result, or its error as an exception. */
|
|
152
|
+
export function resultText(result) {
|
|
153
|
+
const text = (result.content ?? []).map(part => (part.type === 'text' ? part.text ?? '' : '')).join('\n');
|
|
154
|
+
if (result.isError)
|
|
155
|
+
throw new Error(text || 'The Dinox editor request failed');
|
|
156
|
+
return text;
|
|
157
|
+
}
|
|
158
|
+
const SCHEMA_KEYS = new Set(['type', 'oneOf', 'properties', 'required', 'additionalProperties', 'items', 'enum', 'const', 'description', 'title', 'default', 'examples']);
|
|
159
|
+
/**
|
|
160
|
+
* dsh tools accept a strict JSON Schema subset (type, oneOf, properties,
|
|
161
|
+
* required, additionalProperties, items, enum, const + annotations) and reject
|
|
162
|
+
* anything else. The MCP server still validates the full schema.
|
|
163
|
+
*/
|
|
164
|
+
export function toDshSchema(schema) {
|
|
165
|
+
const walk = (node) => {
|
|
166
|
+
if (Array.isArray(node))
|
|
167
|
+
return node.map(walk);
|
|
168
|
+
if (!node || typeof node !== 'object')
|
|
169
|
+
return node;
|
|
170
|
+
const out = {};
|
|
171
|
+
for (const [key, value] of Object.entries(node)) {
|
|
172
|
+
if (!SCHEMA_KEYS.has(key))
|
|
173
|
+
continue;
|
|
174
|
+
if (key === 'properties' && value && typeof value === 'object') {
|
|
175
|
+
out.properties = Object.fromEntries(Object.entries(value).map(([name, child]) => [name, walk(child)]));
|
|
176
|
+
}
|
|
177
|
+
else if (key === 'additionalProperties') {
|
|
178
|
+
// dsh only takes a boolean here.
|
|
179
|
+
out[key] = value !== false;
|
|
180
|
+
}
|
|
181
|
+
else if (key === 'items' || key === 'oneOf') {
|
|
182
|
+
out[key] = walk(value);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
out[key] = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
};
|
|
190
|
+
const root = walk(schema);
|
|
191
|
+
return root && root.type === 'object' ? root : { type: 'object', properties: {} };
|
|
192
|
+
}
|
|
@@ -115,6 +115,34 @@ export declare const ERROR_CODES: {
|
|
|
115
115
|
readonly exitCode: 1;
|
|
116
116
|
readonly description: "The daemon socket could not be reached.";
|
|
117
117
|
};
|
|
118
|
+
readonly EDITOR_ANCHOR_AMBIGUOUS: {
|
|
119
|
+
readonly exitCode: 2;
|
|
120
|
+
readonly description: "The suggestion anchor occurs more than once in the open note.";
|
|
121
|
+
};
|
|
122
|
+
readonly EDITOR_ANCHOR_MISSING: {
|
|
123
|
+
readonly exitCode: 2;
|
|
124
|
+
readonly description: "The suggestion anchor does not occur in the open note.";
|
|
125
|
+
};
|
|
126
|
+
readonly EDITOR_INVALID_DOCUMENT: {
|
|
127
|
+
readonly exitCode: 2;
|
|
128
|
+
readonly description: "The editor document cannot be saved without losing content.";
|
|
129
|
+
};
|
|
130
|
+
readonly EDITOR_NOTE_NOT_OPEN: {
|
|
131
|
+
readonly exitCode: 5;
|
|
132
|
+
readonly description: "The editor session has no open note.";
|
|
133
|
+
};
|
|
134
|
+
readonly EDITOR_STALE_SEQUENCE: {
|
|
135
|
+
readonly exitCode: 5;
|
|
136
|
+
readonly description: "The editor request targets a note the session has since replaced.";
|
|
137
|
+
};
|
|
138
|
+
readonly EDITOR_UNKNOWN_BLOCK: {
|
|
139
|
+
readonly exitCode: 2;
|
|
140
|
+
readonly description: "The suggestion targets a block that is no longer in the open note.";
|
|
141
|
+
};
|
|
142
|
+
readonly EDITOR_UNSAVED_CHANGES: {
|
|
143
|
+
readonly exitCode: 5;
|
|
144
|
+
readonly description: "The editor session has unsaved changes.";
|
|
145
|
+
};
|
|
118
146
|
readonly INTERNAL_ERROR: {
|
|
119
147
|
readonly exitCode: 1;
|
|
120
148
|
readonly description: "Unexpected internal error; not a DinoxError.";
|
package/dist/utils/errorCodes.js
CHANGED
|
@@ -34,6 +34,13 @@ export const ERROR_CODES = {
|
|
|
34
34
|
DAEMON_STOP_FAILED: { exitCode: 1, description: 'The daemon could not be stopped.' },
|
|
35
35
|
DAEMON_UNAVAILABLE: { exitCode: 1, description: 'The daemon is not available for this request.' },
|
|
36
36
|
DAEMON_UNREACHABLE: { exitCode: 1, description: 'The daemon socket could not be reached.' },
|
|
37
|
+
EDITOR_ANCHOR_AMBIGUOUS: { exitCode: 2, description: 'The suggestion anchor occurs more than once in the open note.' },
|
|
38
|
+
EDITOR_ANCHOR_MISSING: { exitCode: 2, description: 'The suggestion anchor does not occur in the open note.' },
|
|
39
|
+
EDITOR_INVALID_DOCUMENT: { exitCode: 2, description: 'The editor document cannot be saved without losing content.' },
|
|
40
|
+
EDITOR_NOTE_NOT_OPEN: { exitCode: 5, description: 'The editor session has no open note.' },
|
|
41
|
+
EDITOR_STALE_SEQUENCE: { exitCode: 5, description: 'The editor request targets a note the session has since replaced.' },
|
|
42
|
+
EDITOR_UNKNOWN_BLOCK: { exitCode: 2, description: 'The suggestion targets a block that is no longer in the open note.' },
|
|
43
|
+
EDITOR_UNSAVED_CHANGES: { exitCode: 5, description: 'The editor session has unsaved changes.' },
|
|
37
44
|
INTERNAL_ERROR: { exitCode: 1, description: 'Unexpected internal error; not a DinoxError.' },
|
|
38
45
|
INVALID_ARGUMENT: { exitCode: 2, description: 'An argument or option value is invalid.' },
|
|
39
46
|
INVALID_PROPERTY_DEF_CONFIG: { exitCode: 1, description: 'A property definition config could not be serialized.' },
|
|
@@ -247,6 +247,8 @@ export interface RemoteDeviceRunStatusRequest {
|
|
|
247
247
|
runId: string;
|
|
248
248
|
threadId: string;
|
|
249
249
|
clientDeviceId: string;
|
|
250
|
+
/** Gateway extension: when `runId` is unknown, answer for the thread's unfinished run. */
|
|
251
|
+
active?: boolean;
|
|
250
252
|
}
|
|
251
253
|
export interface RemoteDeviceRunStatusResponse {
|
|
252
254
|
protocolVersion: typeof REMOTE_DEVICE_PROTOCOL_VERSION;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dinoxx/dinox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"description": "Dinox CLI",
|
|
5
5
|
"main": "dist/dinox.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"bench:startup": "node scripts/bench-startup.mjs",
|
|
8
|
-
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node scripts/add-shebang.mjs",
|
|
8
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node scripts/add-shebang.mjs && node scripts/build-editor.mjs",
|
|
9
9
|
"dev": "tsx src/dinox.ts",
|
|
10
|
+
"editor:preview": "node scripts/editor-preview.mjs",
|
|
10
11
|
"prepublishOnly": "pnpm run skills:check && pnpm run build",
|
|
11
12
|
"publish:npm": "sh ./publish-npm.sh --no-bump",
|
|
12
13
|
"publish:npm:dry-run": "sh ./publish-npm.sh --dry-run --no-bump",
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@agentclientprotocol/sdk": "^1.8.0",
|
|
49
50
|
"@aws-sdk/client-s3": "^3.1021.0",
|
|
51
|
+
"@modelcontextprotocol/ext-apps": "1.7.5",
|
|
50
52
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
51
53
|
"@nats-io/nats-core": "3.4.0",
|
|
52
54
|
"@node-rs/jieba": "^2.0.1",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"@tiptap/extension-text": "^3.20.0",
|
|
78
80
|
"@tiptap/extension-underline": "^3.20.0",
|
|
79
81
|
"@tiptap/markdown": "^3.20.0",
|
|
82
|
+
"@tiptap/pm": "^3.20.0",
|
|
80
83
|
"better-sqlite3": "^12.6.2",
|
|
81
84
|
"commander": "^14.0.3",
|
|
82
85
|
"qrcode": "1.5.4",
|
|
@@ -93,10 +96,14 @@
|
|
|
93
96
|
"sharp": "^0.34.5"
|
|
94
97
|
},
|
|
95
98
|
"devDependencies": {
|
|
99
|
+
"@tiptap/extension-emoji": "3.20.0",
|
|
96
100
|
"@types/better-sqlite3": "^7.6.13",
|
|
97
101
|
"@types/node": "^20.19.0",
|
|
98
102
|
"@types/qrcode": "1.5.6",
|
|
103
|
+
"esbuild": "0.25.12",
|
|
99
104
|
"eslint": "^10.12.0",
|
|
105
|
+
"jsdom": "26.1.0",
|
|
106
|
+
"pele": "1.13.0",
|
|
100
107
|
"tsx": "^4.20.3",
|
|
101
108
|
"typescript": "^5.9.3",
|
|
102
109
|
"typescript-eslint": "^8.71.1"
|