Skip to content

feat: add btw side-channel command#338

Open
kermanx wants to merge 5 commits into
mainfrom
xtr/btw-side-agent
Open

feat: add btw side-channel command#338
kermanx wants to merge 5 commits into
mainfrom
xtr/btw-side-agent

Conversation

@kermanx
Copy link
Copy Markdown
Collaborator

@kermanx kermanx commented Jun 2, 2026

Related Issue

No linked issue. This addresses the need to ask side-channel questions without steering or interrupting the active main agent turn.

Problem

Users sometimes need a separate contextual conversation while the main agent is still working. Sending those questions through the normal main prompt path would change the main turn, while ordinary subagent UI is tied to tool-call cards and does not fit a transient side panel.

What changed

Added /btw <question> as an always-available slash command that creates a temporary side agent from the current context and returns its agent id. The initial and follow-up BTW messages use ordinary prompt calls against that agent, cancellation uses ordinary cancel, and tool calls are denied through a prepended permission policy. The TUI renders the side conversation in a focused panel above the input box without polluting the main transcript, and the SDK/core API no longer exposes a dedicated cancelBtw. Bilingual docs and a changeset are included.

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.

Verification

  • pnpm vitest run apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts apps/kimi-code/test/tui/commands/registry.test.ts apps/kimi-code/test/tui/commands/resolve.test.ts packages/agent-core/test/session/init.test.ts packages/agent-core/test/session/subagent-host.test.ts packages/node-sdk/test/session-prompt-events.test.ts packages/node-sdk/test/session-prompt-input.test.ts
  • pnpm --filter kimi-code typecheck
  • pnpm --filter @moonshot-ai/kimi-code-sdk typecheck
  • pnpm --filter @moonshot-ai/agent-core typecheck

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: 59586a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/migration-legacy Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 2, 2026

pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@59586a6
npx https://pkg.pr.new/@moonshot-ai/kimi-code@59586a6

commit: 59586a6

Copy link
Copy Markdown

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

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: c1158893c9

ℹ️ 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 on lines +198 to +205
const { agent: child } = await this.session.createAgent(
{
type: 'sub',
generate: parent.rawGenerate,
persistence: new InMemoryAgentRecordPersistence(),
},
undefined,
this.ownerAgentId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid persisting temporary BTW agents

Each /btw call goes through Session.createAgent, which records the generated subagent in metadata.agents and writes it to state.json; this path only gives the child in-memory wire records and never removes it after the side question finishes. In sessions where users ask multiple side questions, these supposedly temporary agents accumulate across resumes, so Session.resume() later instantiates and replays every stale empty agent, bloating session state and slowing startup. Consider creating these side agents without session metadata persistence or cleaning the metadata entry when the BTW turn completes/cancels.

Useful? React with 👍 / 👎.

this.streamingUI.resetToolUi();
this.sessionEventHandler.resetRuntimeState();
this.tasksBrowserController.close();
this.state.btwPanelContainer.clear();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cancel BTW before clearing the session UI

When a side question is running, the main session still looks idle because /btw does not update streamingPhase, so idle-only commands such as /new or session switching can reach this reset path; this line only hides the BTW panel and drops the event handler state, while the core Session.close() path flushes/shuts down without cancelling active turns. In that scenario the forked BTW request keeps running invisibly and consuming tokens after the user has moved to another session. Cancel the active BTW turn before clearing/unloading the session, or make session-reset commands blocked while BTW is active.

Useful? React with 👍 / 👎.

@kermanx kermanx force-pushed the xtr/btw-side-agent branch from c115889 to cbf9c70 Compare June 2, 2026 12:46
@kermanx kermanx force-pushed the xtr/btw-side-agent branch from cbf9c70 to d02b48c Compare June 2, 2026 12:57
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