Skip to content

fix(kimi-code): honor --agent-file and --agent at TUI launch - #2770

Open
mohidmakhdoomi wants to merge 1 commit into
MoonshotAI:mainfrom
mohidmakhdoomi:fix/2767-tui-agent-file
Open

fix(kimi-code): honor --agent-file and --agent at TUI launch#2770
mohidmakhdoomi wants to merge 1 commit into
MoonshotAI:mainfrom
mohidmakhdoomi:fix/2767-tui-agent-file

Conversation

@mohidmakhdoomi

@mohidmakhdoomi mohidmakhdoomi commented Aug 10, 2026

Copy link
Copy Markdown

Related Issue

Resolve #2767

Problem

See linked issue: launching the interactive TUI with --agent-file or --agent silently starts the session on the built-in default agent. The same flags work in -p print mode, so there is no error — just the wrong agent.

What changed

The interactive TUI runs on the agent-core-v2 engine, whose SDK client dropped both agent options at session creation and always bound the default profile. Print mode takes a different path and was unaffected.

  • The CLI now hands --agent-file to the harness, which forwards it to the engine's BootstrapInput.args.agentFiles the same way --skills-dir is already forwarded. The SDK gains a matching agentFiles harness option (createKimiHarnessV2 only; the option's docs say so).
  • The requested profile joins the model/thinking bind the client already performs after the session is wired, so the warnings the bind publishes still reach listeners.
  • The profile name is checked against the workspace agent catalog before the session is created, so an unknown name fails before the SessionStart hook runs or session_started is recorded — same order as the legacy engine. The rejection also carries the legacy engine's public error shape (KimiError with agent.not_found) on both engines, keeping one error contract for SDK consumers.
  • A bind that still fails after that check rolls the session back instead of leaving it behind.
  • Selecting a profile stays per-session, while the registered file stays in the agent catalog for the rest of the launch (available for sub-agent delegation; a file named after a built-in keeps replacing it). Both doc locales state this.

Tests: nine agent-path tests across the SDK client and CLI suites, each failing without the fix.

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.

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 88b43b1

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/kimi-code Patch
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/acp-adapter Patch
kimi-code 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

@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: 7ec11430ec

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/node-sdk/src/sdk-rpc-client-v2.ts
Comment thread packages/node-sdk/src/sdk-rpc-client-v2.ts Outdated
@mohidmakhdoomi
mohidmakhdoomi force-pushed the fix/2767-tui-agent-file branch from 7ec1143 to 957bee6 Compare August 10, 2026 02:57
@mohidmakhdoomi

Copy link
Copy Markdown
Author

@codex review

@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: 957bee61eb

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/en/reference/kimi-command.md Outdated
The interactive TUI runs on the agent-core-v2 engine by default, and that
engine's SDK client dropped both agent options at session creation: it read
only the session id, work dir, additional dirs, model, thinking, permission
and metadata, then bound the default profile. The startup session therefore
started on the built-in agent with no warning, while print mode — which takes
a different path — bound the requested one.

Register explicit agent files on the client's engine bootstrap, the way skill
directories already are and the way print mode already registers the same
flag, and pass a requested profile into the bind the client already performs
for the model and thinking effort. That bind deliberately stays where it is,
after the session is wired: it publishes the oversized AGENTS.md and
tool-pattern warnings, the agent event bus has no replay, and the tool-pattern
warning is emitted once per pattern, so binding any earlier would drop them.

Binding that late means the session already exists by the time an unusable
profile name is caught, and creating a session runs the SessionStart hook and
records the start as its last step. So the name is resolved against the
workspace's agent catalog before anything is created, the way the legacy
engine resolves it before its store write, and deleting the session is kept
only as a backstop for a bind that fails after that check passes.

The CLI hands the files to the harness, which is built before any session
exists and is the only place a launch-wide registration can happen. Selecting
a profile stays per-session, so a session created later still starts on the
default agent — though a file named after a built-in agent keeps replacing
that built-in for the rest of the launch, which the docs now state.
@mohidmakhdoomi
mohidmakhdoomi force-pushed the fix/2767-tui-agent-file branch from 957bee6 to 88b43b1 Compare August 10, 2026 03:15
@mohidmakhdoomi

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 88b43b108e

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

TUI ignores --agent-file at launch; startup session binds default agent (works in -p print mode)

1 participant