Repository navigation
fix(terminal): bash 在数组 PROMPT_COMMAND 和回显 BASH_COMMAND 的 DEBUG trap 下仍只上报一次命令开始 - #2055
Merged
Merged
Conversation
…下仍只上报一次命令开始 Ubuntu 26.04(systemd 257 起的 /etc/profile.d/80-systemd-osc-context.sh)把 PROMPT_COMMAND 改成数组,并在 PS0 前放命令替换。集成先读 /etc/profile,于是: - DEBUG trap 路径遇到数组整段跳过,一次命令开始都不报。现在与 PS0 路径一样 在数组首尾加入 __motty_disarm / __motty_arm。 - PS0 路径用 $'...' 写标记,赋值语句文本里就带 ESC/BEL,用户 DEBUG trap 回显 BASH_COMMAND 时伪造一次命令开始。改用 PS0 自己会解码的提示符转义。 回归测试在测试自己的 .bash_profile 里照 systemd 的写法设置,不依赖宿主 /etc/profile;新增 PS0 路径的 TestIntegratedBashReportsEachCommandLineOnce。 同步更新功能矩阵 terminal-shell-integration 与 Shell 集成 Agent Note。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1lck
marked this pull request as ready for review
November 16, 2026 14:18
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
从 #2010(终端接通本地 Shell 集成)开始,main 上每一轮 Desktop CI 的 “Vet and test on Linux” 都有两个测试失败:
TestIntegratedBashDebugTrapReportsEachCommandLineOnce:启动时命令开始标记报了 0 次。TestIntegratedSystemBashReportsEachCommandLineOnce:启动时命令开始标记报了 2 次。原因是 runner 已换成 Ubuntu 26.04。它自带 systemd 257 起提供的
/etc/profile.d/80-systemd-osc-context.sh,这个脚本:PROMPT_COMMAND改成数组;$(__systemd_osc_context_ps0)。集成脚本会先读
/etc/profile,所以用户的机器只要是 Ubuntu 26.04、Fedora 42、Arch 等装了新版 systemd 的发行版,也会遇到同样的问题。CI 只是最先暴露出来。改动 / Changes
desktop/internal/localshell/integration_scripts.go的 bash 集成脚本:PS0=$'\e]133;C…\a'${PS0-},现在改为PS0='\e]133;C…\a'${PS0-}。$'…'在赋值语句的文本里就展开成了 ESC 和 BEL 字节。BASH_COMMAND时,会把一个带本会话令牌的 C 标记原样打到终端,终端就多记了一次“命令开始”。CI 上的 2 次就是这样来的。\e、\a,所以实际输出的标记不变。PROMPT_COMMAND:__motty_disarm和__motty_arm。desktop/internal/localshell/integration_unix_test.go:commandStartProfiles,包含两种用户 profile:PROMPT_COMMAND;PROMPT_COMMAND,外加 PS0 命令替换。.bash_profile里,不依赖宿主的/etc/profile,所以在 macOS 上也能复现。TestIntegratedBashReportsEachCommandLineOnce,用 PATH 中 4.4 以上的 bash 覆盖 PS0 路径。macOS 的/bin/bash是 3.2,原来的测试一直走不到 PS0 路径。TestIntegratedBashDebugTrapReportsEachCommandLineOnce改为对两种 profile 各跑一个子测试。bashAtLeast读取 bash 版本,带 10 秒超时:checkCommandStartReports额外断言 profile 里的PROMPT_COMMAND项和 PS0 内容照常运行。这两项文本由 printf 拼出来,避免被 DEBUG trap 回显的源码误命中。shared/platform-feature-matrix/features/terminal-shell-integration.json:验证说明里加上这种情形和三个测试名,notes 里记一条。.agents/notes/implemented/architecture/2026-11-16-local-shell-integration-shim.md:记录 bash 集成脚本和 Motty 不同的这两处、改动原因和对应的回归测试,避免以后同步 Motty 时被改回去。不在本 PR 范围内 / Out of scope
TestClosingAnIntegratedShellHangsUpTheShellAndItsJobs和TestClosingAnIntegratedShellRightAfterACommandHangsUpItsJobs在 Linux 上偶发失败(最近 22 次中出现 3 次),本机连跑 30 次也无法复现,根因还没确认,已提交 [Bug] Linux 上关闭集成 bash 终端后,后台任务偶尔没有收到挂断而残留 #2054。TestKeymapAddRecordsTheChordPressedAfterIt在 Linux 和 Windows 上一直失败,由 fix(desktop): 快捷键录制测试按当前平台挑选未占用的组合键 #2041 修复,本 PR 合入后接着处理它。internal/sshconn/integration.go,不在本仓库范围内。类型专属:fix
复现与根因
BASH_COMMAND时,实际有 2 次,期望有 1 次。.bash_profile加入 systemd 的写法,用 Homebrew bash 5.3 可以稳定复现同样的 0 次和 2 次。11eb12f9e)从 Motty 引入的 bash 集成脚本里。PROMPT_COMMAND是字符串,遇到数组直接跳过。原注释写的是“数组只出现在有 PS0 的 5.1+”,但系统 profile 也会把它改成数组。$'…',标记字节直接出现在命令文本里。/bin/bash是 3.2,走不到 PS0 路径。检查项
desktop/internal/localshell/integration_unix_test.go。在 macOS 上把修复暂存起来、只保留新测试运行:bashIntegration只被startScript使用。startScript的调用方有两个:本地的integrationScriptWith(macOS/Linux)和wslIntegrationScript(Windows 上的 WSL),两者都用上了修复,WSL 脚本测试TestWSLScriptStartsTheLoginShellInTheStartFolder也通过。zsh 部分没有 DEBUG trap 和 PS0,不受影响。integration_windows.go),不涉及 PS0 和PROMPT_COMMAND;WSL 的 bash 用同一段脚本,本 PR 一并修复。.agents/notes/implemented/bug-fix/记录:约束写在这块代码所属的 Shell 集成 Note(architecture/2026-11-16-local-shell-integration-shim.md)里,和 Motty 的其他差异放在一起,同步时只需要看一处范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:两端的实现状态和验证状态、证据路径、owner、验证动作都如实填写;没有运行验证的保持pending(terminal-shell-integration的验证说明和 notes,状态不变)./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
N/A:没有界面变化,只改了 Shell 启动脚本输出的终端控制序列。
统一日志系统 / Structured logging
N/A:没有新增或改动日志路径。
界面文案 / i18n
N/A:没有用户可见文案。
逻辑归属 / Logic placement
性能与内存 / Performance and memory
N/A:Shell 启动多做一次
declare -p判断;没有新增进程、缓存、定时器或依赖。设置 / Settings
N/A:不涉及设置。
插件契约 / Plugin contract
N/A:不涉及插件契约。
发行包与资源 / Bundle and resources
N/A:启动文件仍写在 Lithe 新建的私有临时目录里,没有新增资源路径。
无用代码与重构 / Dead code and refactoring
refactor标签的 Issue:没有发现验证 / Verification
go test -run 'TestIntegratedBash.*ReportsEachCommandLineOnce|TestIntegratedSystemBashReportsEachCommandLineOnce' ./internal/localshell./.agents/skills/write-stable-tests/scripts/verify-test-stability.sh --base origin/mainrun-go-tests-with-timing.mjs(与test-stability-macos.sh的参数相同,范围是整个./internal/localshell).artifacts/test-stability/index.html./scripts/desktop/desktop-go.sh test -count=1 ./internal/localshell/... ./internal/term/... ./internal/termview/..../scripts/desktop/desktop-go.sh test -race -run ReportsEachCommandLineOnce ./internal/localshellgo vet ./internal/localshell,GOOS=linux go vet ./internal/localshell./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEAD./scripts/agent-notes/verify-agent-notes.shrg未能执行的检查和原因:
test-stability-macos.sh会先扫描整个工作区,被本地另一个会话留下、未跟踪的extension-host/node_modules拦住了。所以这次单独运行了基于--base origin/main的静态检查,再用同样的参数直接运行计时脚本。wsl_unix_test.go只在 Unix 上编译,已经在 macOS 上通过。提交前确认 / Final checks
main创建;目标分支:feat、fix、docs 为main,release 以发布流程要求为准.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图🤖 Generated with Claude Code