Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(tui): Fix the issue where pasted text containing file paths gets truncated

openJiuwen-botf746e569a87d
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/attachments.ts b/jiuwenswarm/channels/tui/frontend/src/core/attachments.ts
index a9b419570e..9ba0a6c957 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/attachments.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/attachments.ts
@@ -170,6 +170,21 @@ export function extractAgentMentions(content: string): string[] {
return [...new Set(results)];
}
+/**
+ * Check if pasted text contains only file paths (pure drag-and-drop)
+ * with no command/message text interspersed.
+ * Terminal file drag-and-drop inserts only the file path(s); any other
+ * text means it's a clipboard paste of a command or message.
+ */
+export function isPurePathPaste(text: string): boolean {
+ const matches = [...text.matchAll(PASTED_PATH_RE)];
+ let remaining = text;
+ for (const m of matches) {
+ remaining = remaining.replace(m[0], "");
+ }
+ return remaining.trim().length === 0;
+}
+
export function extractFilePathsFromPaste(
text: string,
options: Omit<AttachmentExtractionOptions, "classifyAttachment"> = {},
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index bc078ed8ef..aca495a0bf 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -23,6 +23,7 @@ import {
findAttachmentTokenAtCursor,
formatAttachmentMention,
isImageAttachment,
+ isPurePathPaste,
isSupportedAttachment,
syncComposerImageTokens,
} from "../core/attachments.js";
@@ -1412,10 +1413,12 @@ export class AppScreen implements Component, Focusable {
// When files are dragged in, they arrive as a pasted string.
// Windows/PowerShell may not send bracketed paste markers,
// so we detect file paths in any multi-character input.
+ // Only intercept when the paste is *pure* file paths (drag-and-drop).
+ // If there's command text interleaved, treat it as a normal paste.
if (!snapshot.pendingQuestion && data.length > 4) {
const pastedContent = data.replace(/\x1b\[200~/, "").replace(/\x1b\[201~/, "");
const filePaths = extractFilePathsFromPaste(pastedContent);
- if (filePaths.length > 0) {
+ if (filePaths.length > 0 && isPurePathPaste(pastedContent)) {
// 若解析出路径但无一通过附件校验(扩展名不在白名单等),须把原文交给编辑器,避免粘贴被吞掉
if (this.handleDroppedFiles(filePaths)) {
return;