dsh-ide-window 0.3.2 → 0.3.4
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/AGENTS.md +50 -13
- package/CHANGELOG.md +29 -0
- package/README.md +15 -5
- package/client.js +934 -126
- package/index.js +53 -25
- package/locale/en.json +7 -5
- package/locale/zh.json +7 -5
- package/package.json +1 -1
- package/platform/contract.js +4 -2
- package/platform/macos.js +4 -2
- package/platform/windows.js +6 -4
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* connection service answers whether the request may be served at all.
|
|
17
17
|
*/
|
|
18
18
|
import { spawn } from 'node:child_process'
|
|
19
|
-
import { appendFileSync, existsSync, mkdirSync, openSync, fstatSync, readSync, closeSync, readFileSync, readdirSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
19
|
+
import { appendFileSync, existsSync, mkdirSync, openSync, fstatSync, readSync, closeSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
20
20
|
import { fileURLToPath } from 'node:url'
|
|
21
21
|
import { homedir, tmpdir } from 'node:os'
|
|
22
22
|
import { platform } from './platform/index.js'
|
|
@@ -765,6 +765,11 @@ function grepWorkspace(payload) {
|
|
|
765
765
|
|
|
766
766
|
/** Largest JSON request body accepted; `/dsh-ide/kinds` sends a directory of paths. */
|
|
767
767
|
const MAX_BODY_BYTES = 64 * 1024
|
|
768
|
+
/**
|
|
769
|
+
* Screenshot bodies carry the annotated image itself (a data URL), which is
|
|
770
|
+
* hundreds of kilobytes by design; the default cap is for JSON commands.
|
|
771
|
+
*/
|
|
772
|
+
const MAX_SCREENSHOT_BODY_BYTES = 8 * 1024 * 1024
|
|
768
773
|
|
|
769
774
|
/** The four queries the seam exposes; anything else is a caller bug. */
|
|
770
775
|
const OPERATIONS = new Set(['goToDefinition', 'findReferences', 'goToImplementation', 'hover'])
|
|
@@ -853,8 +858,16 @@ export function screenshotLooksPermissionDenied(output) {
|
|
|
853
858
|
* user. The data URL is what the panel previews and what gets pasted into the
|
|
854
859
|
* conversation, so the client never needs a file:// URL.
|
|
855
860
|
*/
|
|
856
|
-
/** The capture is shrunk to a
|
|
861
|
+
/** The capture is shrunk to a JPEG (the platform sets the long edge). */
|
|
857
862
|
const IDE_SCREENSHOT_MAX_BYTES = 1024 * 1024
|
|
863
|
+
/**
|
|
864
|
+
* Capture resolution used by the editor.
|
|
865
|
+
*
|
|
866
|
+
* Bigger than the final 1080p export: the user crops a region, and cropping a
|
|
867
|
+
* 1080p capture would leave a blurry result.
|
|
868
|
+
*/
|
|
869
|
+
/** `null`: keep the capture at the screen's real pixel size. */
|
|
870
|
+
const IDE_SCREENSHOT_EDIT_EDGE = null
|
|
858
871
|
/** JPEG quality ladder: the first result under the budget wins. */
|
|
859
872
|
const IDE_SCREENSHOT_QUALITIES = [80, 70, 60, 50]
|
|
860
873
|
|
|
@@ -866,11 +879,11 @@ const IDE_SCREENSHOT_QUALITIES = [80, 70, 60, 50]
|
|
|
866
879
|
* quality while a text-heavy one steps down. Returns the file that was written,
|
|
867
880
|
* or the PNG when no quality produced a file (the caller still has an image).
|
|
868
881
|
*/
|
|
869
|
-
async function optimizeScreenshot(pngPath) {
|
|
882
|
+
async function optimizeScreenshot(pngPath, longEdge) {
|
|
870
883
|
const jpegPath = pngPath.replace(/\.png$/i, '') + '.jpg'
|
|
871
884
|
let best = null
|
|
872
885
|
for (const quality of IDE_SCREENSHOT_QUALITIES) {
|
|
873
|
-
const { command, args } = platform.imageOptimizeCommand(pngPath, jpegPath, quality)
|
|
886
|
+
const { command, args } = platform.imageOptimizeCommand(pngPath, jpegPath, quality, longEdge)
|
|
874
887
|
const { code, output } = await runProcess(command, args, 20000)
|
|
875
888
|
let bytes = 0
|
|
876
889
|
try {
|
|
@@ -889,6 +902,20 @@ async function optimizeScreenshot(pngPath) {
|
|
|
889
902
|
}
|
|
890
903
|
|
|
891
904
|
export async function captureScreen(payload) {
|
|
905
|
+
// The editor produces the final image in the page; write it out, then copy it.
|
|
906
|
+
if (typeof payload?.copyDataUrl === 'string' && payload.copyDataUrl.startsWith('data:image/')) {
|
|
907
|
+
const comma = payload.copyDataUrl.indexOf(',')
|
|
908
|
+
const binary = Buffer.from(payload.copyDataUrl.slice(comma + 1), 'base64')
|
|
909
|
+
const file = join(tmpdir(), `dsh-ide-shot-${Date.now()}.jpg`)
|
|
910
|
+
writeFileSync(file, binary)
|
|
911
|
+
const clipboard = platform.clipboardImageCommand(file)
|
|
912
|
+
const copied = await runProcess(clipboard.command, clipboard.args, 20000)
|
|
913
|
+
if (copied.code !== 0) {
|
|
914
|
+
logEvent('warn', 'screenshot', 'clipboard copy failed', copied.output)
|
|
915
|
+
throw new RouteError(500, 'clipboard-failed', copied.output.trim() || 'clipboard copy failed')
|
|
916
|
+
}
|
|
917
|
+
return { path: file, copied: true, bytes: binary.length, dataUrl: '' }
|
|
918
|
+
}
|
|
892
919
|
// "只截图" after a capture only needs the existing file on the clipboard.
|
|
893
920
|
if (typeof payload?.copyOf === 'string' && payload.copyOf !== '') {
|
|
894
921
|
const existing = payload.copyOf
|
|
@@ -900,21 +927,20 @@ export async function captureScreen(payload) {
|
|
|
900
927
|
}
|
|
901
928
|
return { path: existing, copied: true, bytes: 0, dataUrl: '' }
|
|
902
929
|
}
|
|
930
|
+
|
|
931
|
+
// One capture path for both runtimes: grab the whole screen, then let the
|
|
932
|
+
// editor frame it. The Host runs on the machine that owns the screen, so this
|
|
933
|
+
// works from a browser tab as well as from the desktop window.
|
|
903
934
|
const target = join(tmpdir(), `dsh-ide-shot-${Date.now()}.png`)
|
|
904
935
|
const { command, args } = platform.screenshotCommand(target)
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
} catch {
|
|
910
|
-
bytes = 0
|
|
911
|
-
}
|
|
912
|
-
if (code !== 0 || bytes === 0) {
|
|
913
|
-
if (screenshotLooksPermissionDenied(output)) {
|
|
914
|
-
throw new RouteError(403, 'no-screen-permission', output.trim() || 'screen recording is not permitted')
|
|
936
|
+
const attempt = await runProcess(command, args, 20000)
|
|
937
|
+
if (attempt.code !== 0) {
|
|
938
|
+
if (screenshotLooksPermissionDenied(attempt.output)) {
|
|
939
|
+
throw new RouteError(403, 'no-screen-permission', attempt.output.trim() || 'screen recording is not permitted')
|
|
915
940
|
}
|
|
916
|
-
throw new RouteError(500, 'capture-failed', output.trim() || `screenshot exited ${code}`)
|
|
941
|
+
throw new RouteError(500, 'capture-failed', attempt.output.trim() || `screenshot exited ${attempt.code}`)
|
|
917
942
|
}
|
|
943
|
+
|
|
918
944
|
if (payload?.copy === true) {
|
|
919
945
|
const clipboard = platform.clipboardImageCommand(target)
|
|
920
946
|
const copied = await runProcess(clipboard.command, clipboard.args, 20000)
|
|
@@ -924,7 +950,8 @@ export async function captureScreen(payload) {
|
|
|
924
950
|
}
|
|
925
951
|
// A raw screen is far too big for a chat attachment: shrink it before it is
|
|
926
952
|
// ever shown or pasted, and keep only the small file on disk.
|
|
927
|
-
|
|
953
|
+
// Native device pixels: the editor displays 1:1 and the crop keeps its detail.
|
|
954
|
+
const optimized = await optimizeScreenshot(target, null)
|
|
928
955
|
try {
|
|
929
956
|
rmSync(target, { force: true })
|
|
930
957
|
} catch {
|
|
@@ -935,12 +962,8 @@ export async function captureScreen(payload) {
|
|
|
935
962
|
}
|
|
936
963
|
const mime = /\.jpe?g$/i.test(optimized.path) ? 'image/jpeg' : 'image/png'
|
|
937
964
|
const dataUrl = `data:${mime};base64,${readFileSync(optimized.path).toString('base64')}`
|
|
938
|
-
logEvent('info', 'screenshot', 'captured', {
|
|
939
|
-
|
|
940
|
-
quality: optimized.quality,
|
|
941
|
-
path: optimized.path,
|
|
942
|
-
})
|
|
943
|
-
// The temp file stays for "只截图" (the notice shows the path).
|
|
965
|
+
logEvent('info', 'screenshot', 'captured', { bytes: optimized.bytes, quality: optimized.quality, path: optimized.path })
|
|
966
|
+
// Two facts the editor needs: the file to keep for "只截图", and the picture.
|
|
944
967
|
return { path: optimized.path, bytes: optimized.bytes, quality: optimized.quality, dataUrl }
|
|
945
968
|
}
|
|
946
969
|
|
|
@@ -999,12 +1022,12 @@ function writeJson(response, status, payload) {
|
|
|
999
1022
|
}
|
|
1000
1023
|
|
|
1001
1024
|
/** Read and parse the request body under a byte cap. */
|
|
1002
|
-
async function readJsonBody(request) {
|
|
1025
|
+
async function readJsonBody(request, limit = MAX_BODY_BYTES) {
|
|
1003
1026
|
const chunks = []
|
|
1004
1027
|
let size = 0
|
|
1005
1028
|
for await (const chunk of request) {
|
|
1006
1029
|
size += chunk.length
|
|
1007
|
-
if (size >
|
|
1030
|
+
if (size > limit) throw new RouteError(413, 'body-too-large', 'request body is too large')
|
|
1008
1031
|
chunks.push(chunk)
|
|
1009
1032
|
}
|
|
1010
1033
|
if (size === 0) return {}
|
|
@@ -1455,7 +1478,12 @@ function createHandler(ctx) {
|
|
|
1455
1478
|
writeJson(response, 404, { ok: false, error: { code: 'not-found', message: 'unknown route' } })
|
|
1456
1479
|
return
|
|
1457
1480
|
}
|
|
1458
|
-
|
|
1481
|
+
// The editor sends the finished image back when copying it: that body is
|
|
1482
|
+
// the picture, not a command, so it gets its own ceiling.
|
|
1483
|
+
const payload = await readJsonBody(
|
|
1484
|
+
request,
|
|
1485
|
+
pathname === ROUTE_SCREENSHOT ? MAX_SCREENSHOT_BODY_BYTES : MAX_BODY_BYTES,
|
|
1486
|
+
)
|
|
1459
1487
|
const value = pathname === ROUTE_GREP
|
|
1460
1488
|
? await grepWorkspace(payload)
|
|
1461
1489
|
: pathname === ROUTE_DIFF
|
package/locale/en.json
CHANGED
|
@@ -230,11 +230,7 @@
|
|
|
230
230
|
"theme_solarized_light": "Solarized Light",
|
|
231
231
|
"theme_intellij_light": "IntelliJ Light",
|
|
232
232
|
"shortcutScreenshot": "Screenshot (can jump to chat)",
|
|
233
|
-
"shotTitle": "Screenshot taken",
|
|
234
233
|
"shotBusy": "Capturing…",
|
|
235
|
-
"shotPreview": "Screenshot preview",
|
|
236
|
-
"shotJump": "Screenshot and jump to chat",
|
|
237
|
-
"shotKeep": "Screenshot only (copy to clipboard)",
|
|
238
234
|
"shotRetry": "Retry",
|
|
239
235
|
"shotFailed": "Screenshot failed",
|
|
240
236
|
"shotNoPermissionTitle": "Cannot capture: Screen Recording permission is missing",
|
|
@@ -245,5 +241,11 @@
|
|
|
245
241
|
"shotCopied": "Screenshot copied to the clipboard",
|
|
246
242
|
"shotNoEditor": "Composer not found: the screenshot is on the clipboard, press ⌘V",
|
|
247
243
|
"shotOpenFailed": "Could not open System Settings. Open it manually: Privacy & Security → Screen Recording",
|
|
248
|
-
"paletteActionScreenshot": "Take a screenshot"
|
|
244
|
+
"paletteActionScreenshot": "Take a screenshot",
|
|
245
|
+
"shotTool_rect": "Box",
|
|
246
|
+
"shotTool_text": "Text",
|
|
247
|
+
"shotUndo": "Undo",
|
|
248
|
+
"shotTextPlaceholder": "Type, then press Enter",
|
|
249
|
+
"shotCopy": "Capture",
|
|
250
|
+
"shotJump": "Capture and open chat"
|
|
249
251
|
}
|
package/locale/zh.json
CHANGED
|
@@ -230,11 +230,7 @@
|
|
|
230
230
|
"theme_solarized_light": "Solarized 浅色",
|
|
231
231
|
"theme_intellij_light": "IntelliJ 浅色",
|
|
232
232
|
"shortcutScreenshot": "截图(可跳转会话)",
|
|
233
|
-
"shotTitle": "截图完成",
|
|
234
233
|
"shotBusy": "正在截图…",
|
|
235
|
-
"shotPreview": "截图预览",
|
|
236
|
-
"shotJump": "截图并跳转会话",
|
|
237
|
-
"shotKeep": "只截图(复制到剪贴板)",
|
|
238
234
|
"shotRetry": "重试",
|
|
239
235
|
"shotFailed": "截图失败",
|
|
240
236
|
"shotNoPermissionTitle": "无法截图:缺少屏幕录制权限",
|
|
@@ -245,5 +241,11 @@
|
|
|
245
241
|
"shotCopied": "截图已复制到剪贴板",
|
|
246
242
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
247
243
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
248
|
-
"paletteActionScreenshot": "截图"
|
|
244
|
+
"paletteActionScreenshot": "截图",
|
|
245
|
+
"shotTool_rect": "矩形",
|
|
246
|
+
"shotTool_text": "文字",
|
|
247
|
+
"shotUndo": "撤销",
|
|
248
|
+
"shotTextPlaceholder": "输入文字后回车",
|
|
249
|
+
"shotCopy": "截图",
|
|
250
|
+
"shotJump": "截图并跳转会话"
|
|
249
251
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ide-window",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "IDEA-style code workspace for DeepSeek Harness: a centre panel with a workspace file tree, editor tabs and live-updating source, while the left navigation column hides.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"icon": "icon.svg",
|
package/platform/contract.js
CHANGED
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
* @property {(path: string) => boolean} needsShell `spawn` needs `shell: true`
|
|
31
31
|
* @property {(path: string) => {command: string, args: string[]}} screenshotCommand
|
|
32
32
|
* Capture the whole screen into that PNG with an OS built-in tool.
|
|
33
|
-
|
|
34
|
-
*
|
|
33
|
+
|
|
34
|
+
* @property {(input: string, output: string, quality: number, longEdge: number) => {command: string, args: string[]}} imageOptimizeCommand
|
|
35
|
+
* Shrink that PNG to a JPEG whose long edge is `longEdge` (1920 = 1080p on a
|
|
36
|
+
* 16:9 screen; the editor keeps a larger capture to crop from), at `quality`.
|
|
35
37
|
* @property {(path: string) => {command: string, args: string[]}} clipboardImageCommand
|
|
36
38
|
* Put that image file on the system clipboard.
|
|
37
39
|
* for this path (Windows blocks `.bat`/`.cmd` without it since CVE-2024-27980).
|
package/platform/macos.js
CHANGED
|
@@ -32,10 +32,12 @@ export const macPlatform = {
|
|
|
32
32
|
screenshotCommand: (path) => ({ command: 'screencapture', args: ['-x', '-t', 'png', String(path ?? '')] }),
|
|
33
33
|
// `sips` ships with macOS: `-Z` fits the long edge and `-s formatOptions` is
|
|
34
34
|
// the JPEG quality. A Retina capture is 5120×2880; 1080p is plenty for chat.
|
|
35
|
-
|
|
35
|
+
// No `-Z` when the caller wants the capture at its native device pixels: the
|
|
36
|
+
// editor shows it 1:1 and the crop is exported as-is.
|
|
37
|
+
imageOptimizeCommand: (input, output, quality, longEdge) => ({
|
|
36
38
|
command: 'sips',
|
|
37
39
|
args: [
|
|
38
|
-
'-Z',
|
|
40
|
+
...(longEdge > 0 ? ['-Z', String(longEdge)] : []),
|
|
39
41
|
'-s', 'format', 'jpeg',
|
|
40
42
|
'-s', 'formatOptions', String(quality),
|
|
41
43
|
String(input ?? ''),
|
package/platform/windows.js
CHANGED
|
@@ -44,9 +44,9 @@ export const windowsPlatform = {
|
|
|
44
44
|
command: 'powershell.exe',
|
|
45
45
|
args: ['-NoProfile', '-NonInteractive', '-Command', windowsScreenshotScript(path)],
|
|
46
46
|
}),
|
|
47
|
-
imageOptimizeCommand: (input, output, quality) => ({
|
|
47
|
+
imageOptimizeCommand: (input, output, quality, longEdge) => ({
|
|
48
48
|
command: 'powershell.exe',
|
|
49
|
-
args: ['-NoProfile', '-NonInteractive', '-Command', windowsOptimizeScript(input, output, quality)],
|
|
49
|
+
args: ['-NoProfile', '-NonInteractive', '-Command', windowsOptimizeScript(input, output, quality, longEdge)],
|
|
50
50
|
}),
|
|
51
51
|
clipboardImageCommand: (path) => ({
|
|
52
52
|
command: 'powershell.exe',
|
|
@@ -70,15 +70,17 @@ function windowsScreenshotScript(path) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/** The PowerShell that shrinks a capture to a 1080p-class JPEG. */
|
|
73
|
-
function windowsOptimizeScript(input, output, quality) {
|
|
73
|
+
function windowsOptimizeScript(input, output, quality, longEdge) {
|
|
74
74
|
const source = String(input ?? '').replace(/'/g, "''")
|
|
75
75
|
const target = String(output ?? '').replace(/'/g, "''")
|
|
76
76
|
const level = Math.min(100, Math.max(10, Number.isFinite(quality) ? quality : 80))
|
|
77
|
+
// `null` / 0 = keep the capture at its native size (no resize step).
|
|
78
|
+
const edge = Number.isFinite(longEdge) && longEdge > 0 ? Math.round(longEdge) : 0
|
|
77
79
|
return [
|
|
78
80
|
'Add-Type -AssemblyName System.Drawing',
|
|
79
81
|
`$source = [System.Drawing.Image]::FromFile('${source}')`,
|
|
80
82
|
'$long = [Math]::Max($source.Width, $source.Height)',
|
|
81
|
-
|
|
83
|
+
`$scale = ${edge > 0 ? `[Math]::Min(1.0, ${edge} / $long)` : '1.0'}`,
|
|
82
84
|
'$width = [int][Math]::Round($source.Width * $scale)',
|
|
83
85
|
'$height = [int][Math]::Round($source.Height * $scale)',
|
|
84
86
|
'$bitmap = New-Object System.Drawing.Bitmap $width, $height',
|