Skip to content

feat: add configurable tool catalog and mode availability - #4797

Draft
liruifengv wants to merge 6 commits into
feat/custom-subagent-settingsfrom
feat/session-tool-policy
Draft

liruifengv wants to merge 6 commits into
feat/custom-subagent-settingsfrom
feat/session-tool-policy

Conversation

@liruifengv

@liruifengv liruifengv commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Desktop needs a built-in tool settings page whose switches apply to both current and new sessions. The server therefore needs a session-independent tool catalog, global [tools] config mapping, current mode-availability information, and server-side entry guards for modes whose required tools are disabled.

This PR intentionally does not snapshot tool defaults per session. Existing global tool policy remains dynamic for loaded agents, subagents, restored sessions, and newly created sessions.

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

Core idea

flowchart LR
    Catalog[Static and runtime tool metadata] --> API[GET /tools/catalog]
    Config[Global tools config] --> REST[Config REST mapping]
    Config --> Existing[Existing agent policy]
    Config --> New[New and restored agent policy]
    Existing --> Availability[Mode availability in agent frames]
    Existing --> Guards[Mode entry guards]
    Availability --> Desktop[Desktop entry visibility]
Loading

The existing AgentToolPolicyService continues to listen for global config changes. There is no defaultTools state, session snapshot, migration, or cold-restore snapshot path. Availability is computed from current policy whenever an agent frame is produced; changing [tools] alone does not publish an additional frame.

Main changes

  • Add GET /api/v1/tools/catalog and expose tools.enabled / tools.disabled through the config REST schema.
  • Mark user-configurable built-in tool contributions. Combine them with media-owned runtime tool metadata and deduplicate catalog entries by name.
  • Add plan_mode_available, swarm_mode_available, tower_mode_available, and goal_mode_available to initial and subsequent agent frames.
  • Reject Plan, Swarm, Tower, and autonomous Goal entry when required tools are unavailable. Pause, cancel, and mode exit remain available.
  • Skip automatic defaultPlanMode entry when ExitPlanMode is disabled.
  • Require the complete 13-tool Tower set. Tower availability augments the profile allowlist with the tools that entry itself would add, while global, workspace, session, and disallowedTools denials still apply.
  • Document the catalog, config fields, availability fields, and the lack of a config-change frame publisher in English and Chinese.

Reading guide

  1. packages/kap-server/src/routes/tools.ts and packages/agent-core-v2/src/agent/toolRegistry/toolContribution.ts — catalog metadata and endpoint.
  2. packages/kap-server/src/transport/ws/v1/agentState.ts — availability frame fields.
  3. packages/agent-core-v2/src/features/{plan,swarm,tower,goal} — entry requirements and guards.
  4. packages/kap-server/test/tools.test.ts and packages/kap-server/test/sessionEventBroadcaster.test.ts — dynamic old/new-session policy and frame coverage.

The session snapshot, Goal prompt, restore-time tool-removal, and reminder changes formerly explored on this branch are not part of the final diff.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Global [tools] semantics Dynamically applied to loaded and new agents Unchanged; no session default snapshot is introduced TUI, desktop, web, VS Code, ACP, and SDK users Existing config behavior is preserved
Tool catalog No session-independent configurable-tool catalog Adds GET /api/v1/tools/catalog with static and runtime built-in metadata Desktop settings and other API clients Additive endpoint; existing /tools is unchanged
Agent frames Reported active Plan/Swarm/Tower modes only Also reports all four mode-availability booleans Desktop and other WebSocket consumers Additive fields; no config-only frame publisher is added
Frame timing after [tools] changes No availability fields existed Availability refreshes on the next snapshot or existing agent frame, not immediately on config save Clients showing current-session entry points Switch/resubscribe or wait for the next existing frame
Plan/Swarm entry Could enter without ExitPlanMode / AgentSwarm Entry is rejected when the required tool is inactive TUI, desktop, web, and SDK users with restricted tools Enable the required tool
defaultPlanMode Always attempted Plan entry Silently skips automatic entry when ExitPlanMode is unavailable Users combining default Plan mode with restricted tools Enable ExitPlanMode or disable default Plan mode
Tower entry Gated by experiment, feature assembly, main agent, and workspace ownership Also requires the complete Tower tool set Experimental Tower users with partial allowlists Enable all 13 Tower tools
Autonomous Goal create/resume Could create or resume without UpdateGoal Create and resume are rejected; pause and cancel remain available Users running goals with restricted tools Enable UpdateGoal
Active modes and goals Existing mode state and controls Active-mode state, exit, Goal pause, and Goal cancel are not removed by these guards Users who disable tools while a mode or goal is active Existing exit/pause/cancel actions remain

