Skip to content

feat: auto approval w/ config granularity issue 1631 - #2095

Closed
suJayhh wants to merge 2 commits into
MoonshotAI:mainfrom
suJayhh:feat/auto-approval-issue-1631
Closed

feat: auto approval w/ config granularity issue 1631#2095
suJayhh wants to merge 2 commits into
MoonshotAI:mainfrom
suJayhh:feat/auto-approval-issue-1631

Conversation

@suJayhh

@suJayhh suJayhh commented Apr 28, 2026

Copy link
Copy Markdown

feat:

Wanted this feature myself. It is working live on my machine and in test cases. It does not retain directories or overrides between sessions beyond what the current kimi -r structure does. Changes integrated into config.toml. Config comments added for clarity.

Changes:
Added Support for Approved Commands (any directory). E.x. mcp:Obsidian_*
Added Support for Approved Directories (all commands). E.x. ~.kimi/plans

Related Issue

Resolve #1631

Description

src/kimi_cli/config.py
• Added default_auto_approve_actions (glob patterns) and auto_approve_workspace_dirs (relative dir names) to the Config model.
• New config files are now written from a commented TOML template with inline examples instead of a plain serialized dump.
• Added write_default_config_file(); load_config() validates the template back into a Config on first run.
src/kimi_cli/soul/agent.py
• Merges config.default_auto_approve_actions into the session's ApprovalState at startup.
• Subtracts config defaults before persisting session state so removing a pattern from config actually disables it later.
src/kimi_cli/soul/approval.py
• Auto-approve matching now supports glob patterns via fnmatch.
• Exact match is checked first for safety; then patterns like mcp:obsidian
* are expanded.
src/kimi_cli/tools/file/replace.py & write.py
• Both tools read auto_approve_workspace_dirs and skip approval for paths inside those directories.
• Added is_auto_approved_dir() helper; rejects absolute paths with a warning to prevent boundary escapes.
• Plan-file auto-approve behavior is preserved alongside the new directory bypass.
Tests
• test_config.py: verifies commented template generation.
• test_session_state.py: verifies glob patterns (e.g., mcp:obsidian
*) auto-approve.
• test_str_replace_file.py & test_write_file.py: verify edits/writes in configured dirs bypass approval.
Docs/Changelog

• Updated English and Chinese changelogs and config-file docs with the two new options and examples.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

Wanted this feature myself. It is working live on my machine and in test cases. It does not retain directories or overrides between sessions beyond what the current kimi -r structure does. Changes integrated into config.toml.

Related Issue

Resolve #1631

Description

src/kimi_cli/config.py
• Added default_auto_approve_actions (glob patterns) and auto_approve_workspace_dirs (relative dir names) to the Config model.
• New config files are now written from a commented TOML template with inline examples instead of a plain serialized dump.
• Added write_default_config_file(); load_config() validates the template back into a Config on first run.
src/kimi_cli/soul/agent.py
• Merges config.default_auto_approve_actions into the session's ApprovalState at startup.
• Subtracts config defaults before persisting session state so removing a pattern from config actually disables it later.
src/kimi_cli/soul/approval.py
• Auto-approve matching now supports glob patterns via fnmatch.
• Exact match is checked first for safety; then patterns like mcp:obsidian
* are expanded.
src/kimi_cli/tools/file/replace.py & write.py
• Both tools read auto_approve_workspace_dirs and skip approval for paths inside those directories.
• Added is_auto_approved_dir() helper; rejects absolute paths with a warning to prevent boundary escapes.
• Plan-file auto-approve behavior is preserved alongside the new directory bypass.
Tests
• test_config.py: verifies commented template generation.
• test_session_state.py: verifies glob patterns (e.g., mcp:obsidian
*) auto-approve.
• test_str_replace_file.py & test_write_file.py: verify edits/writes in configured dirs bypass approval.
Docs/Changelog

• Updated English and Chinese changelogs and config-file docs with the two new options and examples.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment thread src/kimi_cli/config.py
skip_yolo_prompt_injection = false

[loop_control]
max_steps_per_turn = 500

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Config template hardcodes stale max_steps_per_turn = 500 instead of the current default 1000

The _DEFAULT_CONFIG_TEMPLATE at src/kimi_cli/config.py:348 sets max_steps_per_turn = 500, but the LoopControl model default was already bumped to 1000 at src/kimi_cli/config.py:79. The CHANGELOG even documents this change ("Raise default max_steps_per_turn from 500 to 1000"), and the docs at docs/en/configuration/config-files.md:73 show 1000. Every new user who gets a freshly generated config file will silently receive the old, lower limit. Additionally, the new test test_load_config_creates_template_with_comments (tests/core/test_config.py:99-102) asserts config.model_dump(...) == get_default_config().model_dump(), which will fail because the template parses to 500 while get_default_config() yields 1000.

Suggested change
max_steps_per_turn = 500
max_steps_per_turn = 1000
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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

ℹ️ 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 src/kimi_cli/config.py
skip_yolo_prompt_injection = false

[loop_control]
max_steps_per_turn = 500

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 template max_steps_per_turn aligned with runtime default

The new default TOML template hard-codes max_steps_per_turn = 500, but LoopControl.max_steps_per_turn still defaults to 1000. On first run, load_config() now writes and validates this template, so fresh users silently get a lower step limit than the actual default model/config behavior and can hit max_steps_reached earlier. This is a regression from the intended 1000-step default and should be synchronized.

Useful? React with 👍 / 👎.

Comment on lines +73 to +74
if _GLOB_SPECIAL_RE.search(entry):
self._auto_approve_patterns.append(entry)

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 Preserve exact auto-approve entries containing glob chars

This reclassification treats any persisted action containing *, ?, [ or ] as a pattern on reload, even if it was originally approved as an exact action via approve_for_session. Because persisted state stores only raw strings, exact approvals like plugin:tool[beta] can later stop matching themselves and/or match unrelated actions after restart, widening or changing approval scope across sessions.

Useful? React with 👍 / 👎.

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: Granular Auto-Approval Rules (like Claude Code)

1 participant