Skip to content

feat(agent-core-v2): add config switches for file-access guards and skip directory search-root prompts - #4219

Closed
sailist wants to merge 2 commits into
mainfrom
feat-290-10-14-sensitive-file-guard-config
Closed

sailist wants to merge 2 commits into
mainfrom
feat-290-10-14-sensitive-file-guard-config

Conversation

@sailist

@sailist sailist commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Approved requirement, two parts: (1) add per-guard config switches symmetric to dangerous_command_guard that can disable the sensitive-file and git-control-path approval prompts; (2) stop the false positive where Grep path="src/features/credentials" prompts only because the search root's basename matches the sensitive-name list — real-world search roots are directories, and a directory named credentials is almost always source code, not secrets.

Bug Reproduction Steps

N/A (feature PR). The false positive this removes: run Grep with path set to any existing directory named credentials (or .env, id_rsa, …) — the sensitive-file approval prompt fired even though the target is a directory.

Root Cause

N/A (feature PR).

Code Changes

  • packages/agent-core-v2/src/agent/permissionRules/configSection.ts: add sensitive_file_guard and git_control_path_guard keys (default true) to the [permission] config schema, with KIMI_CODE_SENSITIVE_FILE_GUARD / KIMI_CODE_GIT_CONTROL_PATH_GUARD env bindings and isSensitiveFileGuardEnabled / isGitControlPathGuardEnabled getters, following the exact conventions of dangerous_command_guard.
  • packages/agent-core-v2/src/agent/permissionPolicy/policies/sensitive-file-access-ask.ts: inject the config service and the agent runtime; return early when the guard is disabled; when a sensitive-named access path stats as a directory, do not ask — files and unstat-able paths keep asking (fail closed).
  • packages/agent-core-v2/src/agent/permissionPolicy/policies/git-control-path-access-ask.ts: inject the config service and return early when the guard is disabled; behavior otherwise unchanged.
  • Docs: docs/en|zh/configuration/config-files.md document both new keys and env vars; packages/agent-core-v2/docs/config-manifest.toml regenerated.
  • Tests: rewrote two existing test cases — the config-disable case now covers all three guards, and the sensitive-file case now covers a real sensitive file, an unstat-able sensitive path, and a sensitive-named directory. Test count is unchanged.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Sensitive-file approval prompt (sensitive-file-access-ask) Always on On by default; skipped when sensitive_file_guard = false or KIMI_CODE_SENSITIVE_FILE_GUARD=false Users who want the prompt keep it by default Set the guard back to true (default)
Git-control-path approval prompt (git-control-path-access-ask) Always on On by default; skipped when git_control_path_guard = false or KIMI_CODE_GIT_CONTROL_PATH_GUARD=false Users who want the prompt keep it by default Set the guard back to true (default)
Sensitive-named path that is a directory (e.g. Grep path to a credentials/ source dir) Prompted No prompt Nobody intentionally — the prompt was a false positive on directories Not restorable; approved requirement
Sensitive-named path that is a file or cannot be stat'ed Prompted Prompted (unchanged) — —
Read/Write/Edit hard block on secret files (PATH_SENSITIVE) Blocked Blocked (unchanged) — —
Grep/Glob result-level exclusion of secret files Excluded Excluded (unchanged) — —

Affected modules: agent-core-v2 permission policy chain and permission config section.

Config-contract compatibility: the two new [permission] keys are optional and default to true, so config files written by older releases (which never contain them) behave exactly as before; an older release reading a file that does contain them ignores the unknown keys (and preserves them on writeback), with the guards staying on. External consumers of the config surface — the CLI/TUI, the desktop/web clients, and SDK callers of the kap-server /api/v1/config API — only see two additional optional boolean fields; clients that never set them keep the old behavior. No migration is needed. Coverage: test/agent/permissionPolicy/permissionPolicyService.test.ts (chain-level, all rows above), test/app/config/* (config section load/writeback), regenerated config manifest verified by test/app/config/configManifest.test.ts.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve). (Internal requirement approved directly by the project owner; no 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.
  • Ran gen-docs skill, or this PR needs no doc update.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T14:30:52.329509Z 23c1a20 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.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b7bf7e9

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

@pkg-pr-new

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

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

commit: 23c1a20

@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: b7bf7e9608

ℹ️ 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 on lines +41 to +42
sensitiveFileGuard: z.boolean().optional(),
gitControlPathGuard: z.boolean().optional(),

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 Serialize the new guard fields in the TOML writer

When a desktop, web, or SDK client sets either new switch through the config API (POST /api/v1/config or IConfigService.set), validation accepts the field and the current process reports it as applied, but permissionToToml only serializes rules and never writes sensitive_file_guard or git_control_path_guard. The setting is therefore silently absent from config.toml and reverts to true after restart; update the custom writer and add a persistence/reload test for both fields.

AGENTS.md reference: AGENTS.md:L117-L119

Useful? React with 👍 / 👎.

Comment on lines +30 to +31
const stat = await fs.stat(access.path).catch(() => undefined);
return stat !== undefined && stat.isDirectory ? undefined : { kind: 'ask' };

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 Keep sensitive-name symlinks behind approval

When a sensitive search root such as .env is a symlink to a directory, stat() follows the link and this branch silently skips approval even with the guard enabled. Grep path=".env" then passes that link explicitly to ripgrep—whose --help states that explicitly supplied hidden directories are searched—and an ordinary target file such as .env/token.txt is not removed by the basename-based sensitive-result filter, so its contents can reach the model without the previous prompt. Use lstat() or otherwise exclude symlinks from the directory exemption.

AGENTS.md reference: AGENTS.md:L117-L119

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: 23c1a20c4c

ℹ️ 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 on lines +315 to +316
# sensitive_file_guard <- KIMI_CODE_SENSITIVE_FILE_GUARD (custom parse)
# git_control_path_guard <- KIMI_CODE_GIT_CONTROL_PATH_GUARD (custom parse)

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 Document consumers of the expanded config contract

Because these additions expand config-manifest.toml, the PR description must name the relevant external consumers, such as desktop/web config clients, and explain how clients and configuration data from the previous release remain compatible. The current description only says that the manifest was regenerated, so the required cross-repository compatibility check is missing.

AGENTS.md reference: AGENTS.md:L109-L111

Useful? React with 👍 / 👎.

@sailist

sailist commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded: permission guards will be unified under the single dangerous_command_guard switch instead of per-guard switches.

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