Skip to content

feat(agent-core-v2): make workspace trust configurable - #4517

Merged
sailist merged 4 commits into
mainfrom
feat-317-10-29-workspace-trust-toggle
Oct 29, 2026
Merged

sailist merged 4 commits into
mainfrom
feat-317-10-29-workspace-trust-toggle

Conversation

@sailist

@sailist sailist commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

允许用户通过 config.toml 全局关闭工作区信任确认。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 config.toml
+  [workspace]
+  require_trust = false       # 默认 true;false 时所有工作区按已信任处理

 WorkspaceTrustStore
+  统一计算配置开关、进程环境变量和持久化记录的有效信任状态
+  在配置 reload 后传播信任变化,但不改写持久化记录

 McpRegistryService / WorkspaceMcpConfigService / TrustDisclosureService
+  统一通过 trust.get() 读取有效信任状态
+  配置开启时保留原有的存储失败与恢复边界

同时更新配置 manifest、中英文配置/MCP/Server API 文档和 patch changeset。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
默认配置与非法值 信任机制按持久化记录工作 require_trust 默认 true,非法值也回退启用,行为不变 所有现有 TUI、print、Server、SDK 用户 无需操作
显式设置 require_trust = false 无此配置;未信任工作区会提示,项目级 MCP 受门控 跳过信任提示,项目级 MCP 等配置按已信任路径加载 明确选择关闭信任机制的用户 设回 true 并 /reload
KIMI_CODE_TRUST_WORKSPACE 1 按进程强制信任,假值不撤销记录 保持原语义;假值也不覆盖 require_trust = false CI、headless 与脚本调用方 继续使用现有环境变量
trust() / untrust() 与信任记录 分别写入和删除持久化记录 记录管理不变;全局关闭时有效信任仍为 true,重新开启后按记录恢复 Server trust 路由、SDK 与已有信任记录 重新设回 true
配置 reload 没有可切换的信任配置 动态加载或卸载项目级 MCP;运行中的 TUI 不补弹启动提示 编辑 config.toml 的交互用户 /reload 或重启
信任存储失败与恢复 错误向调用方传播,后续调用可恢复 配置开启时保持该边界;配置关闭时直接返回有效信任,不被存储故障阻断 信任存储异常的环境及初始化恢复路径 保持 require_trust = true

覆盖情况:

  • m0-dev 定向回归:workspaces、workspaceTrust、mcpRegistry、mcpManagement、workspaceMcpConfig、initialization 共 6 文件、144/144 通过,包含首轮全量测试发现的两个初始化恢复场景。
  • 本地相关测试:5 文件、119/119 通过;workspaceTrust 保持 21 个用例,测试总数未增加。
  • 真实 SDK 临时 TOML 冒烟:false 加载项目 MCP、真实 reload 恢复 true、非法值 fail closed 均通过。
  • agent-core-v2 typecheck、仓库 lint、完整 build 和中英文 docs build 通过。
  • m0-dev 全量测试:首轮发现 2 个初始化回归后已修复并完成上述定向复验;修复后最终全量 904 文件、17908/17908 通过(另 4 文件、26 用例 skipped)。
  • 第二轮 Codex 三项反馈已处理:registry 双向刷新、文档锚点兼容和 untrust OpenAPI 描述;定向 4 文件 67/67 通过,最终全量同为 904 文件、17908/17908 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • Requirement described above; this is an internal feature request with no external 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, or this PR needs no changeset.
  • Updated bilingual docs and ran docs build. gen-docs 的 changelog 同步步骤无法执行,因为当前基线不存在 docs/scripts/sync-changelog.mjs。

@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0107d08

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T10:57:55.399175Z 0107d08 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

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

commit: 0107d08

@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: 79afeeff3d

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


