Skip to content

feat(env): migrate kimi-cli model request params and auto-update toggle - #458

Merged
RealKai42 merged 3 commits into
mainfrom
migrate-kimi-cli-env-vars
Jun 5, 2026
Merged

RealKai42 merged 3 commits into
mainfrom
migrate-kimi-cli-env-vars

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

背景

kcode-open 是 kimi-cli 的 TS 重制版。对比两边环境变量后,把 kimi-cli 中仍有价值、但 kcode-open 缺失的变量迁移过来。

迁移的变量(全局生效,仅对 `kimi` provider)

变量 作用
`KIMI_MODEL_THINKING_KEEP` Moonshot 保留思考 `thinking.keep` 透传,仅在 Thinking 开启时注入
`KIMI_MODEL_TEMPERATURE` 采样温度
`KIMI_MODEL_TOP_P` 核采样 top_p
`KIMI_CODE_NO_AUTO_UPDATE`(+ 兼容旧名 `KIMI_CLI_NO_AUTO_UPDATE`) 完全禁用自动更新预检

语义对齐 kimi-cli 的 `create_llm`:对任何 kimi provider 全局生效,不依赖 `KIMI_MODEL_NAME`。

实现

  • `kosong`:导出 `KimiChatProvider` + 相关类型,供上层 `instanceof` 判断(对应 kimi-cli 的 `isinstance(chat_provider, Kimi)`)。
  • `agent-core`:新增 `applyKimiEnvGenerationParams`,在 `Agent.get llm()`(全局唯一 LLM 构造点)接线,复用 kosong 已有的 `GenerationKwargs` / `thinking.keep` 透传能力。
  • `kimi-code`:`runUpdatePreflight` 入口早退禁用更新。

关于 `KIMI_MODEL_MAX_TOKENS`(有意未改动)

它在 kcode-open 早已存在并生效——`completion-budget.ts` 已把它作为 `KIMI_MODEL_MAX_COMPLETION_TOKENS` 的 legacy alias 全链路处理。再迁移会产生重复且冲突的两套来源,故复用现有实现,不重复迁移。

不迁移(无承接点 / 已被等价承接)

`KIMI_WEB_`、`KIMI_VIS_RESTRICT_OPEN_IN`、`KIMI_CLI_PASTE_`、`KIMI_FILE_UPLOAD_WITHOUT_MESSAGE`、`KIMI_ANSI_THEME*`(功能不存在);`KIMI_CLI_GIT_BASH_PATH`→已有 `KIMI_SHELL_PATH`、`KIMI_SHARE_DIR`→已有 `KIMI_CODE_HOME`。

测试

  • 全程 TDD(先写失败测试 → 实现 → 通过)。
  • 新增 `resolve.test.ts`、`kimi-env-params.test.ts`,扩展 `preflight.test.ts`。
  • agent-core + kosong:2478 passed;kimi-code update 区:72 passed;lint 0/0。
  • 文档(en/zh env-vars)与 changeset 已同步。

Migrate still-relevant environment variables from kimi-cli:

- KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P: sampling params applied
  globally to any kimi provider (not tied to KIMI_MODEL_NAME).
- KIMI_MODEL_THINKING_KEEP: Moonshot preserved-thinking passthrough
  (thinking.keep), injected only while Thinking is on.
- KIMI_CODE_NO_AUTO_UPDATE (legacy alias KIMI_CLI_NO_AUTO_UPDATE):
  fully disables the update preflight.

Wires env -> provider in Agent.get llm() via applyKimiEnvGenerationParams,
reusing kosong's existing GenerationKwargs / thinking.keep support.
KIMI_MODEL_MAX_TOKENS is intentionally untouched: it already flows through
the completion-budget path.
@changeset-bot

changeset-bot Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 675c355

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 Minor
@moonshot-ai/kosong Patch
@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

@pkg-pr-new

pkg-pr-new Bot commented Jun 5, 2026 •

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

commit: 675c355

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

ℹ️ 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/agent-core/src/agent/index.ts Outdated
Comment on lines +214 to +217
const provider = applyKimiEnvGenerationParams(
this.config.provider.withThinking(this.config.thinkingLevel),
this.config.thinkingLevel,
);

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 env params to compaction requests too

This only wraps the provider used by Agent.llm, but full-history compaction builds its own provider at packages/agent-core/src/agent/compaction/full.ts:243-250 from this.agent.config.provider and then calls this.agent.generate(...) directly. In sessions that trigger compaction, KIMI_MODEL_TEMPERATURE, KIMI_MODEL_TOP_P, and KIMI_MODEL_THINKING_KEEP are therefore not applied to those Kimi requests, despite the new behavior being documented/changesetted as global for every Kimi request.

