Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve pasted paths in logs
Stella-xixi82f38ed69025
diff --git a/apps/desktop/src/renderer/__tests__/pastePipeline.test.ts b/apps/desktop/src/renderer/__tests__/pastePipeline.test.tsindex 412349870a..91df8e67cc 100644--- a/apps/desktop/src/renderer/__tests__/pastePipeline.test.ts+++ b/apps/desktop/src/renderer/__tests__/pastePipeline.test.ts@@ -158,16 +158,30 @@ describe('segmentPastedContent — deep links', () => {});describe('segmentPastedContent — path candidates', () => {- it('emits path segments only for absolute paths inside the workingDir', () => {+ it('keeps paths embedded in prose as literal text', () => {const inPath = `${WORKDIR}/apps/desktop/src/main.ts`;expect(segmentPastedContent(`报错在 ${inPath} 附近,系统文件 /etc/hosts 无关`, {workingDir: WORKDIR,}),- ).toEqual([- { kind: 'text', text: '报错在 ' },+ ).toBeNull();+ });++ it('keeps multiline terminal output containing a Windows workspace path unchanged', () => {+ const script = 'C:\\Code\\XDMaker\\scripts\\build.sh';+ const output = `running build\n/bin/bash: ${script}: No such file or directory\nexit 127`;+ expect(segmentPastedContent(output, { workingDir: WIN_WORKDIR })).toBeNull();+ });++ it('emits a path segment when the entire paste is one workspace path', () => {+ const inPath = `${WORKDIR}/apps/desktop/src/main.ts`;+ expect(segmentPastedContent(inPath, { workingDir: WORKDIR })).toEqual([{ kind: 'path', path: inPath },- { kind: 'text', text: ' 附近,系统文件 /etc/hosts 无关' },+ ]);+ expect(segmentPastedContent(` ${inPath}\n`, { workingDir: WORKDIR })).toEqual([+ { kind: 'text', text: ' ' },+ { kind: 'path', path: inPath },+ { kind: 'text', text: '\n' },]);});@@ -181,54 +195,38 @@ describe('segmentPastedContent — path candidates', () => {expect(segmentPastedContent(`cd ${WORKDIR}/`, { workingDir: WORKDIR })).toBeNull();});- it('emits dir candidates without the trailing separator (review P2)', () => {+ it('does not upgrade a path used as part of a shell command', () => {const dir = `${WORKDIR}/apps/desktop`;- expect(segmentPastedContent(`cd ${dir}/`, { workingDir: WORKDIR })).toEqual([- { kind: 'text', text: 'cd ' },- { kind: 'path', path: dir },- { kind: 'text', text: '/' },- ]);+ expect(segmentPastedContent(`cd ${dir}/`, { workingDir: WORKDIR })).toBeNull();});- it('strips :line / :line:col suffixes from candidates', () => {+ it('keeps a path with diagnostic suffix and prose as literal text', () => {const p = `${WORKDIR}/src/index.ts`;- expect(segmentPastedContent(`${p}:12:5 报错`, { workingDir: WORKDIR })).toEqual([- { kind: 'path', path: p },- { kind: 'text', text: ':12:5 报错' },- ]);+ expect(segmentPastedContent(`${p}:12:5 报错`, { workingDir: WORKDIR })).toBeNull();});it('recognizes paths with CJK dir / file names (review P2)', () => {const cjkPath = `${WORKDIR}/文档/需求说明.md`;- expect(segmentPastedContent(`看 ${cjkPath} 这份`, { workingDir: WORKDIR })).toEqual([- { kind: 'text', text: '看 ' },+ expect(segmentPastedContent(cjkPath, { workingDir: WORKDIR })).toEqual([{ kind: 'path', path: cjkPath },- { kind: 'text', text: ' 这份' },]);// 全角标点终止路径(, 全角逗号不吞进候选;ASCII 逗号是合法路径// 字符,紧贴场景按文档注释走「吞入候选 → stat miss 安全降级」)- expect(segmentPastedContent(`${cjkPath},另外`, { workingDir: WORKDIR })).toEqual([- { kind: 'path', path: cjkPath },- { kind: 'text', text: ',另外' },- ]);+ expect(segmentPastedContent(`${cjkPath},另外`, { workingDir: WORKDIR })).toBeNull();});it('matches Windows paths case-insensitively against the workingDir', () => {const winPath = 'c:\\code\\xdmaker\\Apps\\main.ts';- expect(segmentPastedContent(`见 ${winPath} 一行`, { workingDir: WIN_WORKDIR })).toEqual([- { kind: 'text', text: '见 ' },+ expect(segmentPastedContent(winPath, { workingDir: WIN_WORKDIR })).toEqual([{ kind: 'path', path: winPath },- { kind: 'text', text: ' 一行' },]);});it('matches Windows slash-form paths against a backslash workingDir (review P2)', () => {// Git Bash / Node 输出常用 C:/... 斜杠形态,workdir 存的是 C:\... 反斜杠形态。const slashPath = 'C:/Code/XDMaker/src/a.ts';- expect(segmentPastedContent(`见 ${slashPath} 一行`, { workingDir: WIN_WORKDIR })).toEqual([- { kind: 'text', text: '见 ' },+ expect(segmentPastedContent(slashPath, { workingDir: WIN_WORKDIR })).toEqual([{ kind: 'path', path: slashPath },- { kind: 'text', text: ' 一行' },]);expect(toWorkdirRelativePath(slashPath, WIN_WORKDIR)).toBe('src/a.ts');});@@ -237,14 +235,13 @@ describe('segmentPastedContent — path candidates', () => {expect(segmentPastedContent('/some/other/root/file.ts', { workingDir: WORKDIR })).toBeNull();});- it('scans paths inside the leftover text segments around deep links', () => {+ it('keeps paths literal while still converting deep links in the same paste', () => {const p = `${WORKDIR}/README.md`;expect(segmentPastedContent(`${SESSION_URL} 里改了 ${p}`, { workingDir: WORKDIR }),).toEqual([{ kind: 'session', href: SESSION_URL, label: null },- { kind: 'text', text: ' 里改了 ' },- { kind: 'path', path: p },+ { kind: 'text', text: ` 里改了 ${p}` },]);});});diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex dac234a455..5cb8c405d1 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -2269,10 +2269,11 @@ export function ChatInput({return true;}- // 2. 深链 / 路径混排 → text / session / project / path 分段:+ // 2. 深链 / 独立路径 → text / session / project / path 分段:// session、project 即时成 chip(session 裸链接先短 ID 占位,标题- // 异步原地补齐——sessionLinkPaste.ts);path 段先落纯文本,stat- // 确认存在后原地升级为 @chip(pathPaste.ts)。+ // 异步原地补齐——sessionLinkPaste.ts);整段粘贴仅为一个工作区+ // 绝对路径时,path 段先落纯文本,stat 确认存在后原地升级+ // 为 @chip(pathPaste.ts);日志或叙述中的路径保持字面原文。const segments = text? segmentPastedContent(text, { workingDir: workingDirRef.current }): null;diff --git a/apps/desktop/src/renderer/components/new-chat/pastePipeline.ts b/apps/desktop/src/renderer/components/new-chat/pastePipeline.tsindex e62159bbdf..8fc4c47649 100644--- a/apps/desktop/src/renderer/components/new-chat/pastePipeline.ts+++ b/apps/desktop/src/renderer/components/new-chat/pastePipeline.ts@@ -4,8 +4,9 @@* ChatInput.handlePaste 对剪贴板文本按以下优先级走管线,命中即停:* 1. 长文本(isLongPasteText)→ 整段折叠为 PastedTextChip(长 log 里的* 深链 / 路径不再逐个 chip 化——那是噪音不是引用);- * 2. 深链 / 路径混排(segmentPastedContent)→ text / session / project /- * path 分段:session、project 即时成 chip;path 段先落纯文本,由+ * 2. 深链 / 独立路径(segmentPastedContent)→ text / session / project /+ * path 分段:session、project 即时成 chip;仅整段粘贴是一个路径时,+ * path 段先落纯文本,由* pathPaste.ts 异步 stat 确认后原地升级(见该文件头注释);* 3. 都不命中 → null,调用方 fall through 到默认粘贴。*@@ -155,7 +156,9 @@ export function toWorkdirRelativePath(candidate: string, workingDir: string): st/*** 把粘贴文本切成 text / session / project / path 段。没有任何可变换目标时* 返回 null(调用方走默认粘贴)。深链的 markdown 形式(`[标题](深链)`)- * 优先于裸形式;路径候选在剩余 text 段上做第二遍扫描。+ * 优先于裸形式;路径只在整段粘贴除首尾空白外是单个工作区内+ * 绝对路径时识别。这样粘贴单个路径仍是明确的文件引用操作,终端日志、+ * 错误信息与普通叙述中的字面路径则保持原样。*/export function segmentPastedContent(text: string,@@ -164,8 +167,7 @@ export function segmentPastedContent(const deepLinkSegments = segmentDeepLinks(text);const workingDir = options.workingDir?.trim() || null;- let segments: PastedContentSegment[] = deepLinkSegments ?? [{ kind: 'text', text }];- let matchedAny = deepLinkSegments != null;+ if (deepLinkSegments) return deepLinkSegments;// 快速早退:文本里连 workdir 前缀都没有就不做逐段路径扫描。Windows 路径// 大小写不敏感且 `\` / `/` 两种分隔符形态并存(Git Bash / Node 输出斜杠@@ -177,25 +179,14 @@ export function segmentPastedContent((winLike ? workingDir.toLowerCase().replace(/\\/g, '/') : workingDir).replace(/[\\/]+$/, ''),): false;- if (workingDir && containsWorkdir) {- const withPaths: PastedContentSegment[] = [];- for (const seg of segments) {- if (seg.kind !== 'text') {- withPaths.push(seg);- continue;- }- const pathSegs = segmentPathCandidates(seg.text, workingDir);- if (pathSegs) {- matchedAny = true;- withPaths.push(...pathSegs);- } else {- withPaths.push(seg);- }- }- segments = withPaths;- }-- return matchedAny ? segments : null;+ if (!workingDir || !containsWorkdir) return null;+ const pathSegments = segmentPathCandidates(text, workingDir);+ if (!pathSegments) return null;+ const paths = pathSegments.filter((seg) => seg.kind === 'path');+ const hasOnlySurroundingWhitespace = pathSegments.every(+ (seg) => seg.kind === 'path' || (seg.kind === 'text' && seg.text.trim().length === 0),+ );+ return paths.length === 1 && hasOnlySurroundingWhitespace ? pathSegments : null;}/** 深链(session + project,裸 / markdown 两形态)分段;无命中 → null。 */