UndeadSheep/dsh-file-preview--packages-dsh-file-preview ↗★ 1

@undeadsheep/dsh-file-preview

提供工作区文件树列出、文本读写及预览的宿主端服务。 作为文件预览插件的后端服务,适合需要通过宿主RPC管理和读取工作区文件的开发者。

套件
@undeadsheep/dsh-file-preview
相容性
待驗證
Harness 依賴範圍
^0.1.0-rc.6
Cordis 依賴範圍
^4.0.1
版本
0.1.2
授權
MIT
最近更新
2026年8月18日

安裝

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:UndeadSheep/dsh-file-preview#9b3689bf214cd54779a9da3a9effc3b4f128a2ac&path:packages/dsh-file-preview

@undeadsheep/dsh-file-preview

Workspace file-preview host half: a Typert Remote (filePreview) that lists the workspace tree, reads/writes text files, and resolves the preview theme and config for the browser half.

The browser UI lives in a separate package: @undeadsheep/dsh-client-ui-file-preview.

Remote surface

MethodRequestResult
listDir{ sessionId, path }Ok | Rejected
readFile{ sessionId, path }Ok | Rejected
readImage{ sessionId, path }Ok | Rejected
writeFile{ sessionId, path, content }Ok | Rejected
readTheme{ sessionId }Ok
readConfig{ sessionId }Ok

Business results use the repo's { ok: true, value } | { ok: false, error: { code, ... } } convention; the generated ./remote face wraps them in the RemoteResult carrier. Wire codecs are generated from the @Remote method types by typert codegen — there is no hand-written schema file.

listDir lists a single directory (path = '' for the workspace root) and skips heavy/noise directories (node_modules, .git, .next, .ssh, …) plus sensitive filenames (.env*, id_rsa*, *.pem, *.key, …). A single listing is capped at 1000 children. Dir nodes carry empty children, which the browser half fills lazily by calling listDir again when a directory is expanded. readFile / readImage / writeFile also refuse those sensitive paths, so typing them in Quick Open does not bypass the tree filter.

Config

KeyDefaultMeaning
maxFileBytes2097152Maximum UTF-8 byte length the preview will read or write
maxImageBytes5242880Maximum byte length of an inline image the preview will read

Workspace config files (read per Session, optional)

  • preview.config.json — indentSize, useTabs, pollInterval, fontSize (with .prettierrc / package.json#prettier fallback for indent knobs)
  • preview-theme.json — keyword, string, number, comment, tag, function, type, variable, background, foreground
  • .vscode/settings.json — editor.tokenColorCustomizations and workbench.colorCustomizations are read as a fallback theme

Known limitations

  • Preview is text-only (plus raster png/jpeg/gif/webp); binary, SVG-as-image, or oversized files return not-text / too-large. A stat with no size is refused rather than reading the whole file into memory. Writes use the same byte cap as text reads.
  • listDir returns at most 1000 children per directory.
  • Symlink following after resolve is the host ctx.fs implementation's responsibility; this plugin re-resolves search children against workspaceRoot but cannot realpath on its own.
  • Syntax highlighting is a lightweight hand-written tokenizer (not highlight.js / TextMate), and a prettier engine cannot be embedded.
  • Auto-refresh is polling (pollInterval, clamped 500–60000 ms), not a real file watcher.