Useful? React with 👍 / 👎.

RealKai42 added 2 commits June 5, 2026 14:16
Sink KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P into ConfigState.provider so
every request built from config.provider — main loop and full-history
compaction alike — carries them, matching kimi-cli where these live on the
shared create_llm provider. thinking.keep stays in Agent.llm because it
depends on the runtime thinking state (compaction runs thinking-off and
correctly skips it).

Splits applyKimiEnvGenerationParams into applyKimiEnvSamplingParams (applied
at provider construction) and applyKimiEnvThinkingKeep (applied in Agent.llm).

Addresses PR review feedback about compaction requests bypassing the wrapped
provider.
Resolve overlap with #464 (preserve thinking during compaction): both sink
provider request config from Agent.llm into ConfigState.provider. #464 sinks
withThinking; this branch sinks the KIMI_MODEL_* sampling params and
thinking.keep alongside it. Net effect: compaction — which now carries
thinking via #464 — also carries temperature/top_p and (when thinking is on)
thinking.keep. Agent.llm now simply reads config.provider.
@RealKai42
RealKai42 merged commit 93eb70a into main Jun 5, 2026
8 checks passed
@RealKai42
RealKai42 deleted the migrate-kimi-cli-env-vars branch June 5, 2026 06:54
@github-actions github-actions Bot mentioned this pull request Jun 5, 2026
sailist pushed a commit that referenced this pull request Jun 9, 2026
…le (#458)

* feat(env): migrate kimi-cli model request params and auto-update toggle

Migrate still-relevant environment variables from kimi-cli:

- KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P: sampling params applied
  globally to any kimi provider (not tied to KIMI_MODEL_NAME).
- KIMI_MODEL_THINKING_KEEP: Moonshot preserved-thinking passthrough
  (thinking.keep), injected only while Thinking is on.
- KIMI_CODE_NO_AUTO_UPDATE (legacy alias KIMI_CLI_NO_AUTO_UPDATE):
  fully disables the update preflight.

Wires env -> provider in Agent.get llm() via applyKimiEnvGenerationParams,
reusing kosong's existing GenerationKwargs / thinking.keep support.
KIMI_MODEL_MAX_TOKENS is intentionally untouched: it already flows through
the completion-budget path.

* fix(env): apply Kimi sampling params to compaction requests too

Sink KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P into ConfigState.provider so
every request built from config.provider — main loop and full-history
compaction alike — carries them, matching kimi-cli where these live on the
shared create_llm provider. thinking.keep stays in Agent.llm because it
depends on the runtime thinking state (compaction runs thinking-off and
correctly skips it).

Splits applyKimiEnvGenerationParams into applyKimiEnvSamplingParams (applied
at provider construction) and applyKimiEnvThinkingKeep (applied in Agent.llm).

Addresses PR review feedback about compaction requests bypassing the wrapped
provider.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
…le (MoonshotAI#458)

* feat(env): migrate kimi-cli model request params and auto-update toggle

Migrate still-relevant environment variables from kimi-cli:

- KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P: sampling params applied
  globally to any kimi provider (not tied to KIMI_MODEL_NAME).
- KIMI_MODEL_THINKING_KEEP: Moonshot preserved-thinking passthrough
  (thinking.keep), injected only while Thinking is on.
- KIMI_CODE_NO_AUTO_UPDATE (legacy alias KIMI_CLI_NO_AUTO_UPDATE):
  fully disables the update preflight.

Wires env -> provider in Agent.get llm() via applyKimiEnvGenerationParams,
reusing kosong's existing GenerationKwargs / thinking.keep support.
KIMI_MODEL_MAX_TOKENS is intentionally untouched: it already flows through
the completion-budget path.

* fix(env): apply Kimi sampling params to compaction requests too

Sink KIMI_MODEL_TEMPERATURE / KIMI_MODEL_TOP_P into ConfigState.provider so
every request built from config.provider — main loop and full-history
compaction alike — carries them, matching kimi-cli where these live on the
shared create_llm provider. thinking.keep stays in Agent.llm because it
depends on the runtime thinking state (compaction runs thinking-off and
correctly skips it).

Splits applyKimiEnvGenerationParams into applyKimiEnvSamplingParams (applied
at provider construction) and applyKimiEnvThinkingKeep (applied in Agent.llm).

Addresses PR review feedback about compaction requests bypassing the wrapped
provider.
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