Skip to content

feat: add reload commands#383

Open
liruifengv wants to merge 4 commits into
mainfrom
reload-config
Open

feat: add reload commands#383
liruifengv wants to merge 4 commits into
mainfrom
reload-config

Conversation

@liruifengv
Copy link
Copy Markdown
Collaborator

@liruifengv liruifengv commented Jun 3, 2026

Related Issue

No linked issue.

Problem

Users need a way to apply configuration changes from an active TUI without restarting the CLI, while keeping TUI-only preference reloads separate from full session reloads.

What changed

  • Added /reload to reload the current session and apply updated config.toml settings together with tui.toml UI preferences.
  • Added /reload-tui to reload only tui.toml UI preferences without rebuilding the active session.
  • Added Core and SDK reload support plus TUI tests covering command resolution, reload behavior, and transcript preservation.

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
Copy link
Copy Markdown

changeset-bot Bot commented Jun 3, 2026

🦋 Changeset detected

Latest commit: aa19d63

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/acp-adapter Patch
@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

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: 51c70c5425

ℹ️ 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 +203 to +208
async closeForReload(): Promise<void> {
try {
await Promise.allSettled(
Array.from(this.agents.values(), async (agent) => agent.cron?.stop()),
);
await this.flushMetadata();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve background tasks across reload

When /reload is run while a background bash/subagent task is still running, this new close path flushes the task as running but does not stop it or keep the live BackgroundManager; reloadSession then deletes the old Session and resumes a new one, and Agent.resume() reloads persisted tasks via loadFromDisk()/reconcile(), which marks any non-terminal ghost as lost. The result is an orphaned process that is still running but can no longer be listed/stopped or have its output tracked by the reloaded session.

Useful? React with 👍 / 👎.

Comment on lines +1156 to +1167
this.resetSessionRuntime();
this.session = session;
this.harness.setTelemetryContext({ sessionId: session.id });
this.registerSessionHandlers(session);
await this.syncRuntimeState(session);
this.refreshSessionTitle();
try {
await this.refreshSkillCommands(session);
} catch {
/* keep the reloaded session usable even if dynamic skills fail */
}
this.sessionEventHandler.startSubscription();
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 Rehydrate the session snapshot after reload

For sessions with persisted UI state such as todos, background task metadata/counts, or replay-derived transcript state, this path calls resetSessionRuntime() and then starts the live subscription without running the same sessionReplay.hydrateFromReplay(session) flow used by startup and session switching. After /reload, those panes and controller maps are cleared and remain stale until new live events arrive, even though session.reloadSession() has just populated session.getResumeState() with the refreshed snapshot.

Useful? React with 👍 / 👎.

Comment on lines +339 to +343
if (active !== undefined) {
await active.closeForReload();
this.sessions.delete(summary.id);
}
return this.resumeSession({ sessionId: summary.id });
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 Keep the active session recoverable on reload failure

If the new config causes resumeSession() to fail after the old active session has been closed and removed here (for example a configured alias now has an invalid provider or MCP startup fails during resume), the SDK/TUI still keep the same Session wrapper in KimiHarness.activeSessions, but core no longer has that session in this.sessions. Subsequent prompts or even harness.resumeSession({id}) keep using the stale wrapper and hit SESSION_NOT_FOUND, so a failed /reload can wedge the current UI until restart instead of leaving the previous session usable or fully replacing the wrapper.

Useful? React with 👍 / 👎.

Comment on lines +48 to +50
host.setAppState({
availableModels: config.models ?? {},
availableProviders: config.providers ?? {},
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 Apply refreshed default model when no session is active

In the no-active-session /reload path, this only refreshes the model/provider lists, so appState.model and thinking keep their old values even if config.toml changed default_model or default_thinking. Creating a new session afterwards still reads this.state.appState.model in createSessionFromCurrentState(), which can start with the stale alias (or fail if that alias was removed) despite the command reporting that runtime config was reloaded.

Useful? React with 👍 / 👎.

Comment on lines +21 to +22
const config = await host.harness.getConfig({ reload: true });
applyRuntimeConfig(host, config);
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 Reload cached runtime when there is no active session

When /reload is used after closing the current session, this no-active path only calls getConfig({ reload: true }); that re-reads config.toml but does not clear KimiCore's cached ToolServices or reload the plugin manager. The next newly-created session still goes through createSession()/resolveRuntime(), which reuses the old cached services and old plugin-derived skill/MCP/session-start state, so changes to service URLs or plugin files are not actually applied even though the command reports that runtime config was reloaded.

Useful? React with 👍 / 👎.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 3, 2026

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

commit: aa19d63

@liruifengv liruifengv changed the title 新增 /reload 与 /reload-tui 命令 feat: add reload commands Jun 3, 2026
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: aa19d63a5a

ℹ️ 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".

await active.closeForReload();
this.sessions.delete(summary.id);
}
return this.resumeSession({ sessionId: summary.id });
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 Preserve caller-provided MCP servers on reload

When a host creates or resumes a session with mcpServers, those servers are only merged from the create/resume payload before constructing the session runtime; they are not persisted in the session. This new reload path closes the active session and resumes it with only { sessionId }, so any host-scoped MCP servers that were active before /reload disappear after reload, breaking their tools even though the session itself resumes successfully.

Useful? React with 👍 / 👎.

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.

3 participants