Skip to content

fix(desktop): preserve pasted paths in logs - #3856

Open
Stella-xixi wants to merge 2 commits into
makecindy:mainfrom
Stella-xixi:codex/fix-pasted-path-log-rewrite
Open

fix(desktop): preserve pasted paths in logs#3856
Stella-xixi wants to merge 2 commits into
makecindy:mainfrom
Stella-xixi:codex/fix-pasted-path-log-rewrite

Conversation

@Stella-xixi

@Stella-xixi Stella-xixi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

收窄输入框的粘贴路径自动引用行为:只有整段粘贴除首尾空白外仅包含一个工作区内绝对路径时,才继续确认文件并升级为引用。终端日志、错误信息和普通叙述中混入的绝对路径保持字面原文,避免发送给模型时静默变成 @相对路径

变更类型

  • fix 缺陷修复

范围

  • 关联 Issue / 需求:Fixes 粘贴文本中的工作区绝对路径被改写为 @ 相对路径 #3846
  • 本 PR 包含:粘贴路径识别边界调整;Windows 多行终端输出、混合文本、独立路径和深链混排回归测试;修复 Greptile 指出的目录尾分隔符识别问题,补充 Windows/POSIX、连续分隔符、周围空白及诊断后缀回归测试
  • 明确不包含:文件引用的 stat、序列化和显式 @/拖拽入口改动
  • 用户可见变化:日志和普通文本中的路径原样发送;单独粘贴路径仍生成文件引用
  • 是否存在 breaking change:无

UI 变化

  • 引用的设计规范:不涉及:未修改视觉、布局、样式或 UI 文案,仅修正既有输入框的粘贴语义

怎么验证的

自动验证

pnpm --filter desktop exec vitest run src/renderer/__tests__/pastePipeline.test.ts
结果:通过,44 tests

pnpm --filter desktop run --if-present typecheck
结果:通过

pnpm test:unit:related
结果:通过,apps/desktop related unit tests

pnpm check:dco -- --base origin/main --head HEAD
结果:通过,2 commits signed off

验证说明:修复提交接到 PR 来源基线后,已确认完整代码树与通过上述测试的版本一致;DCO 在最终提交上重新检查通过。

手工验证

不涉及:本次用纯函数回归测试覆盖 Issue 中的 Windows 终端输出输入形态。

未执行的验证

未启动 Desktop 做 GUI 手工验证;改动位于纯粘贴分段函数,已由定向与 related 单测覆盖。

风险

风险分类

  • 其他:输入框粘贴路径识别边界变化

影响与回滚

  • 影响范围:Desktop 输入框中自动识别工作区绝对路径的粘贴流程
  • 回滚 / 降级方式:回退本提交即可恢复混合文本内路径自动升级;不涉及持久化格式或数据迁移

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名
  • UI 改动已在「UI 变化」注明不涉及视觉变化
  • 未提交凭证、令牌或授权文件
  • 已补充必要测试
  • 已确认测试结果

@Stella-xixi
Stella-xixi requested a review from a team as a code owner September 3, 2026 09:04
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown

Greptile Summary

本 PR 收窄 Desktop 输入框的路径自动引用规则,使日志、叙述和深链混排中的路径保持原文,同时保留独立路径的引用升级。

  • 检测到深链时直接返回深链分段,不再扫描其中的路径。
  • 仅当整段内容包含一个路径且其余分段均为空白时返回路径分段。
  • 增加 Windows 终端输出、混合文本、独立路径和深链混排测试。

Confidence Score: 4/5

合并前应修复独立目录路径带尾分隔符时无法生成引用的问题。

新的空白限定会把路径解析器剥离后保留的 /\ 视为额外正文,使常见的独立目录粘贴退化为普通文本。

Files Needing Attention: apps/desktop/src/renderer/components/new-chat/pastePipeline.ts;apps/desktop/src/renderer/tests/pastePipeline.test.ts

Important Files Changed

Filename Overview
apps/desktop/src/renderer/components/new-chat/pastePipeline.ts 收窄路径识别范围符合修复目标,但新增空白判定错误拒绝带尾分隔符的独立目录路径。
apps/desktop/src/renderer/components/new-chat/ChatInput.tsx 仅更新粘贴管线说明,与新的混合文本处理语义一致。
apps/desktop/src/renderer/tests/pastePipeline.test.ts 覆盖了主要日志和混排回归场景,但遗漏单独粘贴带尾分隔符目录的既有支持形态。
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:186-189
**尾分隔符破坏目录路径识别**

