Skip to content

feat: add default_swarm_mode config option - #2670

Open
zelinewang wants to merge 2 commits into
MoonshotAI:mainfrom
zelinewang:feat/default-swarm-mode
Open

feat: add default_swarm_mode config option#2670
zelinewang wants to merge 2 commits into
MoonshotAI:mainfrom
zelinewang:feat/default-swarm-mode

Conversation

@zelinewang

@zelinewang zelinewang commented Aug 5, 2026

Copy link
Copy Markdown

Related Issue

Resolve #720

Problem

See linked issue. config.toml supports default_plan_mode but has no swarm equivalent, so users who want swarm mode in every session have to remember to type /swarm on at the start of each one.

What changed

Rebase note (2026-08-05): rebased onto current main after #2599 removed apps/kimi-web (web UI source moved to the code-app repo) and #2627 made agent-core-v2 the default CLI engine. The earlier revision's kimi-web changes are dropped as obsolete; the REST config schema additions below are what a web client (now living in code-app) consumes. With v2 as the default engine, the agent-core-v2 path here is the primary one; the v1 path covers KIMI_CODE_LEGACY_FLAG=1.

Adds a default_swarm_mode boolean config option (default false — no behavior change unless opted in) that mirrors default_plan_mode end to end:

  • v1 (agent-core): config schema (+ patch schema), TOML round-trip scalar, config-service response mapping, and a createSession hook that enters swarm mode on fresh sessions. Resumed sessions restore their own swarm state from wire records and never re-apply the default.
  • v2 (agent-core-v2): new agent/swarm/configSection.ts (registered, defaultValue: false), applied in SessionLifecycleService.create; config manifest regenerated.
  • Wire/SDK: default_swarm_mode added to the protocol and kap-server REST config schemas (response + patch) and the node-sdk v2 config mapper.
  • TUI: footer swarm state hydrates from the config default before the first lazy session exists.
  • Docs: config-files.md (en/zh) complete-example block and field table.

Why this approach: it follows the existing default_plan_mode pattern 1:1, so the behavior is consistent wherever sessions are created (TUI, SDK, kap-server, ACP). The entry uses the 'manual' trigger — task/tool swarm entries auto-exit at turn end, which would make a session-level default pointless; 'manual' is exactly what /swarm on does, and a per-session /swarm off persists across resume via the wire records.

Testing: new v2 lifecycle bootstrap cases (fresh/absent/resume, enter-with-'manual'), a v1 wire-record harness test (same matrix from a real config.toml), config parse + v1/v2 parity assertions, and TUI hydration. Full suites green for all touched packages (agent-core, agent-core-v2, node-sdk, protocol, kap-server, kimi-code), plus clean typecheck and lint.

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 Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 563903d

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/kimi-code Patch
@moonshot-ai/kimi-code-sdk 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

When default_swarm_mode = true is set in config.toml, every freshly
created session enters swarm mode (trigger 'manual', equivalent to an
explicit /swarm on). Resumed sessions restore their own swarm state
from records and never re-apply the default; /swarm off still
overrides per session.

Mirrors the existing default_plan_mode behavior end to end: v1
(agent-core) config schema/toml/configService plus the createSession
hook, v2 (agent-core-v2) config section registration plus the
sessionLifecycle hook, wire schemas (protocol, kap-server), node-sdk
config mapper, TUI footer hydration, and docs.

Refs MoonshotAI#720.
@zelinewang
zelinewang force-pushed the feat/default-swarm-mode branch from cb43e29 to 6976782 Compare August 6, 2026 00:59

@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: 6976782ba8

ℹ️ 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 .changeset/default-swarm-mode.md Outdated
Comment on lines +2 to +3
"@moonshot-ai/kimi-code": minor
"@moonshot-ai/kimi-code-sdk": 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.

P1 Badge Use patch bumps for this config addition

When this changeset is consumed during release, both packages will receive minor versions even though default_swarm_mode only adds a global default for the existing swarm feature. The required gen-changesets policy classifies additions to an existing feature's configuration as patch, so change both frontmatter entries to patch to avoid unnecessary minor releases.

AGENTS.md reference: AGENTS.md:L82-L83

Useful? React with 👍 / 👎.

@@ -0,0 +1,100 @@
import { mkdtemp, mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';

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 Consolidate the swarm bootstrap tests

This creates a separate harness test file even though packages/agent-core/test/harness/plan-mode-session.test.ts already covers the corresponding mode-bootstrap lifecycle and this file duplicates its rig and scenario matrix. Move these swarm cases into that existing test file so coverage for the same component is not fragmented.

AGENTS.md reference: AGENTS.md:L59-L60

Useful? React with 👍 / 👎.

Review follow-ups: defaulting an existing feature's config is a patch
bump per the gen-changesets policy, and the swarm bootstrap cases belong
in the existing plan-mode-session harness suite (AGENTS.md test
placement convention).
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.

Feature request: configurable default swarm mode

1 participant