Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): a very long paste becomes a text-file attachment (#919)

Yaowei Zhenge6f0789aa222
diff --git a/changelog/unreleased/2026-10-01-long-paste-attachment.md b/changelog/unreleased/2026-10-01-long-paste-attachment.md
new file mode 100644
index 00000000..94befe50
--- /dev/null
+++ b/changelog/unreleased/2026-10-01-long-paste-attachment.md
@@ -0,0 +1,13 @@
+# A very long paste becomes a text-file attachment
+
+- **Date:** 2026-10-01
+- **Type:** fix
+- **Scope:** `web`, `docs`
+
+[中文版](2026-10-01-long-paste-attachment.zh.md)
+
+Pasting a very long text into the composer — more than 20,000 characters or 400 lines, such as a
+whole log — no longer puts it in the text box, where every later keystroke re-rendered it and the
+page stopped responding. It is attached as a text file named `pasted-<date>-<time>.txt`, shown as
+an attachment chip with a short notice, and sent like any attached file, so the model still reads
+all of it. Goal mode takes no file attachments, so there the text is pasted as before.
diff --git a/changelog/unreleased/2026-10-01-long-paste-attachment.zh.md b/changelog/unreleased/2026-10-01-long-paste-attachment.zh.md
new file mode 100644
index 00000000..0e4a7528
--- /dev/null
+++ b/changelog/unreleased/2026-10-01-long-paste-attachment.zh.md
@@ -0,0 +1,9 @@
+# 超长粘贴改为文本文件附件
+
+- **Date:** 2026-10-01
+- **Type:** fix
+- **Scope:** `web`, `docs`
+
+[English](2026-10-01-long-paste-attachment.md)
+
+向输入框粘贴很长的文本(超过 20,000 个字符或 400 行,比如一整段日志)时,不再放进输入框——此前之后的每次按键都要重新渲染这段文本,页面随之卡死。它会作为文本文件 `pasted-<日期>-<时间>.txt` 加入附件,显示为附件卡片并给出简短提示,发送方式与其他附件相同,模型仍会读到全部内容。目标模式不接受文件附件,此时照常粘贴为文本。
diff --git a/packages/docs/content/chat.en.md b/packages/docs/content/chat.en.md
index 6b10f72e..8bede75c 100644
--- a/packages/docs/content/chat.en.md
+++ b/packages/docs/content/chat.en.md
@@ -58,6 +58,7 @@ Press Enter to send, and Shift+Enter for a new line. In an empty composer, the u
### Attach images and files
- Paste an image into the composer. Pasting accepts images only.
+- Paste a very long text (more than 20,000 characters or 400 lines, such as a whole log) and it is attached as a text file named `pasted-<date>-<time>.txt` instead of filling the text box, so typing stays responsive; the model still reads all of it. In goal mode, which takes no file attachments, it is pasted as text.
- In the + menu (**More input options**), select **Upload image** or **Upload file**.
An attachment can be any type. Selected files show as removable chips above the text, in the order you picked them, and a message with attachments and no text can be sent.
diff --git a/packages/docs/content/chat.zh.md b/packages/docs/content/chat.zh.md
index 6af014b9..8a0fced4 100644
--- a/packages/docs/content/chat.zh.md
+++ b/packages/docs/content/chat.zh.md
@@ -58,6 +58,7 @@ Session 创建后,模型和 Workspace 就锁定了。之后想换模型,见[
### 附加图片和文件
- 直接把图片粘贴到输入框。粘贴只接受图片。
+- 粘贴很长的文本(超过 20,000 个字符或 400 行,比如一整段日志)时,它会作为文本文件 `pasted-<日期>-<时间>.txt` 加入附件,而不是塞进输入框,输入因此保持流畅;模型仍会读到全部内容。目标模式不接受文件附件,此时照常粘贴为文本。
- 在 + 菜单(**更多输入方式**)中选择**上传图片**或**上传文件**。
附件不限类型。选中的文件按选择顺序以小卡片的形式显示在正文上方,可以逐个移除;只有附件、没有文字的消息也能发送。
diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsx
index a5d0a317..aefccc73 100644
--- a/packages/web/src/features/chat/chat-input.tsx
+++ b/packages/web/src/features/chat/chat-input.tsx
@@ -151,6 +151,7 @@ import { FileDropZone } from "./drop-zone";
import { ContextGauge } from "./context-gauge";
import { modelWindowBelowCompactionLimit } from "../../lib/context";
import { splitDroppedFiles } from "../../lib/file-drop";
+import { isLongPaste, longPasteFileName } from "../../lib/long-paste";
import { splitBySize } from "../../lib/upload-limits";
import type { ComposerReference } from "../../lib/workspace-tree";
import { ReferenceChip } from "./reference-chip";
@@ -1872,6 +1873,17 @@ export function ChatInput({
if (files.length > 0) {
e.preventDefault();
addFiles(files);
+ return;
+ }
+ // A paste too long for the text box (a whole log) is attached as a text file instead:
+ // inserted, it makes every later keystroke re-render the whole text and the tab hangs.
+ // Goal mode takes no file attachments, so there the text goes in as it always did.
+ const text = e.clipboardData.getData("text/plain");
+ if (!goalOn && isLongPaste(text)) {
+ e.preventDefault();
+ const name = longPasteFileName(new Date());
+ addAttachments([new File([text], name, { type: "text/plain" })]);
+ toastInfo(S.chat.longPasteAttached(name));
}
};
diff --git a/packages/web/src/lib/long-paste.ts b/packages/web/src/lib/long-paste.ts
new file mode 100644
index 00000000..739af66a
--- /dev/null
+++ b/packages/web/src/lib/long-paste.ts
@@ -0,0 +1,31 @@
+/**
+ * A paste too long to live in the composer's text box becomes a text-file attachment instead.
+ *
+ * A pasted log of hundreds of kilobytes makes every later keystroke re-render and re-measure
+ * the whole text, and the tab stops responding. Kept as a file, it travels the same way any
+ * attached file does — staged as a chip, written to the Session's scratchpad on send, and
+ * named in the message by its `[attached file: …]` line — so the model still reads all of it,
+ * and the text box keeps only what the user types.
+ */
+
+/** Past either limit a paste is attached as a file rather than inserted. */
+export const LONG_PASTE_MAX_CHARS = 20_000;
+export const LONG_PASTE_MAX_LINES = 400;
+
+/** Whether `text` is too long to insert into the text box. */
+export function isLongPaste(text: string): boolean {
+ if (text.length > LONG_PASTE_MAX_CHARS) return true;
+ let lines = 1;
+ for (let i = 0; i < text.length; i++) {
+ if (text.charCodeAt(i) === 10 && ++lines > LONG_PASTE_MAX_LINES) return true;
+ }
+ return false;
+}
+
+/** The attachment's file name: `pasted-YYYYMMDD-HHmmss.txt`, in the viewer's local time. */
+export function longPasteFileName(at: Date): string {
+ const two = (n: number) => String(n).padStart(2, "0");
+ const date = `${at.getFullYear()}${two(at.getMonth() + 1)}${two(at.getDate())}`;
+ const time = `${two(at.getHours())}${two(at.getMinutes())}${two(at.getSeconds())}`;
+ return `pasted-${date}-${time}.txt`;
+}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index c65b1599..3464ed63 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3040,6 +3040,9 @@ Scenarios:
dropFilesDesc: "Images and files are added to the message draft",
/** Toast when non-image files are dropped in goal mode (the objective carries images only). */
dropFilesGoalHint: "Goal mode takes images only; the files were not attached.",
+ /** A paste too long for the text box, attached as a text file instead. */
+ longPasteAttached: (name: string): string =>
+ `The pasted text was long, so it was attached as ${name}.`,
goalMode: "Goal mode",
goalModeDesc: "Loop until the goal completes",
goalBudgetLabel: "Token budget",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 8a823f57..0be11102 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3093,6 +3093,8 @@ Benchmark:
dropFilesDesc: "图片与文件将添加到输入框",
/** Toast when non-image files are dropped in goal mode (the objective carries images only). */
dropFilesGoalHint: "目标模式仅支持附加图片,文件未添加。",
+ /** A paste too long for the text box, attached as a text file instead. */
+ longPasteAttached: (name: string): string => `粘贴的文本较长,已作为附件 ${name} 添加。`,
goalMode: "目标模式",
goalModeDesc: "循环运行直至目标完成",
goalBudgetLabel: "Token 预算",
diff --git a/packages/web/test/long-paste.test.ts b/packages/web/test/long-paste.test.ts
new file mode 100644
index 00000000..9e85d35e
--- /dev/null
+++ b/packages/web/test/long-paste.test.ts
@@ -0,0 +1,39 @@
+/**
+ * A long paste becomes a text-file attachment instead of text in the composer.
+ *
+ * - Given an ordinary paste (a sentence, a short snippet), it stays text.
+ * - Given a paste longer than the character limit, it is attached as a file.
+ * - Given a paste of many short lines past the line limit, it is attached as a file even though
+ * it is short in characters.
+ * - The attached file is named by the local time of the paste, so a user can tell which paste
+ * it was.
+ */
+import { describe, expect, it } from "vitest";
+import {
+ LONG_PASTE_MAX_CHARS,
+ LONG_PASTE_MAX_LINES,
+ isLongPaste,
+ longPasteFileName,
+} from "../src/lib/long-paste";
+
+describe("long paste", () => {
+ it("an ordinary paste stays text", () => {
+ expect(isLongPaste("fix the flaky test in server")).toBe(false);
+ expect(isLongPaste("line\n".repeat(LONG_PASTE_MAX_LINES - 1))).toBe(false);
+ expect(isLongPaste("x".repeat(LONG_PASTE_MAX_CHARS))).toBe(false);
+ });
+
+ it("a paste past the character limit is attached", () => {
+ expect(isLongPaste("x".repeat(LONG_PASTE_MAX_CHARS + 1))).toBe(true);
+ });
+
+ it("many short lines past the line limit are attached", () => {
+ const log = "ok\n".repeat(LONG_PASTE_MAX_LINES);
+ expect(log.length).toBeLessThan(LONG_PASTE_MAX_CHARS);
+ expect(isLongPaste(log)).toBe(true);
+ });
+
+ it("the file is named by the local time of the paste", () => {
+ expect(longPasteFileName(new Date(2026, 9, 1, 9, 5, 7))).toBe("pasted-20261001-090507.txt");
+ });
+});