From 41df9ea5ec6e4ef10b0c26bf7925b2bfc39be2ba Mon Sep 17 00:00:00 2001 From: lehhair Date: Mon, 2 Nov 2026 09:21:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(attachment):=20=E6=9C=AC=E6=9C=BA?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=BC=95=E7=94=A8=E5=8F=AA=E5=86=99=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=95=B4=E4=BB=BD=E8=AF=BB?= =?UTF-8?q?=E8=BF=9B=20prompt.files[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 拖入和 @ 选中的文件都带 `@path` 文本,同时又进了 prompt.files[], 服务端会按 file:// 把整份文件读进内存——超过 20MB 直接以 `Attachment exceeds the 20971520 byte limit` 失败。 对齐官方 composer 的 path 部件:这类附件只作路径引用,模型需要时 用工具读。同时补一层兜底:用户把 `@path` 从文本里删掉但 chip 还在时, 发送前把路径引用加回去,否则 pathOnly 附件模型完全看不到。 (cherry picked from commit 983bb028870d936b749a60d01ac668cabab2e9a3) --- src/api/message.test.ts | 21 ++++++++++++++++ src/api/message.ts | 25 +++++++++++++------ src/features/chat/InputBox.tsx | 19 +++++++++++--- .../chat/InputBoxAttachments.test.tsx | 6 ++++- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/api/message.test.ts b/src/api/message.test.ts index 09b797c9..8c56fd6c 100644 --- a/src/api/message.test.ts +++ b/src/api/message.test.ts @@ -299,6 +299,27 @@ describe('sendMessage — 路径型附件的文本引用', () => { expect(payload.metadata?.attachments).toBeUndefined() }) + it('带 mention 的附件被从文本删掉后仍补路径(pathOnly 只能靠文本可见)', async () => { + await sendMessage({ + ...baseParams(), + text: '看下这个', + attachments: [ + { + id: 'a1', + type: 'file', + displayName: 'foo.ts', + url: 'file:///proj/src/foo.ts', + pathOnly: true, + textRange: { value: '@src/foo.ts', start: 0, end: 11 }, + }, + ] as never, + }) + + const payload = lastPromptPayload() + expect(payload.files).toBeUndefined() + expect(payload.text).toBe('看下这个\nAttached file: `/proj/src/foo.ts`') + }) + it('revert 回填的文本里已有同一引用时不重复追加', async () => { const path = '/tmp/opencode/uploads/u1/report.zip' await sendMessage({ diff --git a/src/api/message.ts b/src/api/message.ts index d82d1648..5492ce1e 100644 --- a/src/api/message.ts +++ b/src/api/message.ts @@ -273,14 +273,20 @@ export function fileUrlToAbsolutePath(url: string): string | undefined { } /** - * 路径型附件:`file://` 引用且**不带 mention**。 + * 路径型附件:`file://` 引用。 * - * 带 mention 的附件(`@` 提及、侧边栏拖入)路径已经在文本里,再补一行 - * 路径引用纯属噪声——官方也是这么区分的(path 部件 vs file 部件)。 + * 带 mention 的附件(`@` 提及、拖入)路径已经在文本里,不再补一行引用 + * ——官方也是这么区分的(path 部件 vs file 部件)。 + * + * 但 pathOnly 附件不会进 `prompt.files[]`,文本是模型看到它的唯一途径。 + * 如果用户把 `@path` 那段删掉了(chip 还在),这里必须补回去, + * 否则模型完全看不到这个附件。 */ -export function isPathReferenceAttachment(attachment: Attachment): boolean { +export function isPathReferenceAttachment(attachment: Attachment, text?: string): boolean { if (attachment.type !== 'file') return false - if (attachment.textRange) return false + if (attachment.textRange) { + return text !== undefined && !text.includes(attachment.textRange.value) + } return Boolean(attachment.url?.startsWith('file://')) } @@ -291,11 +297,14 @@ export function attachmentReferencePath(attachment: Attachment): string | undefi } /** 收集路径引用(去重、保序) */ -export function buildAttachmentReferences(attachments: Attachment[]): PromptAttachmentReference[] { +export function buildAttachmentReferences( + attachments: Attachment[], + text?: string, +): PromptAttachmentReference[] { const references: PromptAttachmentReference[] = [] for (const attachment of attachments) { - if (!isPathReferenceAttachment(attachment)) continue + if (!isPathReferenceAttachment(attachment, text)) continue const path = attachmentReferencePath(attachment) if (!path) continue @@ -384,7 +393,7 @@ function buildPromptInput( const { files, agents, skills } = buildPromptParts(params.attachments) // 路径型附件额外把绝对路径写进文本(官方 request.ts:173-182 同款): // files[].uri 只让服务端读到字节,模型能否看到取决于 mime(见文件顶部说明)。 - const attachmentReferences = buildAttachmentReferences(params.attachments) + const attachmentReferences = buildAttachmentReferences(params.attachments, params.text) return { sessionID, diff --git a/src/features/chat/InputBox.tsx b/src/features/chat/InputBox.tsx index 20192033..1b9150a3 100644 --- a/src/features/chat/InputBox.tsx +++ b/src/features/chat/InputBox.tsx @@ -1246,6 +1246,9 @@ function InputBoxComponent({ mime: item.type === 'reference' ? 'application/x-directory' : item.type !== 'agent' ? 'text/plain' : undefined, agentName: item.type === 'agent' ? item.displayName : undefined, skillId: item.type === 'skill' ? item.value : undefined, + // 物理路径引用只写路径(官方 composer 的 path 部件):`@path` 已在文本里, + // 进 prompt.files[] 只会让服务端把整份文件读进内存,还撞 20MB 上限。 + ...(attachType === 'file' || attachType === 'folder' ? { pathOnly: true } : {}), textRange: { value: mentionText, start: mentionStartIndex, @@ -1474,9 +1477,15 @@ function InputBoxComponent({ } }, []) - // 将拖入的文件信息插入为 @mention 附件 + /** + * 将拖入的文件信息插入为 @mention 附件。 + * + * `pathOnly`:只把路径写进 prompt 文本,不进 `prompt.files[]`。外部拖入的本机 + * 文件走这条(对齐官方 composer 的 `path` 部件):服务端不必把整份文件读进内存、 + * 也不会撞上 20MB 上限,模型按需用工具读。侧边栏内部拖拽仍传 files[]。 + */ const insertDraggedFiles = useCallback( - (fileInfos: DraggedFileInfo[]) => { + (fileInfos: DraggedFileInfo[], options: { pathOnly?: boolean } = {}) => { if (fileInfos.length === 0) return const currentText = textareaRef.current?.value ?? text @@ -1508,6 +1517,7 @@ function InputBoxComponent({ relativePath, url: toFileUrl(fileInfo.absolute), mime: fileInfo.type === 'file' ? 'text/plain' : undefined, + ...(options.pathOnly ? { pathOnly: true } : {}), textRange: { value: mentionText, start, @@ -1737,7 +1747,10 @@ function InputBoxComponent({ setAttachments(prev => [...prev, ...uploadAttachments]) } - insertDraggedFiles(mentionFiles) + // 外部拖入的本机文件只作路径引用(官方 composer 的 `path` 部件): + // 路径已经在 prompt 文本里,再进 files[] 会让服务端把整份文件读进内存, + // 超过 20MB 还会让整条 prompt 以 AttachmentError 失败。 + insertDraggedFiles(mentionFiles, { pathOnly: true }) } catch (err) { console.warn('[InputBox] Failed to process dropped paths:', err) } diff --git a/src/features/chat/InputBoxAttachments.test.tsx b/src/features/chat/InputBoxAttachments.test.tsx index 8298d22f..edba96e1 100644 --- a/src/features/chat/InputBoxAttachments.test.tsx +++ b/src/features/chat/InputBoxAttachments.test.tsx @@ -39,7 +39,7 @@ vi.mock('../attachment', () => ({ attachments, onRetry, }: { - attachments: Array<{ id: string; url?: string; uploadStatus?: string; progress?: number }> + attachments: Array<{ id: string; url?: string; uploadStatus?: string; progress?: number; pathOnly?: boolean }> onRetry?: (id: string) => void }) => (
@@ -47,6 +47,7 @@ vi.mock('../attachment', () => ({ {attachments.map(attachment => ( {`${attachment.url ?? ''}|${attachment.uploadStatus ?? ''}|${attachment.progress ?? ''}`} + {attachment.pathOnly ? '|pathOnly' : ''} ))} {attachments @@ -303,6 +304,9 @@ describe('InputBox attachment handling', () => { // 项目外的文件用绝对路径做引用;整条链路不碰上传 expect(uploadAttachmentMock).not.toHaveBeenCalled() expect(screen.getByTestId('attachment-count')).toHaveTextContent('1') + // 引用只写路径(对齐官方 composer 的 path 部件):不进 prompt.files[], + // 服务端就不会把整份文件读进内存,也不会撞上 20MB 上限 + expect(screen.getByTestId('attachment-meta')).toHaveTextContent('|pathOnly') }) it('选中的是模型支持的媒体(图片)→ 内联,不占用 @,也不上传', async () => { From f0b7cbfd8c5a3a5689f1ddf732379f299885d00b Mon Sep 17 00:00:00 2001 From: lehhair Date: Mon, 2 Nov 2026 09:21:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(markdown):=20=E9=95=BF=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E6=94=AF=E6=8C=81=E6=A8=AA=E5=90=91=E6=BB=9A=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KaTeX 的 display 公式是 nowrap,手机上超宽部分会被父容器裁掉, 末尾看不见。容器改成 flex + overflow-x: auto,居中用 margin-inline 而不是 justify-content(后者在内容溢出时会把左端推到不可滚动的 负区域,滚不到公式开头)。 滚动条交给全局 overlayScrollbar,不写原生样式。 (cherry picked from commit 44800bdd23e7e5ea1fcbc9ef1b015dc1045ee288) --- src/index.css | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/index.css b/src/index.css index afd22252..799ed04e 100644 --- a/src/index.css +++ b/src/index.css @@ -526,6 +526,29 @@ body { stroke: currentColor; } +/* 长公式横向滚动(手机窄屏必需) + * + * KaTeX 的 display 公式是 nowrap,超宽时会直接溢出容器被裁掉,末尾看不见。 + * 这里把容器改成横向滚动: + * - 不溢出时靠 `margin-inline: auto` 保持居中(跟 KaTeX 默认 text-align 一致) + * - 溢出时 margin 归零、内容左对齐,滚动条能从公式开头一直拖到结尾 + * 不能直接用 `justify-content: center`:溢出时左端会跑到不可滚动的负区域里。 + * 只作用于块级公式,行内公式仍按正常行内流换行。 + * + * 滚动条不写样式:原生滚动条全局隐藏,overlayScrollbar.ts 会扫描 + * `overflow-x: auto` 且真的溢出的容器,自动挂 `.os-thumb-x`(表格、代码块同款)。 */ +.markdown-content .katex-display { + display: flex; + overflow-x: auto; + overflow-y: hidden; + overscroll-behavior-x: contain; + padding-block: 0.125rem; +} + +.markdown-content .katex-display > .katex { + margin-inline: auto; +} + /* Streaming Markdown is rendered in stable/live chunks. Without this, Tailwind * first:/last: margin utilities run per chunk root and make adjacent blocks too tight. * Use DOM position (:first-child/:last-child) so settled blocks need no isFirst/isLast props. */ From 3bb8f4791767183eb58f65bfde044ba497770a27 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 2 Nov 2026 02:09:57 +0000 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=E5=90=8C=E6=AD=A5=E4=B8=8A?= =?UTF-8?q?=E6=B8=B8=20v0.7.24=E2=86=92v0.7.25=EF=BC=8C=E5=87=86=E5=A4=87?= =?UTF-8?q?=E5=8F=91=E5=B8=83=20v1.0.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sync lehhair/OpenCodeUI 3cc22e8..c5a729e. Keep independent 1.x; skip upstream 0.7.25 version bump. Co-authored-by: xiufeigo --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be8de0c0..6d068038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [v1.0.11] - 2026-11-02 + +- fix(markdown): 长公式支持横向滚动 (44800bdd) +- fix(attachment): 本机路径引用只写路径,不再整份读进 prompt.files[] (983bb028) + ## [v1.0.10] - 2026-10-26 - chore: bump version to 0.7.24 (3cc22e8c) diff --git a/package-lock.json b/package-lock.json index 5bf567d6..2eb0406d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "hasInstallScript": true, "license": "GPL-3.0-only", "dependencies": { diff --git a/package.json b/package.json index fc5bd9b3..22b8c296 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opencodeui", - "version": "1.0.10", + "version": "1.0.11", "description": "A third-party web frontend for OpenCode", "license": "GPL-3.0-only", "type": "module", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 19df3a7d..32515f58 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2725,7 +2725,7 @@ dependencies = [ [[package]] name = "opencodeui" -version = "1.0.10" +version = "1.0.11" dependencies = [ "futures-util", "log", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 504f4020..f7a90d9e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opencodeui" -version = "1.0.10" +version = "1.0.11" description = "OpenCode UI - Tauri Mobile App" authors = ["lehhair"] license = "GPL-3.0-only" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 46229e6e..888fa85a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "OpenCode", - "version": "1.0.10", + "version": "1.0.11", "identifier": "com.opencodeui.app", "build": { "frontendDist": "../dist",