Skip to content

feat: add /provider refresh subcommand - #4316

Merged
Grapedge merged 2 commits into
MoonshotAI:mainfrom
huangzheng2016:feat/provider-refresh
Oct 21, 2026
Merged

Grapedge merged 2 commits into
MoonshotAI:mainfrom
huangzheng2016:feat/provider-refresh

Conversation

@huangzheng2016

Copy link
Copy Markdown
Contributor

Requirement or Bug

让 /provider 支持在运行时手动刷新 provider 的模型列表(此前只有 TUI 启动时和 kap-server 定时器会自动刷新)。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 /provider [args]
+  refresh [providerId]
+    showProgressSpinner
+    authFlow.refreshProviderModels({ providerId }?)
+      harness.refreshProviderModels → engine ProviderDiscoveryService
+    reportProviderRefresh: changed(+N/-M,removed 用 warning 色) / failed / unchanged
+    modelMigration.retire(retired_default?)
   (无参数) → provider manager 对话框(不变)
+  未知子命令 → usage 提示(此前参数被静默忽略、直接打开对话框)
  • apps/kimi-code/src/tui/commands/provider.ts:新增 refresh 子命令与结果汇报;handleProviderCommand 接收参数。
  • apps/kimi-code/src/tui/commands/dispatch.ts:/provider 把参数传入 handler;SlashCommandHost 接口暴露 modelMigration(KimiTUI 已有该 controller,默认模型退役迁移直接复用)。
  • apps/kimi-code/src/tui/controllers/auth-flow.ts:refreshProviderModels 增加可选 { providerId } 透传(可选参数,向后兼容);有变化时照旧自动 refreshAvailableModels(),界面模型列表立即生效。
  • 文档:docs/en|zh/reference/slash-commands.md 新增 /provider refresh [providerId] 行;docs/en|zh/configuration/providers.md 补充手动刷新说明。
  • 行为细节:不带参数时刷新全部 provider(与 kap-server 定时刷新同一条 scope: 'all' 路径);被下架的 alias 会以 warning 色标出(绑定它的 agent 下一轮会报 "Model X is not configured in config.toml");默认模型被 registry 退役且声明了 upgrade 替代品时,引擎自动迁移所有绑定它的 live agent,TUI 复用现有 model-migration 提示。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
/provider 无参数 打开 provider manager 对话框 不变 所有 TUI 用户 —
/provider refresh [providerId] 不存在(命令描述提到 refresh 但无入口) 运行时刷新全部/单个 provider 的模型列表,按 provider 汇报新增/下架/失败 不想等启动刷新或 kap-server 定时刷新的 TUI 用户 重启 CLI 触发启动刷新,或等 kap-server 定时刷新
/provider <未知文本> 参数被静默忽略,打开对话框 显示 usage 提示 无文档记载的用法;打错字的用户会被提示正确语法 单独输入 /provider

受影响模块与测试覆盖:

  • commands/provider.ts 刷新子命令:test/tui/commands/provider.test.ts 新增 6 个用例(全量汇报 +N/-M 与 failed、单 provider 范围、removed 警告色、retired_default 走迁移、抛错路径、未知子命令 usage)。
  • controllers/auth-flow.ts 可选参数:test/tui/controllers/ 现有用例全过。
  • 整体验证:test/tui/commands/ 295 通过、test/tui/controllers/ 334 通过、tsc --noEmit 与 oxlint 干净。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • 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 Oct 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 60c8a43

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

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

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 commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T11:06:14.774442Z 60c8a43 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026 •

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

commit: 60c8a43

@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: 040ae7301b

ℹ️ 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 184 to 186
const result = await this.host.harness.refreshProviderModels(options);
if (result.changed.length > 0) {
await this.refreshAvailableModels();

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 provider state after config-only refreshes

When a custom registry changes only provider configuration (for example type or baseUrl) while its models are identical, core persists the provider change but returns changed: [] and puts the ID in unchanged. This guard then leaves appState.availableProviders stale, so effort/model protocol decisions keep using old provider data until /reload or restart even though the new runtime command reported success; reload provider state after any successful refresh rather than only model changes.

AGENTS.md reference: AGENTS.md:L104-L104

Useful? React with 👍 / 👎.

// removals surface as a warning rather than a plain status.
const total = change.added + change.removed;
host.showStatus(
`${change.provider_name}: ${parts.join(' / ')} model${total === 1 ? '' : 's'}.`,

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 Handle metadata-only refresh results

Registry responses deliberately represent display-name, capability, or upgrade-only updates as a changed entry with both counters zero. Here parts stays empty, so the command prints output such as Example: models. after a successful metadata refresh; add an explicit metadata-updated message and cover the 0/0 response shape.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

export async function handleProviderCommand(host: SlashCommandHost, rawArgs = ''): Promise<void> {
const args = rawArgs.trim().split(/\s+/).filter((part) => part.length > 0);
if (args[0] === 'refresh') {
await handleProviderRefresh(host, args[1]);

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 Reject extra refresh arguments

With input such as /provider refresh foo unexpected, this branch immediately refreshes foo and silently discards the remaining token; if foo exists, an invocation outside the advertised syntax can mutate its catalog instead of showing the usage error. Validate the argument count before dispatching (or parse the full provider ID) so surplus input does not trigger a refresh.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

Comment thread .changeset/provider-refresh-command.md Outdated
"@moonshot-ai/kimi-code": minor
---

Add a `/provider refresh [providerId]` subcommand that re-fetches model lists from providers at runtime. Run `/provider refresh` to update every provider, or `/provider refresh <providerId>` to update one. Typing an unknown `/provider` subcommand now shows a usage hint instead of silently opening the provider manager.

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 Use a single sentence in the changeset

This user-facing entry contains three sentences, while the repository requires one short sentence that states only what changed; condense it before release so the generated changelog follows the mandated changeset format.

AGENTS.md reference: AGENTS.md:L90-L90

Useful? React with 👍 / 👎.

@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: 60c8a437cc

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

for (const change of result.changed) {
if (change.added === 0 && change.removed === 0) {
// Metadata-only refresh: display name, capabilities, or upgrade info changed.
host.showStatus(`${change.provider_name}: model metadata updated.`);

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 Report default self-healing in zero-count refreshes

When a refresh repairs an absent defaultModel (the rewrites a missing defaultModel even when the catalog is unchanged case in packages/agent-core-v2/test/app/kosongConfig/discovery.test.ts), the engine deliberately returns a changed item with added: 0 and removed: 0 even though no model metadata changed. This branch therefore tells the user only that metadata changed while the command actually selected and persisted a new default model; use wording that covers configuration changes or compare before/after state and report the default switch. This is fresh evidence beyond the earlier malformed models. output.

AGENTS.md reference: AGENTS.md:L112-L112

Useful? React with 👍 / 👎.

@Grapedge
Grapedge merged commit 874d9ab into MoonshotAI:main Oct 21, 2026
16 checks passed
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.

2 participants