Skip to content

feat(plugin): add configurable compaction providers#1549

Open
CanerKocak wants to merge 10 commits intoMoonshotAI:mainfrom
CanerKocak:feat/plugin-compaction
Open

feat(plugin): add configurable compaction providers#1549
CanerKocak wants to merge 10 commits intoMoonshotAI:mainfrom
CanerKocak:feat/plugin-compaction

Conversation

@CanerKocak
Copy link
Copy Markdown

@CanerKocak CanerKocak commented Mar 22, 2026

Related Issue

N/A

Description

This PR adds explicit, user-configurable compaction support to Kimi Code CLI.

Changes in this PR:

  • add loop_control.compaction_model so context compaction can use a dedicated model instead of always reusing the active chat model
  • add loop_control.compaction_plugin so users can select a plugin-provided compactor explicitly
  • extend plugin.json to support compaction.entrypoint for custom compaction implementations
  • thread the dedicated compaction LLM through runtime and use the configured compactor in KimiSoul
  • harden config edge cases around missing models/providers and invalid empty plugin names
  • add tests for config validation, startup wiring, and plugin-based compaction paths

This core work is also intended to support a companion plugin repo, CanerKocak/kimi-morph-plugin, which builds on top of the new plugin-based compaction path as a concrete consumer of these hooks.

morph-plugin-demo.mp4

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

- Extend plugin.json with compaction.entrypoint (module.Class under plugin dir)
- Resolve first loadable compactor from ~/.kimi/plugins (sorted); warn on conflicts
- KimiSoul uses plugin compactor when present, else SimpleCompaction
- Purge cached top-level module before import so plugins can reuse module names

Made-with: Cursor
devin-ai-integration[bot]

This comment was marked as resolved.

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

# Conflicts:
#	CHANGELOG.md
#	docs/en/release-notes/changelog.md
#	docs/zh/release-notes/changelog.md
#	src/kimi_cli/soul/agent.py
#	tests/core/test_startup_progress.py
chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

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: 1c6416f142

ℹ️ 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 on lines +87 to +90
for part in module_parts[:-1]:
parent_dir = parent_dir / part
parent_package = f"{parent_package}.{part}"
_ensure_package_module(parent_package, parent_dir)
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 Load real parent packages for package entrypoints

When compaction.entrypoint points to a submodule (for example mypkg.compactor.MyCompactor), _load_plugin_module() creates synthetic parent package modules via _ensure_package_module() but never executes mypkg/__init__.py. In that case, valid plugins that rely on package-init symbols (e.g. from . import SOME_CONST) fail at import time with ImportError, even though they work with normal Python imports. Parent packages need to be imported/executed, not only stubbed, before loading the target submodule.

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.

2 participants