Skip to content

feat: File operation auto-approve with glob pattern rules (Auto-approve Part 3)#216

Open
xinyi-gong wants to merge 3 commits into
feature/auto-approvefrom
tori/auto-approve-edits
Open

feat: File operation auto-approve with glob pattern rules (Auto-approve Part 3)#216
xinyi-gong wants to merge 3 commits into
feature/auto-approvefrom
tori/auto-approve-edits

Conversation

@xinyi-gong
Copy link
Copy Markdown
Member

@xinyi-gong xinyi-gong commented May 18, 2026

Summary

Adds file-operation (read/write) auto-approve support to the confirmation framework, allowing users to configure glob-pattern rules that automatically approve or deny file access requests from Agent Mode.

This is Auto-approve Part 3, building on the terminal auto-approve shipped in Part 2.

Changes

Core

  • FileOperationAutoApproveRule — Data model for glob pattern → allow/deny rules
  • FileSafetyRuleInfo / GetDefaultFileSafetyRulesResult — LSP protocol types for fetching default rules from CLS
  • CopilotLanguageServer / CopilotLanguageServerConnection — Added getDefaultFileSafetyRules JSON-RPC method
  • CopilotAgentSettings — Added autoApproveUnmatchedFileOp field, EditSettings inner class with equals/hashCode/toString (also added to ToolsSettings and TerminalSettings)
  • Constants — Added AUTO_APPROVE_FILE_OP_RULES and AUTO_APPROVE_UNMATCHED_FILE_OP

Confirmation Handler

  • FileOperationConfirmationHandler — Evaluates file confirmation requests with this priority:
    1. Attached files (auto-approve)
    2. Session cache (file-level and folder-level)
    3. Outside-workspace check (always requires confirmation)
    4. Global glob rules (first match wins)
    5. Unmatched fallback (configurable, default: enabled)
  • AttachedFileRegistry — Tracks user-attached context files with pending/flush lifecycle for conversation ID timing
  • ConfirmationService — Registers handler for FILE_READ, FILE_WRITE, FILE_OPERATION categories

Preferences UI

  • FileOperationAutoApproveSection — Rule table with add/remove/toggle/reset, fetches CLS defaults async
  • AddFileOperationRuleDialog — Dialog for adding glob patterns with allow/deny selection
  • AutoApprovePreferencePage — Now hosts both terminal and file operation sections
  • CopilotPreferenceInitializer — Added file-operation rule defaults
  • LanguageServerSettingManager — Syncs file-operation rules and unmatched setting to CLS

ChatView Integration

  • Collects attached file paths and stages them in AttachedFileRegistry before sending messages
  • Flushes pending files once the real conversation ID is available

Tests

  • FileOperationConfirmationHandlerTests — 42 unit tests covering all evaluation paths
  • LanguageServerSettingManagerTests — Updated expected params to account for tools initialization
  • Test plan: test-plans/file-operation-auto-approve/ — 9 E2E test cases

Preference Page:
image

Resets to Default:
image

Add Rule:
image

Allow dialog for files under workspace:
image

Allow dialog for outside-of-workspace files:
image

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds configurable auto-approve support for Agent Mode file operations (read/write/edit) using glob-pattern allow/deny rules, with CLS-synced defaults and preference UI integration—extending the existing confirmation/auto-approve framework beyond terminal commands.

Changes:

  • Introduces file-operation auto-approve rule model + CLS protocol/API for fetching default file safety rules.
  • Implements file-operation confirmation handling (attached-files/session cache/outside-workspace/rules/unmatched fallback) and wires it into ConfirmationService.
  • Adds preferences UI to manage file-operation rules and sync them to CLS; updates chat to stage/flush attached files by conversation.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/messages.properties Adds NLS strings for file-operation auto-approve preference UI.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/Messages.java Exposes new preference NLS keys as public static String fields.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/LanguageServerSettingManager.java Syncs file-operation auto-approve rules + unmatched toggle into CLS settings.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/FileOperationAutoApproveSection.java New preference section for viewing/editing file-operation glob rules and CLS defaults.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CopilotPreferenceInitializer.java Seeds default file-operation rule JSON and unmatched default.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/AutoApprovePreferencePage.java Hosts both terminal and file-operation auto-approve sections and persists them.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/AddFileOperationRuleDialog.java New dialog for adding file-operation rules (pattern/description/allow-deny).
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/services/AgentToolService.java Adds AttachedFileRegistry and passes it into ConfirmationService.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/messages.properties Adds file-operation confirmation dialog titles/messages and session actions.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/Messages.java Exposes new chat confirmation NLS keys.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/confirmation/FileOperationConfirmationHandler.java New handler implementing rule evaluation + session/global decisions for file ops.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/confirmation/ConfirmationService.java Registers file-operation handler for FILE_READ/FILE_WRITE/FILE_OPERATION categories.
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/confirmation/AttachedFileRegistry.java New registry to track user-attached files (pending + per-conversation).
com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/ChatView.java Stages pending attached files before send and flushes them once conversationId is known.
com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/preferences/LanguageServerSettingManagerTests.java Updates expected settings initialization for tools edit/terminal auto-approve maps.
com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/confirmation/TerminalConfirmationHandlerTests.java Adjusts Mockito strictness configuration for tests.
com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/confirmation/FileOperationConfirmationHandlerTests.java Adds unit tests covering file-operation confirmation evaluation paths.
com.microsoft.copilot.eclipse.swtbot.test/test-plans/file-operation-auto-approve/file-operation-auto-approve.md Adds E2E manual test plan for file-operation auto-approve feature.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/GetDefaultFileSafetyRulesResult.java New protocol type for CLS default file safety rules response.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/FileSafetyRuleInfo.java New protocol type representing a CLS file safety rule.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/protocol/CopilotAgentSettings.java Extends agent settings with unmatched file-op flag and tools.edit auto-approve rules.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServerConnection.java Adds getDefaultFileSafetyRules() wrapper method.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/lsp/CopilotLanguageServer.java Adds JSON-RPC request getDefaultFileSafetyRules.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/Constants.java Adds preference keys for file-operation rule JSON + unmatched toggle.
com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/chat/FileOperationAutoApproveRule.java Adds rule model for pattern/description/allow-deny, including default-rule marker.
Comments suppressed due to low confidence (1)

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/AddFileOperationRuleDialog.java:72

  • The description placeholder text is hardcoded ("Optional description"). For consistency/localization, externalize this string into messages.properties/Messages (similar to AddTerminalRuleDialog).
    Label descLabel = new Label(container, SWT.NONE);
    descLabel.setText(
        Messages.preferences_page_file_op_auto_approve_add_dialog_description);
    descriptionText = new Text(container, SWT.BORDER);
    descriptionText.setMessage("Optional description");
    descriptionText.setLayoutData(
        new GridData(SWT.FILL, SWT.CENTER, true, false));

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