Affected contracts are additive: the tool catalog route, config tools field, and agent availability booleans. No wire, session-state, SDK method, or old-client fallback contract is introduced.

Verification
  • 493 targeted agent-core tests passed across Goal, Plan, Swarm, and Tower suites.
  • 93 targeted kap-server tests passed across config, tools, agent frames, and API surface coverage.
  • After the catalog metadata refinement, all 15 tools-route tests passed again.
  • After CI exposed three additional test setups, 113 loop, Goal state, and Plan guard tests passed with explicit default tool-policy conditions.
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck: passed.
  • pnpm --filter @moonshot-ai/kap-server typecheck: passed.
  • Pre-commit type-aware oxlint and comment checks passed.
  • Read-only final-diff audit found no secrets, private endpoints, unpublished model identifiers, real session data, snapshot remnants, config-only frame publisher, or unrelated main-branch changes.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (this is an internal feature request with no linked issue).
  • 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; added .changeset/configurable-tool-catalog.md.
  • Ran gen-docs skill assessment and updated the relevant English and Chinese server API pages.

Companion desktop PR: https://github.com/MoonshotAI/kimi-code-app/pull/1239

Copilot AI lite review requested due to automatic review settings November 10, 2026 08:35
@changeset-bot

changeset-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b91c13b

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

Copilot AI 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.

🟡 Changes recommended

Two moderate active issues remain: task-tool guidance incorrectly disappears when only one tool is disabled, and connected clients can receive stale tool-availability state after session policy changes.

2 open issues
What changed in this PR

This PR makes [tools] a session-scoped default policy captured at session creation, persisted for recovery, inherited by subagents, and used consistently for tool availability, mode entry, prompts, and reminders.

Changes:

  • Persist and restore session-level default tool policies, including legacy-session initialization.
  • Add tool catalog and configuration API support plus WebSocket mode-availability fields.
  • Enforce required tools for Plan, Swarm, Tower, and autonomous goals while updating consumers, reminders, tests, manifests, and documentation.
