Skip to content

feat(tui): detach foreground tasks to background with Ctrl+B - #976

Merged
liruifengv merged 7 commits into
mainfrom
add-to-background
Jun 22, 2026
Merged

feat(tui): detach foreground tasks to background with Ctrl+B#976
liruifengv merged 7 commits into
mainfrom
add-to-background

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This builds on PR #821 (core detachBackground capability) by adding the TUI entry point and the surrounding UX.

Problem

Foreground Bash and subagent tasks block the current turn until they finish. PR #821 added the core RPC to detach an already-running foreground task into a background task, but there was no way to trigger it from the TUI. Users had to either wait for long commands / subagents to finish, or cancel them outright. There was also a subtle UX gap: after a detach, the tool-result prompt nudged the model to call TaskOutput, which re-blocked the main agent and defeated the point of detaching.

What changed

  • Added a Ctrl+B shortcut (active while streaming) that detaches all running foreground Bash / subagent tasks at once. A one-shot footer hint (Moved N tasks to background. /tasks to view.) confirms the action and auto-clears after a few seconds.
  • Tool cards now show a Press Ctrl+B to run in background hint — immediately for subagents (they are long-running by nature), after 10s for Bash (to avoid nagging on short commands). The agent group panel shows the same hint while any subagent is still running in the foreground.
  • Detached foreground subagents now render as ◐ backgrounded instead of flipping to ✓ Completed, so they are visually distinguishable from work that actually finished.
  • The /tasks panel now filters out foreground tasks; they appear in the panel only after being detached.
  • The tool-result prompt after a detach now explicitly tells the model do NOT wait, poll, or call TaskOutput on it; continue with your current work, so detaching actually frees the main agent. The run_in_background=true prompt was also aligned to the Agent tool's no polling needed wording.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

- Add Ctrl+B shortcut to detach all foreground Bash/subagent tasks at once

- Show "Press Ctrl+B to run in background" hint in tool cards (Agent immediately, Bash after 10s) and in the agent group panel

- Mark detached foreground subagents as ◐ backgrounded instead of ✓ Completed

- Filter foreground tasks out of the /tasks panel (they appear after detach)

- Steer the model away from blocking on TaskOutput after a detach
@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d121c64

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code-sdk Patch
@moonshot-ai/kimi-code Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d121c64
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d121c64

commit: d121c64

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9369d94691

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/components/messages/tool-call.ts
Comment thread apps/kimi-code/src/tui/components/editor/custom-editor.ts Outdated
- Preserve `◐ backgrounded` for detached subagents inside AgentGroupComponent by reusing getDerivedSubagentPhase in getSubagentSnapshot

- Distinguish detached-from-foreground subagents from started-in-background ones so the latter still read as `done`

- Let Ctrl+B fall through to readline backward-char at the idle prompt instead of always consuming the key
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a4d03117f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Outdated
Comment thread apps/kimi-code/src/tui/kimi-tui.ts
- Auto-clear the "No foreground task running." hint via showDetachHint so it doesn't stick on the footer

- Don't clobber a newer transient hint (e.g. exit confirmation) when the detach hint timer fires

- Add FooterComponent.getTransientHint()
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bcd26d7b56

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/tui/controllers/session-event-handler.ts
Comment thread apps/kimi-code/src/tui/components/dialogs/tasks-browser.ts
- Only mark foreground-running subagent cards as backgrounded (skip done/backgrounded cards so background resumes don't mutate older rows)

- Count /tasks header from the filtered (background-only) task set so foreground-only sessions don't read misleading counts
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5749a265b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .changeset/foreground-task-detach.md
Comment thread apps/kimi-code/src/tui/kimi-tui.ts
Comment thread apps/kimi-code/src/tui/components/messages/tool-call.ts
@liruifengv
liruifengv merged commit e7dd138 into main Jun 22, 2026
8 checks passed
@liruifengv
liruifengv deleted the add-to-background branch June 22, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant