dsh-split-workspace 0.5.0 → 0.9.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/README.md +324 -14
- package/lib/client.js +1286 -52
- package/lib/index.js +269 -6
- package/package.json +17 -5
package/lib/index.js
CHANGED
|
@@ -1,11 +1,274 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host half of dsh-split-workspace.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The split workspace itself lives entirely in the browser. This half adds the
|
|
5
|
+
* one thing a renderer cannot build on its own: a URL for a REAL separate
|
|
6
|
+
* window that shows a single conversation.
|
|
7
|
+
*
|
|
8
|
+
* Why a URL and not a BrowserWindow: DSH Desktop runs this Host in a Node child
|
|
9
|
+
* process (no Electron APIs), and its main window denies `window.open` except
|
|
10
|
+
* for http/https, which it forwards to the system browser. The Host therefore
|
|
11
|
+
* returns the authenticated Web GUI URL (`?token=…`) with a `#dsvWindow=<id>`
|
|
12
|
+
* marker; the renderer opens it, and the client half renders only that one
|
|
13
|
+
* conversation inside the new system window. In the Web profile the same route
|
|
14
|
+
* works and `window.open` opens a normal browser window.
|
|
15
|
+
*
|
|
16
|
+
* It also serves the on-disk plugin version so a running page can notice a
|
|
17
|
+
* freshly installed bundle, and it can close and reopen the Desktop app: DSH
|
|
18
|
+
* production builds have no in-app restart entry, so the split menu's
|
|
19
|
+
* "Restart DSH" action asks this Host to perform the OS-level quit and
|
|
20
|
+
* relaunch (the Host is a Node child of the Electron shell).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { spawn } from "node:child_process";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
25
|
+
import { resolve } from "node:path";
|
|
26
|
+
|
|
27
|
+
const ROUTE_PATH = "/dsv/system-window";
|
|
28
|
+
const VERSION_PATH = "/dsv/version";
|
|
29
|
+
const RESTART_PATH = "/dsv/restart";
|
|
30
|
+
const MAX_BODY_BYTES = 64 * 1024;
|
|
31
|
+
/** The Desktop app has no in-app restart entry in production builds; this
|
|
32
|
+
route recreates that one action at the OS level. */
|
|
33
|
+
const RESTART_COOLDOWN_MS = 15000;
|
|
34
|
+
let lastRestartAt = 0;
|
|
35
|
+
const SESSION_ID = /^[A-Za-z0-9._:@+-]+$/;
|
|
36
|
+
const MAX_SESSION_ID_LENGTH = 256;
|
|
37
|
+
|
|
38
|
+
/** The plugin version currently on disk (not the one this process loaded). */
|
|
39
|
+
function packageVersion() {
|
|
40
|
+
try {
|
|
41
|
+
const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
42
|
+
return typeof manifest.version === "string" && manifest.version !== "" ? manifest.version : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Read and JSON-parse a small request body. */
|
|
49
|
+
function readJsonBody(req) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
let size = 0;
|
|
52
|
+
const chunks = [];
|
|
53
|
+
req.on("data", (chunk) => {
|
|
54
|
+
size += chunk.length;
|
|
55
|
+
if (size > MAX_BODY_BYTES) {
|
|
56
|
+
reject(new Error("request body too large"));
|
|
57
|
+
req.destroy();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
chunks.push(chunk);
|
|
61
|
+
});
|
|
62
|
+
req.on("end", () => {
|
|
63
|
+
try {
|
|
64
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
65
|
+
resolve(text === "" ? {} : JSON.parse(text));
|
|
66
|
+
} catch (error) {
|
|
67
|
+
reject(error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
req.on("error", reject);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function respond(res, status, value) {
|
|
75
|
+
try {
|
|
76
|
+
res.writeHead(status, {
|
|
77
|
+
"content-type": "application/json; charset=utf-8",
|
|
78
|
+
"cache-control": "no-store",
|
|
79
|
+
});
|
|
80
|
+
res.end(JSON.stringify(value));
|
|
81
|
+
} catch {}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** True when this Host was spawned by the DSH Desktop shell. */
|
|
85
|
+
function runningInDesktop() {
|
|
86
|
+
return typeof process.versions.electron === "string" && process.versions.electron !== "";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** POSIX single-quote escaping for one shell word. */
|
|
90
|
+
function shellQuote(value) {
|
|
91
|
+
return "'" + String(value).replace(/'/g, "'\\''") + "'";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The detached command that closes DSH and opens it again.
|
|
96
|
+
*
|
|
97
|
+
* macOS asks the application to quit through AppleScript, so DSH's own quit
|
|
98
|
+
* confirmation (running tasks) still runs. Windows has no comparable public
|
|
99
|
+
* quit entry, so it closes the main window and then terminates the process;
|
|
100
|
+
* the renderer warns before calling this route.
|
|
8
101
|
*/
|
|
102
|
+
export function restartCommand() {
|
|
103
|
+
const pid = process.ppid;
|
|
104
|
+
const executable = process.execPath;
|
|
105
|
+
if (process.platform === "darwin") {
|
|
106
|
+
const appBundle = resolve(executable, "../../..");
|
|
107
|
+
return {
|
|
108
|
+
command: "/bin/sh",
|
|
109
|
+
args: ["-c", [
|
|
110
|
+
"sleep 1",
|
|
111
|
+
`osascript -e 'tell application id "com.deepseek.dsh" to quit' >/dev/null 2>&1 || kill -TERM ${pid} 2>/dev/null`,
|
|
112
|
+
`n=0; while kill -0 ${pid} 2>/dev/null && [ $n -lt 120 ]; do n=$((n+1)); sleep 0.5; done`,
|
|
113
|
+
`open ${shellQuote(appBundle)} >/dev/null 2>&1`,
|
|
114
|
+
].join("; ")],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (process.platform === "win32") {
|
|
118
|
+
const script = [
|
|
119
|
+
"Start-Sleep -Milliseconds 900",
|
|
120
|
+
`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue`,
|
|
121
|
+
"if ($p) { $p.CloseMainWindow() | Out-Null; Start-Sleep -Milliseconds 700 }",
|
|
122
|
+
`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue`,
|
|
123
|
+
`if ($p) { Stop-Process -Id ${pid} -Force -ErrorAction SilentlyContinue }`,
|
|
124
|
+
`for ($i = 0; $i -lt 40; $i++) { if (-not (Get-Process -Id ${pid} -ErrorAction SilentlyContinue)) { break }; Start-Sleep -Milliseconds 250 }`,
|
|
125
|
+
`Start-Process -FilePath '${String(executable).replace(/'/g, "''")}'`,
|
|
126
|
+
].join("; ");
|
|
127
|
+
return {
|
|
128
|
+
command: "powershell.exe",
|
|
129
|
+
args: ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", script],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
command: "/bin/sh",
|
|
134
|
+
args: ["-c", [
|
|
135
|
+
"sleep 1",
|
|
136
|
+
`kill -TERM ${pid} 2>/dev/null`,
|
|
137
|
+
`n=0; while kill -0 ${pid} 2>/dev/null && [ $n -lt 120 ]; do n=$((n+1)); sleep 0.5; done`,
|
|
138
|
+
`setsid ${shellQuote(executable)} >/dev/null 2>&1 &`,
|
|
139
|
+
].join("; ")],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Close and reopen the Desktop app without blocking the HTTP response. */
|
|
144
|
+
function scheduleRestart() {
|
|
145
|
+
const now = Date.now();
|
|
146
|
+
if (now - lastRestartAt < RESTART_COOLDOWN_MS) return false;
|
|
147
|
+
lastRestartAt = now;
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
try {
|
|
150
|
+
const command = restartCommand();
|
|
151
|
+
spawn(command.command, command.args, {
|
|
152
|
+
detached: true,
|
|
153
|
+
stdio: "ignore",
|
|
154
|
+
windowsHide: true,
|
|
155
|
+
}).unref();
|
|
156
|
+
} catch (error) {
|
|
157
|
+
try { console.warn("[dsh-split-workspace] restart failed:", error); } catch {}
|
|
158
|
+
}
|
|
159
|
+
}, 250);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @param {import('@deepseek-ai/cordis').Context} ctx */
|
|
164
|
+
export function apply(ctx) {
|
|
165
|
+
const getService = (name) => {
|
|
166
|
+
try {
|
|
167
|
+
return typeof ctx.get === "function" ? ctx.get(name) : undefined;
|
|
168
|
+
} catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** The current authenticated Web GUI URL with the standalone-window marker. */
|
|
174
|
+
const standaloneUrl = (sessionId) => {
|
|
175
|
+
const app = getService("webApp");
|
|
176
|
+
const connection = getService("connection");
|
|
177
|
+
const origin = app !== null && app !== undefined && typeof app.getAdvertisedUrl === "function"
|
|
178
|
+
? app.getAdvertisedUrl()
|
|
179
|
+
: null;
|
|
180
|
+
if (typeof origin !== "string" || origin === "") return null;
|
|
181
|
+
let base = origin;
|
|
182
|
+
if (connection !== null && connection !== undefined && typeof connection.authenticatedUrl === "function") {
|
|
183
|
+
const authenticated = connection.authenticatedUrl(origin);
|
|
184
|
+
if (typeof authenticated === "string" && authenticated !== "") base = authenticated;
|
|
185
|
+
}
|
|
186
|
+
const url = new URL(base);
|
|
187
|
+
url.hash = "dsvWindow=" + encodeURIComponent(sessionId);
|
|
188
|
+
return url.href;
|
|
189
|
+
};
|
|
9
190
|
|
|
10
|
-
|
|
11
|
-
|
|
191
|
+
ctx.inject(["webServer"], (webCtx) => {
|
|
192
|
+
webCtx.effect(() => {
|
|
193
|
+
const disposeWindow = webCtx.webServer.register({
|
|
194
|
+
kind: "exact",
|
|
195
|
+
path: ROUTE_PATH,
|
|
196
|
+
handler: async (req, res) => {
|
|
197
|
+
if (req.method !== "POST") {
|
|
198
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
let body;
|
|
202
|
+
try {
|
|
203
|
+
body = await readJsonBody(req);
|
|
204
|
+
} catch {
|
|
205
|
+
respond(res, 400, { ok: false, error: "body" });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const sessionId = body !== null && typeof body === "object" ? body.sessionId : undefined;
|
|
209
|
+
if (typeof sessionId !== "string" || sessionId === "" || sessionId.length > MAX_SESSION_ID_LENGTH || !SESSION_ID.test(sessionId)) {
|
|
210
|
+
respond(res, 400, { ok: false, error: "session" });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const url = standaloneUrl(sessionId);
|
|
215
|
+
if (url === null) {
|
|
216
|
+
respond(res, 503, { ok: false, error: "unavailable" });
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
respond(res, 200, { ok: true, url });
|
|
220
|
+
} catch (error) {
|
|
221
|
+
respond(res, 500, { ok: false, error: String(error !== null && error !== undefined && error.message !== undefined ? error.message : error).slice(0, 200) });
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
const disposeVersion = webCtx.webServer.register({
|
|
226
|
+
kind: "exact",
|
|
227
|
+
path: VERSION_PATH,
|
|
228
|
+
handler: (req, res) => {
|
|
229
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
230
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const version = packageVersion();
|
|
234
|
+
if (version === null) {
|
|
235
|
+
respond(res, 503, { ok: false, error: "version" });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
respond(res, 200, { ok: true, version });
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
const disposeRestart = webCtx.webServer.register({
|
|
242
|
+
kind: "exact",
|
|
243
|
+
path: RESTART_PATH,
|
|
244
|
+
handler: (req, res) => {
|
|
245
|
+
if (req.method !== "POST") {
|
|
246
|
+
respond(res, 405, { ok: false, error: "method" });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const origin = req.headers.origin;
|
|
250
|
+
if (typeof origin === "string" && origin !== "" && origin !== "dsh-app://app"
|
|
251
|
+
&& !/^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/iu.test(origin)) {
|
|
252
|
+
respond(res, 403, { ok: false, error: "origin" });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (req.headers["x-dsv-restart"] !== "1") {
|
|
256
|
+
respond(res, 403, { ok: false, error: "confirm" });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (!runningInDesktop()) {
|
|
260
|
+
respond(res, 200, { ok: false, mode: "web", error: "not-desktop" });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const scheduled = scheduleRestart();
|
|
264
|
+
respond(res, 200, { ok: true, mode: "desktop", platform: process.platform, pending: scheduled !== true });
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
return () => {
|
|
268
|
+
try { disposeWindow(); } catch {}
|
|
269
|
+
try { disposeVersion(); } catch {}
|
|
270
|
+
try { disposeRestart(); } catch {}
|
|
271
|
+
};
|
|
272
|
+
}, "split-workspace: host routes");
|
|
273
|
+
});
|
|
274
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-split-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange.",
|
|
5
|
+
"description": "Split-screen workspace for DeepSeek Harness (DSH) Desktop: unlimited native panes, side-by-side, stacked and 2×2 grid layouts, drag to rearrange, movable floating windows, OS-level standalone system windows, and a performance mode for slow machines.",
|
|
6
6
|
"icon": "./icon.svg",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "mhlywxl",
|
|
@@ -64,6 +64,8 @@
|
|
|
64
64
|
"split-pane",
|
|
65
65
|
"multi-pane",
|
|
66
66
|
"multi-session",
|
|
67
|
+
"floating-window",
|
|
68
|
+
"picture-in-picture",
|
|
67
69
|
"panes",
|
|
68
70
|
"workspace",
|
|
69
71
|
"layout",
|
|
@@ -71,10 +73,18 @@
|
|
|
71
73
|
"tiling",
|
|
72
74
|
"desktop",
|
|
73
75
|
"分屏",
|
|
76
|
+
"浮窗",
|
|
74
77
|
"多窗格",
|
|
75
78
|
"多会话",
|
|
76
79
|
"多窗口",
|
|
77
|
-
"
|
|
80
|
+
"独立窗口",
|
|
81
|
+
"田字布局",
|
|
82
|
+
"system-window",
|
|
83
|
+
"standalone-window",
|
|
84
|
+
"系统窗口",
|
|
85
|
+
"performance-mode",
|
|
86
|
+
"性能模式",
|
|
87
|
+
"low-spec"
|
|
78
88
|
],
|
|
79
89
|
"peerDependencies": {
|
|
80
90
|
"react": "^18.0.0"
|
|
@@ -85,8 +95,10 @@
|
|
|
85
95
|
}
|
|
86
96
|
},
|
|
87
97
|
"scripts": {
|
|
88
|
-
"
|
|
89
|
-
"check": "node
|
|
98
|
+
"build": "node scripts/build-client.mjs",
|
|
99
|
+
"build:check": "node scripts/build-client.mjs --check",
|
|
100
|
+
"test": "node scripts/build-client.mjs --check && node test.mjs",
|
|
101
|
+
"check": "node scripts/build-client.mjs --check && node --check lib/client.js && node test.mjs",
|
|
90
102
|
"pack:check": "npm pack --dry-run"
|
|
91
103
|
}
|
|
92
104
|
}
|