mirror of
https://github.com/NanmiCoder/claude-code-haha.git
synced 2026-10-10 11:53:10 +08:00
feat(desktop): preview documents in the workspace and images in chat
Documents the agent writes open in the workspace panel instead of another application, and local images the agent mentions show up in the conversation. Workspace preview - PDF (pdf.js with its own layout and text layer), Word (docx-preview inside a scripts-disabled sandboxed iframe) and Excel (SheetJS; .xlsx, .xlsm, .xls) open in the side panel with zoom and fit, per-file scroll/zoom/sheet memory, and a refresh when the agent rewrites the file. The engines load lazily. - Bytes come from a new GET /api/sessions/:id/workspace/raw route, with an extension allowlist, size caps, the workspace boundary and canonical-path checks. The file endpoint returns metadata and a version for documents. The client fetches with the bearer credential, so it works in Electron, LAN H5 and remote access alike. - Chat links, output cards and the change card open pdf/docx/xlsx in the workspace; documents outside the workdir still go to the system application. - Image viewer with fit, zoom and pan, and "open in system app". Chat images - Markdown images outside the workdir, at ~/, C:\ and file:// paths render, open in the viewer, and offer "open original" (pictures only). - Images returned by tools such as Read appear as thumbnails under the call. Hardening found in review - previewFsUrl escapes each path segment; a double-escaped %2e%2e used to leave /preview-fs/<session>/. - The CORS, API timing and remote-access header decorators set headers in place. Rebuilding the response buffered whole files in memory and dropped Content-Length. - The engine owns the pdf.js worker, so closing one document no longer fails the next open. - Office archives are inflated in steps to check their real sizes, not the sizes they declare. - A viewer that fails to load stays in its panel instead of taking the window down. Adds pdfjs-dist, docx-preview, xlsx (SheetJS 0.20.3 tarball) and fflate as renderer dev dependencies; Vite bundles them. Refs #1397
This commit is contained in:
@@ -27,6 +27,7 @@ Claude 干活时不是一句话回你,中间会插进来几种卡片:
|
||||
- **思考块**:模型在动手前的推理过程,标题写「思考中」,结束后变成「已思考」。默认折叠。
|
||||
- **文件编辑**:直接在对话里显示内联 diff,绿加红减,不用切到别处看。
|
||||
- **Claude 需要你的输入**:它拿不准时会反问,给几个选项按钮,也可以自己输入回答。
|
||||
- **图片**:回复里用 Markdown 图片语法引用的本地图片会直接显示,不限于项目目录内——绝对路径、`~/` 开头的路径、Windows 的 `C:\...` 和 `file:///...` 都可以(位于用户目录或临时目录下的图片)。Claude 用「读取」等工具看过的图片,也会以缩略图的形式出现在那条工具调用下面,不必展开。点开任意一张,可以缩放和拖动;桌面版的查看器右下角有「用系统程序打开」,用来打开原文件。在浏览器里访问(H5)时,按路径引用的本地图片暂时显示不出来,读取工具产生的缩略图不受影响。
|
||||
|
||||
对话很长时,`⌘F` 打开页内查找,可以在当前对话里跳上一个 / 下一个匹配。`⌘K` 是全局搜索,跨所有历史会话找内容。
|
||||
|
||||
|
||||
@@ -35,6 +35,19 @@ order: 2
|
||||
|
||||
任何文件都可以右键复制路径,或者点「添加到聊天」把它作为上下文塞回输入框。
|
||||
|
||||
### 预览 PDF、Word、Excel 和图片
|
||||
|
||||
Claude 生成的报告、论文、数据表不必再切到别的软件去看。在文件标签里选中它们,或者点对话里指向它们的链接和文件卡片,就会直接在工作区里打开:
|
||||
|
||||
- **PDF** — 连续滚动,可以缩放,文字能选中复制。默认适应宽度。
|
||||
- **Word(`.docx`)** — 显示文字和基本排版。公式和部分形状不会出现,预览上方会有提示;需要精确排版时,用「用系统程序打开」打开原文件。
|
||||
- **Excel(`.xlsx`、`.xlsm`、`.xls`)** — 每个工作表一个标签页,单元格按 Excel 中的显示格式呈现。图表、图片和公式不显示;每张表最多显示前 5000 行、100 列,超出时会说明。
|
||||
- **图片** — 适应窗口显示,可以缩放和拖动;按住 `⌘` / `Ctrl` 滚动滚轮或在触控板上捏合来缩放,双击在「适应窗口」和 100% 之间切换。
|
||||
|
||||
预览区顶部的「用系统程序打开」会把原文件交给系统默认程序。太大的文件(PDF 超过 100 MB,Word / Excel 超过 30 MB)和已加密的 PDF 不会预览,同样可以用系统程序打开。工作区之外的文档也一样,直接交给系统程序。
|
||||
|
||||
Claude 重新写入正在预览的文件时,预览会在原位置刷新;文件恰好写到一半、读不出来时,会继续显示上一次的内容并提示刷新失败。
|
||||
|
||||
## Diff 评审:给某一行留话
|
||||
|
||||

