Skip to content

feat: add experimental feature-flag system - #205

Merged
liruifengv merged 2 commits into
mainfrom
feat/experimental-flags
May 29, 2026
Merged

feat: add experimental feature-flag system#205
liruifengv merged 2 commits into
mainfrom
feat/experimental-flags

Conversation

@liruifengv

@liruifengv liruifengv commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No tracking issue — the problem is explained below.

Problem

Experimental features have to live in the codebase before they are ready for all users, but today they are gated only by ad-hoc process.env reads scattered across packages, with several different boolean-parsing styles and no single place to see what exists.

What changed

Adds the experimental-flag infrastructure. No flags are defined yet — the registry ships empty; adding the first one is a one-line edit plus a flags.enabled('id') check.

  • Central registry + resolver (packages/agent-core/src/flags/): each flag is declared once as { id, env, default, surface } in FLAG_DEFINITIONS, resolved by a process-global flags constant that reads live process.env. Precedence (high → low): master switch KIMI_CODE_EXPERIMENTAL_FLAG → per-feature KIMI_CODE_EXPERIMENTAL_<NAME> → registry default, with lenient boolean parsing via parseBooleanEnv. FlagId is a literal union derived from the registry, giving flags.enabled('…') autocomplete and typo-checking.
  • SDK boundary: KimiHarness.getExperimentalFlags() returns the resolved values over RPC; the SDK re-exports only the flag types — no runtime value crosses the boundary.
  • TUI gating (generic, ready for use): a slash command may carry an experimentalFlag; when that flag is off the command is hidden from the palette and resolved as an unknown command. Inert today since no command is gated.
  • Docs: a short "Experimental Features" section in AGENTS.md points to the registry.

The changeset intentionally lists only @moonshot-ai/agent-core (the home of the flag system).

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 May 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 51fdd6c

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

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Minor
@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 May 29, 2026

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

commit: 51fdd6c

@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: 71275b0a29

ℹ️ 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 thread packages/agent-core/src/plugin/manager.ts Outdated
@liruifengv
liruifengv force-pushed the feat/experimental-flags branch 2 times, most recently from 3d84d46 to 85aaf54 Compare May 29, 2026 10:51

@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: 85aaf54e00

ℹ️ 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 thread packages/agent-core/src/plugin/manager.ts Outdated
Comment thread apps/kimi-code/src/tui/commands/resolve.ts Outdated
@liruifengv
liruifengv force-pushed the feat/experimental-flags branch 6 times, most recently from 390215a to 6a478de Compare May 29, 2026 11:27
Introduce a central, env-driven flag registry in agent-core. Each flag is declared once with an id, full env var name, default, and surface. Within agent-core, flags are consulted through a process-global 'flags' constant that reads live process.env. Resolution precedence: master switch KIMI_CODE_EXPERIMENTAL_FLAG > per-feature KIMI_CODE_EXPERIMENTAL_<NAME> > registry default, with lenient boolean parsing via parseBooleanEnv. FlagId is a literal union derived from the registry for compile-time autocomplete and typo-checking.

SDK boundary: KimiHarness.getExperimentalFlags() returns the resolved values over RPC, and the SDK re-exports only the flag *types* — no runtime value crosses the boundary. The TUI caches that snapshot once at startup and reads it synchronously for command gating.

Gate the plugin system behind the 'plugins' flag, off by default: PluginManager.load() consults flags.enabled('plugins'), so when off no installed plugins are loaded or activated, and the TUI /plugins command is hidden from the palette and resolves as an unknown command.

Tests cover the resolver precedence matrix, registry invariants, the FlagId type guard, the live-env singleton, the plugin-load gate, the getExperimentalFlags RPC, and the TUI command gating.
@liruifengv
liruifengv force-pushed the feat/experimental-flags branch from 6a478de to 904985d Compare May 29, 2026 11:51
@liruifengv
liruifengv merged commit 96bbc47 into main May 29, 2026
7 checks passed
@liruifengv
liruifengv deleted the feat/experimental-flags branch May 29, 2026 11:55

@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: 51fdd6c4da

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

@@ -0,0 +1,5 @@
---
"@moonshot-ai/agent-core": minor

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 Add the affected packages to the changeset

This changeset only selects @moonshot-ai/agent-core, but the diff also changes apps/kimi-code startup/command behavior and packages/node-sdk public API (KimiHarness.getExperimentalFlags and exported flag types). The repo’s gen-changesets rules require listing packages that were actually changed and adding @moonshot-ai/kimi-code when bundled internal changes enter the CLI; otherwise the release PR can omit the CLI/SDK version and changelog entries for this user-visible/API change.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot mentioned this pull request May 29, 2026
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