dsh-ide-window 0.3.2 → 0.3.3
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 +31 -12
- package/CHANGELOG.md +14 -0
- package/README.md +13 -5
- package/client.js +840 -126
- package/index.js +40 -8
- package/locale/en.json +9 -5
- package/locale/zh.json +9 -5
- package/package.json +1 -1
- package/platform/contract.js +3 -2
- package/platform/macos.js +2 -2
- package/platform/windows.js +5 -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,15 @@ 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
|
+
const IDE_SCREENSHOT_EDIT_EDGE = 2560
|
|
858
870
|
/** JPEG quality ladder: the first result under the budget wins. */
|
|
859
871
|
const IDE_SCREENSHOT_QUALITIES = [80, 70, 60, 50]
|
|
860
872
|
|
|
@@ -866,11 +878,11 @@ const IDE_SCREENSHOT_QUALITIES = [80, 70, 60, 50]
|
|
|
866
878
|
* quality while a text-heavy one steps down. Returns the file that was written,
|
|
867
879
|
* or the PNG when no quality produced a file (the caller still has an image).
|
|
868
880
|
*/
|
|
869
|
-
async function optimizeScreenshot(pngPath) {
|
|
881
|
+
async function optimizeScreenshot(pngPath, longEdge) {
|
|
870
882
|
const jpegPath = pngPath.replace(/\.png$/i, '') + '.jpg'
|
|
871
883
|
let best = null
|
|
872
884
|
for (const quality of IDE_SCREENSHOT_QUALITIES) {
|
|
873
|
-
const { command, args } = platform.imageOptimizeCommand(pngPath, jpegPath, quality)
|
|
885
|
+
const { command, args } = platform.imageOptimizeCommand(pngPath, jpegPath, quality, longEdge)
|
|
874
886
|
const { code, output } = await runProcess(command, args, 20000)
|
|
875
887
|
let bytes = 0
|
|
876
888
|
try {
|
|
@@ -889,6 +901,20 @@ async function optimizeScreenshot(pngPath) {
|
|
|
889
901
|
}
|
|
890
902
|
|
|
891
903
|
export async function captureScreen(payload) {
|
|
904
|
+
// The editor produces the final image in the page; write it out, then copy it.
|
|
905
|
+
if (typeof payload?.copyDataUrl === 'string' && payload.copyDataUrl.startsWith('data:image/')) {
|
|
906
|
+
const comma = payload.copyDataUrl.indexOf(',')
|
|
907
|
+
const binary = Buffer.from(payload.copyDataUrl.slice(comma + 1), 'base64')
|
|
908
|
+
const file = join(tmpdir(), `dsh-ide-shot-${Date.now()}.jpg`)
|
|
909
|
+
writeFileSync(file, binary)
|
|
910
|
+
const clipboard = platform.clipboardImageCommand(file)
|
|
911
|
+
const copied = await runProcess(clipboard.command, clipboard.args, 20000)
|
|
912
|
+
if (copied.code !== 0) {
|
|
913
|
+
logEvent('warn', 'screenshot', 'clipboard copy failed', copied.output)
|
|
914
|
+
throw new RouteError(500, 'clipboard-failed', copied.output.trim() || 'clipboard copy failed')
|
|
915
|
+
}
|
|
916
|
+
return { path: file, copied: true, bytes: binary.length, dataUrl: '' }
|
|
917
|
+
}
|
|
892
918
|
// "只截图" after a capture only needs the existing file on the clipboard.
|
|
893
919
|
if (typeof payload?.copyOf === 'string' && payload.copyOf !== '') {
|
|
894
920
|
const existing = payload.copyOf
|
|
@@ -903,6 +929,7 @@ export async function captureScreen(payload) {
|
|
|
903
929
|
const target = join(tmpdir(), `dsh-ide-shot-${Date.now()}.png`)
|
|
904
930
|
const { command, args } = platform.screenshotCommand(target)
|
|
905
931
|
const { code, output } = await runProcess(command, args, 20000)
|
|
932
|
+
logEvent('info', 'screenshot', 'capture: spawned', { code, bytes: output.length })
|
|
906
933
|
let bytes = 0
|
|
907
934
|
try {
|
|
908
935
|
bytes = statSync(target).size
|
|
@@ -924,7 +951,7 @@ export async function captureScreen(payload) {
|
|
|
924
951
|
}
|
|
925
952
|
// A raw screen is far too big for a chat attachment: shrink it before it is
|
|
926
953
|
// ever shown or pasted, and keep only the small file on disk.
|
|
927
|
-
const optimized = await optimizeScreenshot(target)
|
|
954
|
+
const optimized = await optimizeScreenshot(target, IDE_SCREENSHOT_EDIT_EDGE)
|
|
928
955
|
try {
|
|
929
956
|
rmSync(target, { force: true })
|
|
930
957
|
} catch {
|
|
@@ -999,12 +1026,12 @@ function writeJson(response, status, payload) {
|
|
|
999
1026
|
}
|
|
1000
1027
|
|
|
1001
1028
|
/** Read and parse the request body under a byte cap. */
|
|
1002
|
-
async function readJsonBody(request) {
|
|
1029
|
+
async function readJsonBody(request, limit = MAX_BODY_BYTES) {
|
|
1003
1030
|
const chunks = []
|
|
1004
1031
|
let size = 0
|
|
1005
1032
|
for await (const chunk of request) {
|
|
1006
1033
|
size += chunk.length
|
|
1007
|
-
if (size >
|
|
1034
|
+
if (size > limit) throw new RouteError(413, 'body-too-large', 'request body is too large')
|
|
1008
1035
|
chunks.push(chunk)
|
|
1009
1036
|
}
|
|
1010
1037
|
if (size === 0) return {}
|
|
@@ -1455,7 +1482,12 @@ function createHandler(ctx) {
|
|
|
1455
1482
|
writeJson(response, 404, { ok: false, error: { code: 'not-found', message: 'unknown route' } })
|
|
1456
1483
|
return
|
|
1457
1484
|
}
|
|
1458
|
-
|
|
1485
|
+
// The editor sends the finished image back when copying it: that body is
|
|
1486
|
+
// the picture, not a command, so it gets its own ceiling.
|
|
1487
|
+
const payload = await readJsonBody(
|
|
1488
|
+
request,
|
|
1489
|
+
pathname === ROUTE_SCREENSHOT ? MAX_SCREENSHOT_BODY_BYTES : MAX_BODY_BYTES,
|
|
1490
|
+
)
|
|
1459
1491
|
const value = pathname === ROUTE_GREP
|
|
1460
1492
|
? await grepWorkspace(payload)
|
|
1461
1493
|
: 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,13 @@
|
|
|
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
|
+
"shotSelectHint": "Press the left button and drag to frame the area; release to finish, Esc cancels.",
|
|
246
|
+
"shotMarkHint": "Drag inside the frame to draw a box, or pick Text and click to type. ⌘Z undoes, Esc closes.",
|
|
247
|
+
"shotTool_rect": "Box",
|
|
248
|
+
"shotTool_text": "Text",
|
|
249
|
+
"shotUndo": "Undo",
|
|
250
|
+
"shotTextPlaceholder": "Type, then press Enter",
|
|
251
|
+
"shotCopy": "Capture",
|
|
252
|
+
"shotJump": "Capture and open chat"
|
|
249
253
|
}
|
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,13 @@
|
|
|
245
241
|
"shotCopied": "截图已复制到剪贴板",
|
|
246
242
|
"shotNoEditor": "没找到对话框:截图已复制到剪贴板,按 ⌘V 粘贴",
|
|
247
243
|
"shotOpenFailed": "打不开系统设置,请手动打开:系统设置 → 隐私与安全性 → 屏幕录制",
|
|
248
|
-
"paletteActionScreenshot": "截图"
|
|
244
|
+
"paletteActionScreenshot": "截图",
|
|
245
|
+
"shotSelectHint": "按住鼠标左键拖动,框出要截的范围;松开后完成选框,Esc 取消",
|
|
246
|
+
"shotMarkHint": "在选框内拖动可画矩形,选「文字」后点一下输入;⌘Z 撤销,Esc 关闭",
|
|
247
|
+
"shotTool_rect": "矩形",
|
|
248
|
+
"shotTool_text": "文字",
|
|
249
|
+
"shotUndo": "撤销",
|
|
250
|
+
"shotTextPlaceholder": "输入文字后回车",
|
|
251
|
+
"shotCopy": "截图",
|
|
252
|
+
"shotJump": "截图并跳转会话"
|
|
249
253
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ide-window",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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,9 @@
|
|
|
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
|
-
* @property {(input: string, output: string, quality: number) => {command: string, args: string[]}} imageOptimizeCommand
|
|
34
|
-
* Shrink that PNG to a
|
|
33
|
+
* @property {(input: string, output: string, quality: number, longEdge: number) => {command: string, args: string[]}} imageOptimizeCommand
|
|
34
|
+
* Shrink that PNG to a JPEG whose long edge is `longEdge` (1920 = 1080p on a
|
|
35
|
+
* 16:9 screen; the editor keeps a larger capture to crop from), at `quality`.
|
|
35
36
|
* @property {(path: string) => {command: string, args: string[]}} clipboardImageCommand
|
|
36
37
|
* Put that image file on the system clipboard.
|
|
37
38
|
* for this path (Windows blocks `.bat`/`.cmd` without it since CVE-2024-27980).
|
package/platform/macos.js
CHANGED
|
@@ -32,10 +32,10 @@ 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
|
-
imageOptimizeCommand: (input, output, quality) => ({
|
|
35
|
+
imageOptimizeCommand: (input, output, quality, longEdge) => ({
|
|
36
36
|
command: 'sips',
|
|
37
37
|
args: [
|
|
38
|
-
'-Z',
|
|
38
|
+
'-Z', String(longEdge ?? 1920),
|
|
39
39
|
'-s', 'format', 'jpeg',
|
|
40
40
|
'-s', 'formatOptions', String(quality),
|
|
41
41
|
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,16 @@ 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
|
+
const edge = Number.isFinite(longEdge) && longEdge > 0 ? Math.round(longEdge) : 1920
|
|
77
78
|
return [
|
|
78
79
|
'Add-Type -AssemblyName System.Drawing',
|
|
79
80
|
`$source = [System.Drawing.Image]::FromFile('${source}')`,
|
|
80
81
|
'$long = [Math]::Max($source.Width, $source.Height)',
|
|
81
|
-
|
|
82
|
+
`$scale = [Math]::Min(1.0, ${edge} / $long)`,
|
|
82
83
|
'$width = [int][Math]::Round($source.Width * $scale)',
|
|
83
84
|
'$height = [int][Math]::Round($source.Height * $scale)',
|
|
84
85
|
'$bitmap = New-Object System.Drawing.Bitmap $width, $height',
|