|
||||
|
||||
@@ -27,6 +27,7 @@ Claude doesn't just reply with a paragraph. Several kinds of card appear along t
|
||||
- **Thinking blocks** — the reasoning before it acts, labelled **Thinking** while it runs and **Thought** once done. Collapsed by default.
|
||||
- **File edits** — shown as an inline diff right in the conversation, so you don't have to look anywhere else.
|
||||
- **Claude needs your input** — when it's genuinely unsure it asks, with buttons for the likely answers plus a free-text box.
|
||||
- **Images** — a local image a reply references with Markdown image syntax is shown right in the conversation, and it doesn't have to be inside the project: an absolute path, one starting with `~/`, a Windows `C:\...` path or a `file:///...` URL all work (for images under your home directory or the temporary directories). Pictures Claude looked at with a tool such as Read also appear as thumbnails under that tool call, without expanding it. Click any of them to zoom and drag; in the desktop app the viewer has **Open in system app** at the bottom right, which opens the original file. When you use the app from a browser (H5), pictures referenced by path don't load yet; the thumbnails of pictures Claude read with a tool are not affected.
|
||||
|
||||
In a long conversation, `⌘F` opens find-in-page and jumps between matches in the current session. `⌘K` is global search across every session you've ever had.
|
||||
|
||||
|
||||
@@ -35,6 +35,19 @@ If the folder is not a Git repository, the **Review** entry explains why it is u
|
||||
|
||||
Any file can have its path copied, or be pushed back into the composer as context with **Add to chat**.
|
||||
|
||||
### Previewing PDFs, Word, Excel, and images
|
||||
|
||||
Reports, papers, and spreadsheets Claude produces no longer need another app to read. Select one in a Files tab, or click a link or file card that points at it in the conversation, and it opens right in the workspace:
|
||||
|
||||
- **PDF** — scrolls continuously and zooms, with selectable text. It opens fitted to the panel width.
|
||||
- **Word (`.docx`)** — shows the text and basic layout. Equations and some shapes do not appear, and a note above the preview says so; when you need the exact layout, use **Open in system app** to open the original.
|
||||
- **Excel (`.xlsx`, `.xlsm`, `.xls`)** — one tab per worksheet, with each cell shown as Excel formats it. Charts, images, and formulas are not shown. A sheet shows at most its first 5,000 rows and 100 columns, and says so when it is cut off.
|
||||
- **Images** — fitted to the window, with zoom and drag. Hold `⌘` / `Ctrl` and scroll, or pinch on a trackpad, to zoom; double-click to switch between **Fit to window** and 100%.
|
||||
|
||||
**Open in system app** at the top of the preview hands the original file to your system's default program. Files that are too large (PDFs over 100 MB, Word or Excel over 30 MB) and password-protected PDFs are not previewed; open them with the system app the same way. So are documents outside the workspace.
|
||||
|
||||
When Claude rewrites a file you are previewing, the preview refreshes in place. If the file is caught half-written and cannot be read, the last good version stays on screen with a note that the refresh failed.
|
||||
|
||||
## Diff review: leaving a note on a line
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user