feat: badge background Bash tasks by reusing the launch card#23
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements support for background Bash tasks by reusing the original launch terminal card instead of creating a duplicate background card. It updates the protocol documentation, tracks launch card reuse in BackgroundTaskListener, threads the background flag through the event translator, and adds corresponding unit tests. The review feedback identifies a critical bug in src/handlers/background-tasks.ts where the actual command output is incorrectly skipped on completion if the launch acknowledgement was already streamed. To resolve this, the reviewer suggests removing the !alreadyStreamed check to rely on prefix-diffing, and provides a corresponding test update to assert that the final output is correctly streamed.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Solution: reuse the launch card
让 BackgroundTaskListener 把后台生命周期路由回发起卡片,单卡呈现完整生命周期,不再产生重复卡片。
Changes
1.
translators/event-translator.ts+translators/types.ts— 透传background标志input.run_in_background识别后台 Bash,缓存到backgroundCallIds: Set<string>ToolCallNew/ToolCallUpdate加background?: boolean字段tool.updated { kind:"result" }的inputOmitted:true难题——通过scheduled阶段缓存的 callId 查询2.
handlers/dispatch.ts— 后台 Bash 发起卡保持 in_progressdispatchTerminalUpdate新增skipExit选项terminal_exit,只发terminal_output,卡片保持in_progressterminalSentData留空标记,作为"这是被跟踪的发起卡"信号给 BackgroundTaskListener3.
handlers/background-tasks.ts— 复用发起卡片 + 完成时收尾onTaskStatus检测到session.updated.toolCallId在terminalSentData中时,复用该 toolCallId(不再新建bg_*)terminal_output(若 launch text 没流过)+terminal_exit收尾,清理terminalSentDatamarkCancelled对复用卡片同样补terminal_exitbg_*新建卡片逻辑,feat: sync sub-agent and background task events to ACP client #21 完全不受影响4.
docs/PROTOCOL.md— 新增 "Background Bash" 小节,说明复用机制与 Agent 子代理(新建bg_*)的区别Fallback matrix
terminalSentData有 toolCallId)bg_*卡片(#21 原行为)toolCallId存在但未跟踪(老后端)bg_*卡片(安全回退)Verification
pnpm typecheck✅pnpm test✅ 271 tests passed(含新增 16 个)Untouched
run_in_background:feat: sync sub-agent and background task events to ACP client #21 已处理,本次不动tool-helpers.ts的parseSubagentMetadata/BACKGROUND_RE:不动Bash: <cmd>/execute,靠 in_progress→completed 状态机区分而非改名EOF