当用户单独粘贴以 `/``\` 结尾的工作区目录路径时,`trimPathCandidate` 会剥离尾分隔符并将其留在非空白文本段中,导致 `hasOnlySurroundingWhitespace` 判定失败,最终按普通文本粘贴而无法生成目录引用 chip。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(desktop): preserve pasted paths in l..." | Re-trigger Greptile

Comment on lines +186 to +189
const hasOnlySurroundingWhitespace = pathSegments.every(
(seg) => seg.kind === 'path' || (seg.kind === 'text' && seg.text.trim().length === 0),
);
return paths.length === 1 && hasOnlySurroundingWhitespace ? pathSegments : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 尾分隔符破坏目录路径识别

当用户单独粘贴以 /\ 结尾的工作区目录路径时,trimPathCandidate 会剥离尾分隔符并将其留在非空白文本段中,导致 hasOnlySurroundingWhitespace 判定失败,最终按普通文本粘贴而无法生成目录引用 chip。

Context Used: 使用和PR描述相同的语言进行评论 (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/components/new-chat/pastePipeline.ts
Line: 186-189

Comment:
**尾分隔符破坏目录路径识别**

当用户单独粘贴以 `/``\` 结尾的工作区目录路径时,`trimPathCandidate` 会剥离尾分隔符并将其留在非空白文本段中,导致 `hasOnlySurroundingWhitespace` 判定失败,最终按普通文本粘贴而无法生成目录引用 chip。

**Context Used:** 使用和PR描述相同的语言进行评论 ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示) labels Sep 3, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

这条会改变输入框粘贴路径时要不要自动变成文件引用,属于用户看得见的交互变化。维护者确认门先拦住,等维护者在 PR 上 Approve。需要修改就 Request Changes。讨论 issue:#3860

@MagicLizi

Copy link
Copy Markdown
Contributor

@Stella-xixi 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/renderer/components/new-chat/pastePipeline.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi

Copy link
Copy Markdown
Contributor

命中 UI 路径(apps/desktop/src/renderer/components/new-chat/ChatInput.tsx / apps/desktop/src/renderer/components/new-chat/pastePipeline.ts)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立审查未通过(0 P0 / 1 P1)。请按下列路径修改后再推。

P1 apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:186 — 单独粘贴带尾分隔符的工作区目录时,路径识别被「整段仅空白包围」判定误杀。segmentPathCandidatestrimPathCandidate 剥掉尾 /\ 后,把剥离物留成非空白 text 段,hasOnlySurroundingWhitespace 失败,整段返回 null,不会进 path chip。Finder / 资源管理器 / shell 补全常见的 dir/dir\ 会回归成普通粘贴。请把剥掉的尾分隔符当作路径本体,而不是额外正文;cd ${dir}/ 这类混合文本继续 null。补测:POSIX dir/、Windows dir\、首尾空白 + 尾分隔符。

@MagicLizi MagicLizi added status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed awaiting-discussion 等待维护者讨论(review-pr) labels Sep 3, 2026
@MagicLizi
MagicLizi dismissed their stale review September 3, 2026 23:13

这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。

@MagicLizi MagicLizi added the awaiting-discussion 等待维护者讨论(review-pr) label Sep 3, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@Stella-xixi 👋 这个 PR 现在在等维护者确认,确认之前流程不会合并它 —— 不是卡住了,也不是在等你再改一版(你推的改动流程都读到了,判的就是最新一版代码)。

这条是流程自动发的状态提醒(同一版代码只发一次),不用回复。

@MagicLizi MagicLizi removed the status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) label Sep 3, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立审查(standard)未通过,P1×1。当前 head 4ce29df 不能合。维护者确认门仍在拦(product),本轮不合并。

  • [P1] apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:276 — segmentPathCandidatestrimPathCandidate 剥掉尾分隔符后,按 trimmed 长度推进 cursor,剩下的 /\ 变成 text 段。新的整段粘贴门要求非 path 段必须是空白,于是单独粘贴工作区内目录路径(.../apps/desktop/)无法升级为引用 chip。请把 trim 掉的尾分隔符算进同一条 path,不要当成散文。验证:整段粘贴 workdir/subdir/C:\Code\app\ 仍产出 path chip;混有日志/叙述的路径保持原文。

@MagicLizi MagicLizi added status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed awaiting-discussion 等待维护者讨论(review-pr) labels Sep 4, 2026
@MagicLizi
MagicLizi dismissed their stale review September 4, 2026 20:07

这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) labels Sep 4, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查结论:需要修改(P1 × 1)

单独粘贴带尾分隔符的工作区目录时,新的「整段仅空白包围」门会把剥下来的 /\ 当成非空白文本,整段返回 null,目录无法升级成 path chip。这和 PR「单独路径仍引用」的承诺冲突;现有 greptile thread 指向同一处。

P1

  • apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:276segmentPathCandidatestrimPathCandidate 剥掉尾 /\\ 后按 trimmed 长度推进 cursor,剥离物变成非空白 text 段;hasOnlySurroundingWhitespace(186–189)失败。复现:…/apps/desktop/[path, text:'/'] → 门失败;无尾斜杠的同一目录仍成功。请把剥掉的尾分隔符算进同一条 path,不要当散文;cd ${dir}/ 继续 null。补测:POSIX dir/、Windows dir\\、首尾空白 + 尾分隔符。

@MagicLizi MagicLizi added status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed awaiting-discussion 等待维护者讨论(review-pr) labels Sep 4, 2026
@MagicLizi
MagicLizi dismissed their stale review September 4, 2026 23:56

这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) awaiting-discussion 等待维护者讨论(review-pr) labels Sep 5, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立审查未通过(P1×1)。greptile 未 resolve 的尾分隔符意见仍成立,未代 resolve。

  • apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:186 — trimPathCandidate 会剥掉尾分隔符,但 segmentPathCandidatescursor = m.index + trimmed.length 把剥下来的 /\ 留成非空白 text 段;新闸门 hasOnlySurroundingWhitespace 因此失败,整段粘贴退回 null。契约是「除首尾空白外仅一个工作区绝对路径」仍应升级为引用。现行为:…/apps/desktop → path 段;…/apps/desktop/…/apps/desktop//、Windows 尾 \null。单 path 判定应对整段 trim 后再 trimPathCandidate 与唯一 path 段比较,或把仅含 [\\/] 的残留与空白同等放行,并补 POSIX/Windows 尾分隔符用例。

@MagicLizi MagicLizi added the status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) label Sep 5, 2026
@MagicLizi
MagicLizi dismissed their stale review September 5, 2026 10:31

这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) labels Sep 6, 2026

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立审查未通过(P1×1)。当前 head 4ce29df4e1d8fa907ff9a2cedfe606c53edcf874 不能合。维护者确认门仍在拦(product),本轮不合并。未代 resolve greptile thread。

  • [P1] apps/desktop/src/renderer/components/new-chat/pastePipeline.ts:186 — 单独粘贴带尾分隔符的工作区目录时,路径识别被「整段仅空白包围」判定误杀。trimPathCandidate 剥掉尾 /\ 后,segmentPathCandidates 把剥离物留成非空白 text 段,hasOnlySurroundingWhitespace 失败,整段返回 null,不会生成目录 chip。这和 PR「单独路径仍引用」的承诺冲突。请忽略只含被剥离尾分隔符的 leftover text,并补 POSIX / 与 Windows \ 的回归测试。

@MagicLizi MagicLizi added status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed awaiting-discussion 等待维护者讨论(review-pr) labels Sep 6, 2026
@MagicLizi
MagicLizi dismissed their stale review September 6, 2026 05:43

这些问题已在当前 head 的后续 commit 中修复(格式门/安全门已通过),自动 dismiss 旧的 CHANGES_REQUESTED 以解除合并阻塞。

@MagicLizi MagicLizi added awaiting-discussion 等待维护者讨论(review-pr) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) labels Sep 6, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@Stella-xixi 👋 这个 PR 已经有 3 天没有 rebase 了。

为了避免合入后出现 CI 未曾验证过的新问题,请在本地 rebase 最新的 origin/main 后重新推送。rebase 后 CI 会自动重跑,全部通过后 auto-review 会在下一轮继续处理。

@MagicLizi

Copy link
Copy Markdown
Contributor

@Stella-xixi 👋 这个 PR 已经有 4 天没有 rebase 了。

为了避免合入后出现 CI 未曾验证过的新问题,请在本地 rebase 最新的 origin/main 后重新推送。rebase 后 CI 会自动重跑,全部通过后 auto-review 会在下一轮继续处理。

Signed-off-by: Stella-xixi <2559689615@qq.com>
Signed-off-by: Stella-xixi <2559689615@qq.com>
@Stella-xixi
Stella-xixi force-pushed the codex/fix-pasted-path-log-rewrite branch from 375575b to 596fb6f Compare September 7, 2026 02:07
@MagicLizi

Copy link
Copy Markdown
Contributor

@Stella-xixi 👋 这个 PR 已经有 4 天没有 rebase 了。

为了避免合入后出现 CI 未曾验证过的新问题,请在本地 rebase 最新的 origin/main 后重新推送。rebase 后 CI 会自动重跑,全部通过后 auto-review 会在下一轮继续处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-discussion 等待维护者讨论(review-pr) touches:product-ui 改动碰到产品 / UI 面(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

粘贴文本中的工作区绝对路径被改写为 @ 相对路径

2 participants