feat(agent): 新增右侧会话终端【已审核 PR】#956
Open
Andreaseszhang wants to merge 1 commit into
Open
Conversation
ErlichLiu
reviewed
Jun 28, 2026
ErlichLiu
left a comment
Collaborator
There was a problem hiding this comment.
感谢 PR!终端嵌入右侧面板的想法很好,提一个关于 CWD 选择的 UX 反馈:
核心问题:当前 CWD 死绑定会话目录,脱离用户真实意图
目前终端的 cwd 固定为 ~/.proma/agent-workspaces/{slug}/{sessionId}/,但用户打开终端的真实场景是——正在看 diff 面板里的改动文件,想顺手跑个命令。这时候终端进的是会话 UUID 目录,跟 diff 里显示的改动文件完全无关,用户还得手动 cd 到 worktree 根目录去,体验断层。
建议:让终端 CWD 跟随 diff 上下文
改动的文件 终端 CWD
──────────────────────────────────────────────
(无选中,有改动列表) → 改动文件的公共 git root
选中 ChatInput.tsx → apps/electron/src/renderer/components/chat/
多根目录改动 → 可快速切换的根目录列表
DiffTabContent 已经接收了 dirPath 和 gitRoot,信息是现成的——只是没传到终端。
本质是场景思考
终端放在"Git 改动" Tab 下方,用户的心智模型是"我在看 Agent 改了什么,终端帮我快速验证"。如果 CWD 跟 diff 脱节,这个联动就失去了意义——还不如开外部终端。
建议终端的默认 CWD 等于改动文件的公共根目录(单 worktree 场景),或者提供根目录切换(多 worktree 场景),让用户打开就能用。
c60cb1c to
8513110
Compare
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.
概述
这个 PR 在 Agent 右侧面板的「Git 改动」下方加入内置 Terminal 区域,让每个 Agent 会话可以在自己的 session 目录下直接使用 shell。实现包含主进程 PTY 管理、renderer 端 xterm 展示、多终端 tab、折叠/拖拽、主题同步、输出节流与缓存、终端数量限制,以及 node-pty 打包权限处理。
改动
apps/electron/src/main/lib/terminal-service.ts— 新增主进程终端服务,基于 node-pty 启动 zsh/bash,按会话和 webContents 管理终端,提供输出 buffer、16ms/33ms 合并刷新、后台会话降频、最大缓存、backpressure、关闭/resize/list/reconnect/busy 查询等能力。packages/shared/src/types/terminal.ts— 新增终端 IPC 输入输出类型、事件类型和 channel 常量。apps/electron/src/main/ipc.ts、apps/electron/src/preload/index.ts— 暴露终端启动、写入、resize、关闭、列表、当前会话、忙碌状态查询和 data/exit 事件订阅 API。apps/electron/src/renderer/components/agent/TerminalPanel.tsx— 新增右侧终端 UI,支持每个会话自动启动终端、多 tab、最多单会话 4 个终端、切会话内存级保持、折叠、上下拖拽、主题实时同步、关闭运行中进程确认和重连输出恢复。apps/electron/src/renderer/components/agent/SidePanel.tsx、apps/electron/src/renderer/components/diff/DiffTabContent.tsx— 将 Git 改动区域上下拆分,在「文件改动」视图下显示 terminal,会话文件/工作区文件视图不显示。apps/electron/src/renderer/styles/globals.css— 增加 terminal tab 选中指示条样式,选中态用文字色和底部条表达,指示条按标题长度动态收缩,避免 tab 被不均匀压缩或指示条过长。apps/electron/scripts/fix-node-pty-permissions.cjs、apps/electron/electron-builder.yml、apps/electron/package.json、bun.lock— 接入 node-pty/xterm 依赖,构建前校验 native 产物和 spawn-helper 权限,并在 electron-builder 中包含 node-pty prebuild 文件。apps/electron/src/main/lib/agent-session-manager.ts— 删除 Agent 会话时同步停止该会话全部终端,避免后台 PTY 泄漏。packages/shared/package.json— 递增 shared patch 版本。测试方法
bun run --filter=@proma/electron typecheck,确认 Electron 包类型检查通过。bun run --filter=@proma/shared typecheck,确认 shared 包类型检查通过。bun run --filter=@proma/electron build:main,确认主进程构建和 node-pty 权限校验通过。bun run --filter=@proma/electron build:preload,确认 preload 构建通过。bun run --filter=@proma/electron build:renderer,确认 renderer 构建通过。git diff --check upstream/main...HEAD,确认没有 whitespace 问题。备注
Andreaseszhang/Promafork,PR base 仍是ErlichLiu/Proma:main。