feat: add btw side-channel command#338
Conversation
🦋 Changeset detectedLatest commit: 59586a6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
commit: |
There was a problem hiding this comment.
💡 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".
| const { agent: child } = await this.session.createAgent( | ||
| { | ||
| type: 'sub', | ||
| generate: parent.rawGenerate, | ||
| persistence: new InMemoryAgentRecordPersistence(), | ||
| }, | ||
| undefined, | ||
| this.ownerAgentId, |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 👍 / 👎.
c115889 to
cbf9c70
Compare
cbf9c70 to
d02b48c
Compare
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 dedicatedcancelBtw. Bilingual docs and a changeset are included.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, 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.tspnpm --filter kimi-code typecheckpnpm --filter @moonshot-ai/kimi-code-sdk typecheckpnpm --filter @moonshot-ai/agent-core typecheck