async get(): Promise<boolean> {
await this.config.ready;
if (!this.trustGateEnabled()) return true;

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 persisted trust before re-enabling the gate

When Kimi Code starts with require_trust = false, this early return bypasses this.ready, so an existing trust record is never read. If the user then re-enables the requirement with the documented /reload flow, onConfigChange() publishes the cached false state and reloadAfterTrustChange() unloads project MCP servers; a later get() can discover the persisted true value, but normal initialization emits no follow-up change, leaving MCP unloaded until restart or re-trust. Load the persisted state before publishing the re-enabled gate state.

AGENTS.md reference: AGENTS.md:L111-L113

Useful? React with 👍 / 👎.

@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: 38e2305416

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

const trusted =
(await readWorkspaceTrust(this.docs, cwd)) ||
trustWorkspaceEnvTrusted((name) => this.bootstrap.getEnv(name));
const trusted = await this.trust.forRoot(cwd).get();

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 Refresh persisted trust before registry queries

When this process has queried a workspace once, WorkspaceTrustEntry.get() reuses its resolved initialization promise and never reads the trust record again. If another Kimi Code process subsequently trusts or untrusts the same directory, MCP management operations in this process continue returning the old project-level registry view until restart; the replaced implementation called readWorkspaceTrust on every query and observed such changes. Preserve that fresh-read behavior or invalidate the cached entry when querying the registry.

AGENTS.md reference: AGENTS.md:L127-L129

Useful? React with 👍 / 👎.

Comment thread docs/en/configuration/config-files.md Outdated

`enabled` can be overridden by the `KIMI_CODE_WATCH` environment variable, which takes higher priority than `config.toml`.

## `workspace`

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 Keep the existing workspace documentation anchor stable

Adding this second heading named workspace duplicates the existing project-local workspace heading later in both locale pages. VitePress assigns the first heading #workspace and disambiguates the later one, so existing public links or bookmarks to the project-local configuration now land on the unrelated global trust section. Give the new section a distinct heading/anchor and update the new links so the prior #workspace target remains stable.

AGENTS.md reference: docs/AGENTS.md:L18-L21

Useful? React with 👍 / 👎.

#### `POST /api/v1/workspaces/{workspace_id}/untrust`

Revokes workspace trust, unloading its project-level MCP config.
Revokes the persisted workspace trust record. Unless a process or config override keeps the workspace trusted, its project-level MCP config unloads.

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 Update the untrust route's generated description

This documentation correctly makes MCP unloading conditional, but the route definition in packages/kap-server/src/routes/workspaces.ts still publishes the unconditional OpenAPI description Revoke workspace trust (project-level MCP config unloads). With require_trust = false, the endpoint now leaves project MCP loaded, so generated API consumers receive a contract that contradicts both the response and this reference page; update the route metadata to describe the override.

AGENTS.md reference: AGENTS.md:L123-L125

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 7d72ae3 into main Oct 29, 2026
17 checks passed
@sailist
sailist deleted the feat-317-10-29-workspace-trust-toggle branch October 29, 2026 11:13
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
… as already landed

MoonshotAI#4434's CSP already allows data: and blob: media fetches, MoonshotAI#4517's
[workspace] require_trust section and its store short-circuit are in the
tree with both locale docs, and MoonshotAI#4605's tunnel scenario already reports
httpCapabilities and asserts the reconnected response.

Ledger: closed 28 -> 32, remaining 67.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
Ports the docs half of upstream MoonshotAI/kimi-code 8b6a003 (MoonshotAI#4673): the
2.5.0 section from the upstream release notes lands in both changelogs, en
and zh, word for word.

Every feature the section names is in this tree - busy /model and /effort
(MoonshotAI#4621), merged project-level skills (MoonshotAI#4520), remote sessions in SSH, Docker
and custom-command environments (MoonshotAI#4062), [workspace] require_trust (MoonshotAI#4517),
web search off by default (MoonshotAI#4516), and the subagent model pool (MoonshotAI#4418) - so
the notes describe what the fork actually does.

Deliberately not touched: apps/kimi-code/CHANGELOG.md still tops out at 2.4.1
and package.json still says 2.4.1. That file is generated by `changeset
version`, this tree has 377 pending changesets, and AGENTS.md forbids running
version or publish from this repository, so the entry is written on the docs
side only. Whoever next cuts a release here should reconcile this section
with what changeset version generates rather than re-deriving it by hand.
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