File Description
packages/​kap-server/​test/​tools.test.ts Tests the tool catalog and old/new session policy isolation.
packages/​kap-server/​test/​config.test.ts Tests REST configuration merging and reporting for tool policies.
packages/​kap-server/​test/​__snapshots__/​apiSurface.snapshot.test.ts.snap Updates the API snapshot for the tool catalog route.
packages/​kap-server/​src/​transport/​ws/​v1/​agentState.ts Adds mode-availability values to WebSocket agent state frames.
packages/​kap-server/​src/​routes/​tools.ts Implements the user-configurable tool catalog endpoint.
packages/​kap-server/​src/​protocol/​ws-agent.ts Extends the WebSocket agent-state schema with availability fields.
packages/​kap-server/​src/​protocol/​tool.ts Defines schemas for tool catalog entries.
packages/​kap-server/​src/​protocol/​rest-tool.ts Defines the REST tool catalog response schema.
packages/​kap-server/​src/​protocol/​rest-config.ts Adds tool policy fields to REST configuration schemas.
packages/​agent-core-v2/​test/​session/​subagent/​subagentScopeCache.test.ts Updates subagent session-policy test fixtures.
packages/​agent-core-v2/​test/​session/​agentLifecycle/​agentLifecycle.test.ts Updates agent lifecycle session-policy test fixtures.
packages/​agent-core-v2/​test/​features/​tower/​towerService.test.ts Tests Tower entry rejection when required tools are unavailable.
packages/​agent-core-v2/​test/​features/​tower/​tools/​towerTools.test.ts Updates Tower service fixtures for tool availability.
packages/​agent-core-v2/​test/​features/​swarm/​swarm.test.ts Tests Swarm entry policy enforcement.
packages/​agent-core-v2/​test/​features/​plan/​plan.test.ts Tests Plan entry requirements and policy-aware fixtures.
packages/​agent-core-v2/​test/​features/​notify/​notifyUserNudgeService.test.ts Tests NotifyUser nudges under restricted tool policies.
packages/​agent-core-v2/​test/​features/​goal/​injection/​goalInjection.test.ts Tests goal guidance and UpdateGoal availability behavior.
packages/​agent-core-v2/​test/​features/​goal/​goal.test.ts Updates goal lifecycle tests to include required policy tools.
packages/​agent-core-v2/​test/​app/​agentProfileCatalog/​profile-shared.test.ts Tests retaining skill catalog visibility when Skill invocation is disabled.
packages/​agent-core-v2/​test/​agent/​toolSelect/​toolSelectService.test.ts Tests restore-time tool removal announcement behavior.
packages/​agent-core-v2/​test/​agent/​toolPolicy/​toolPolicyService.test.ts Tests session-scoped policy snapshots and stable policy behavior.
packages/​agent-core-v2/​test/​agent/​task/​taskService.test.ts Tests task reminders under restricted tool policies.
packages/​agent-core-v2/​test/​agent/​profile/​profileOps.test.ts Updates profile operation session-policy fixtures.
packages/​agent-core-v2/​test/​agent/​profile/​binding.test.ts Tests policy snapshot restoration, legacy migration, and skill visibility.
packages/​agent-core-v2/​test/​agent/​changeNotifier/​changeNotifier.test.ts Tests skill reminders independently of Skill invocation availability.
packages/​agent-core-v2/​src/​workspace/​sessionLifecycle/​sessionLifecycleService.ts Skips automatic Plan entry when ExitPlanMode is unavailable.
packages/​agent-core-v2/​src/​session/​sessionToolPolicy/​sessionToolPolicyService.ts Captures, persists, restores, and exposes session default tool policies.
packages/​agent-core-v2/​src/​session/​sessionToolPolicy/​sessionToolPolicy.ts Defines the session default tool policy contract.
packages/​agent-core-v2/​src/​features/​tower/​towerService.ts Validates the complete Tower tool set before entry.
packages/​agent-core-v2/​src/​features/​tower/​towerFeature.ts Marks Tower tools as user-configurable.
packages/​agent-core-v2/​src/​features/​tower/​tower.ts Adds Tower handling for unavailable required tools.
packages/​agent-core-v2/​src/​features/​todo/​todoFeature.ts Marks TodoList as user-configurable.
packages/​agent-core-v2/​src/​features/​swarm/​swarmFeature.ts Marks AgentSwarm as user-configurable.
packages/​agent-core-v2/​src/​features/​swarm/​agent/​swarmService.ts Rejects Swarm entry when AgentSwarm is unavailable.
packages/​agent-core-v2/​src/​features/​skill/​skillFeature.ts Marks Skill as user-configurable.
packages/​agent-core-v2/​src/​features/​plan/​planService.ts Rejects Plan entry when ExitPlanMode is unavailable.
packages/​agent-core-v2/​src/​features/​plan/​planFeature.ts Marks ExitPlanMode as user-configurable.
packages/​agent-core-v2/​src/​features/​notify/​notifyUserNudgeService.ts Suppresses NotifyUser nudges when the tool is disabled.
packages/​agent-core-v2/​src/​features/​notify/​notifyFeature.ts Marks NotifyUser as user-configurable.
packages/​agent-core-v2/​src/​features/​goal/​injection/​goalInjection.ts Makes goal budget guidance depend on tool availability.
packages/​agent-core-v2/​src/​features/​goal/​injection/​goal-active-sparse-reminder.md Adds conditional budget guidance to sparse goal reminders.
packages/​agent-core-v2/​src/​features/​goal/​injection/​goal-active-reminder.md Adds conditional budget guidance to full goal reminders.
packages/​agent-core-v2/​src/​features/​goal/​goalService.ts Requires UpdateGoal for goal creation and resumption.
packages/​agent-core-v2/​src/​features/​goal/​goalFeature.ts Marks goal-management tools as user-configurable.
packages/​agent-core-v2/​src/​features/​cron/​cronFeature.ts Marks cron tools as user-configurable.
packages/​agent-core-v2/​src/​app/​telemetry/​events.ts Adds the Tower tools-disabled telemetry reason.
packages/​agent-core-v2/​src/​app/​agentProfileCatalog/​profile-shared.ts Keeps skill catalogs visible independently of Skill invocation availability.
packages/​agent-core-v2/​src/​agent/​toolSelect/​toolSelectService.ts Filters policy-inactive tools from restore-time removal announcements.
packages/​agent-core-v2/​src/​agent/​tools/​web-search/​webSearchTool.ts Marks WebSearch as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​task/​task-wait/​taskWaitTool.ts Marks WaitFor as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​task/​task-stop/​taskStopTool.ts Marks TaskStop as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​task/​task-output/​taskOutputTool.ts Marks TaskOutput as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​task/​task-list/​taskListTool.ts Marks TaskList as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​os/​write/​writeTool.ts Marks Write as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​os/​read/​readTool.ts Marks Read as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​os/​grep/​grepTool.ts Marks Grep as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​os/​glob/​globTool.ts Marks Glob as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​os/​bash/​bashTool.ts Marks Bash as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​fetch-url/​fetchUrlTool.ts Marks FetchURL as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​edit/​editTool.ts Marks Edit as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​ask-user-question/​askUserQuestionTool.ts Marks AskUserQuestion as user-configurable.
packages/​agent-core-v2/​src/​agent/​tools/​agent/​agentTool.ts Marks Agent as user-configurable.
packages/​agent-core-v2/​src/​agent/​toolRegistry/​toolContribution.ts Adds contribution metadata for configurable tools.
packages/​agent-core-v2/​src/​agent/​toolPolicy/​toolPolicyService.ts Switches policy evaluation from live configuration to the session snapshot.
packages/​agent-core-v2/​src/​agent/​task/​taskService.ts Makes background-task reminders respect individually available tools.
packages/​agent-core-v2/​src/​agent/​profile/​profileService.ts Uses the session snapshot for profile policy checks and warnings.
packages/​agent-core-v2/​src/​agent/​changeNotifier/​changeNotifierService.ts Uses session policy data while preserving skill reminders.
packages/​agent-core-v2/​docs/​state-manifest.d.ts Documents persisted default tool policy state.
docs/​zh/​reference/​server-api.md Documents the tool catalog endpoint and availability fields in Chinese.
docs/​zh/​configuration/​config-files.md Documents session-scoped tool configuration in Chinese.
docs/​en/​reference/​server-api.md Documents the tool catalog endpoint and availability fields in English.
docs/​en/​configuration/​config-files.md Documents session-scoped tool configuration in English.
.changeset/​session-default-tool-policy.md Records the user-facing session-scoped tool policy changes.

Review effort: Lite

Comment on lines +351 to +355
const taskToolsActive =
this.policy.isToolActive('TaskList') &&
this.policy.isToolActive('TaskOutput') &&
this.policy.isToolActive('TaskStop');
if (!taskToolsActive) return formatTaskList(tasks, true);
Comment on lines +37 to +40
plan_mode_available: toolPolicy?.isToolActive('ExitPlanMode') === true,
swarm_mode_available: toolPolicy?.isToolActive('AgentSwarm') === true,
tower_mode_available: optionalService(handle, IAgentTowerService)?.toolsAvailable === true,
goal_mode_available: toolPolicy?.isToolActive('UpdateGoal') === true,
@liruifengv liruifengv changed the title feat: add session-scoped default tool policies feat: add configurable tool catalog and mode availability Nov 10, 2026
@liruifengv
liruifengv changed the base branch from main to feat/custom-subagent-settings November 11, 2026 03:35

This branch has not been deployed

No deployments
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