feat: implement extensible plan mode with custom directory configuration#18775
feat: implement extensible plan mode with custom directory configuration#18775mahimashanware wants to merge 16 commits intomainfrom
Conversation
Summary of ChangesHello @mahimashanware, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the flexibility and power of Plan Mode by introducing dynamic policy management. It allows agents to specify particular files or directories for write access during planning, moving beyond a fixed temporary directory. This change streamlines the planning process by enabling workspace-wide plan creation and ensures that temporary permissions are properly managed and cleaned up, improving both security and usability. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces an extensible plan mode, allowing dynamic write access to specified paths and supporting workspace-wide plan locations. However, a significant security flaw exists: the user confirmation prompt is misleading, stating that the agent will be restricted to read-only tools, while it may actually be gaining write access to the entire workspace. Additionally, the list of allowed tools is unrestricted, which could lead to privilege escalation if dangerous tools are enabled in Plan Mode. Furthermore, a critical bug related to path escaping on Windows has been identified, and an information disclosure vulnerability where detailed error messages are passed to the LLM has been addressed in line with prompt injection prevention guidelines.
There was a problem hiding this comment.
Code Review
This pull request successfully extends the plan mode to allow dynamic write access and workspace-wide plan locations. However, a high-severity security issue was identified in the user confirmation flow: the EnterPlanModeTool provides a misleading prompt that fails to disclose when write access is being enabled for a specific path, potentially tricking users into granting excessive permissions. This should be addressed by dynamically updating the confirmation prompt based on the tool's parameters. Additionally, a high-severity issue concerning path escaping on Windows was found, which could prevent the feature from working as expected on that platform.
6b21379 to
e65aecc
Compare
|
Size Change: +3.5 kB (+0.01%) Total Size: 24.5 MB
ℹ️ View Unchanged
|
e65aecc to
7c94a4e
Compare
7c94a4e to
6b9d4ed
Compare
6b9d4ed to
eb2d6f8
Compare
eb2d6f8 to
1627e9d
Compare
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable directory for plan files, moving the configuration from an experimental flag to a general.plan setting. While the approach of dynamically injecting high-priority security policies for write access in Plan Mode is good, a high-severity security risk exists: the custom directory path is not validated. This oversight could allow a malicious repository to configure the plan directory to point to sensitive system locations, granting the LLM unauthorized write access. It is crucial to add validation to ensure the plan directory remains within the workspace. Additionally, a critical issue was identified regarding how paths are escaped for the dynamic policy regex, which could lead to incorrect policy enforcement.
3129416 to
181904e
Compare
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a feature to allow users to configure a custom directory for implementation plans. The changes span configuration loading, schema updates, core logic in the Config class to handle the new directory, and UI updates. While the implementation of the configuration and path resolution is solid, there is a critical discrepancy between the feature's description and its implementation. The PR summary claims dynamic policy injection for the custom plan directory, but the code and documentation require manual policy creation by the user. This will lead to a broken user experience and should be addressed before merging.
|
Thank you for linking an issue! This pull request has been automatically reopened. |
f4a96bb to
891f88d
Compare
891f88d to
45fcd98
Compare
Introduces a new 'Project' tier (Tier 3) for policies, allowing users to define project-specific rules in `$PROJECT_ROOT/.gemini/policies`. Key Changes: - **Core**: Added `PROJECT_POLICY_TIER` (3) and bumped `ADMIN_POLICY_TIER` to 4. Updated `getPolicyDirectories`, `getPolicyTier`, and `createPolicyEngineConfig` to handle project-level policy directories. - **Storage**: Added `getProjectPoliciesDir()` to the `Storage` class. - **CLI**: Updated `loadCliConfig` to securely load project policies. Crucially, project policies are **only loaded if the workspace is trusted**. - **Tests**: Added comprehensive tests for both core policy logic and CLI integration, verifying priority hierarchy (Admin > Project > User > Default) and trust checks. This hierarchy ensures that project-specific rules override user defaults but are still subject to system-wide admin enforcement.
Adds the 'Project' tier (Base 3) to the policy engine documentation. Updates the priority hierarchy, location table, and formula examples to reflect the new Project -> User precedence.
…efault Updates the policy engine to prioritize User policies over Project-specific policies. This change is a security measure to ensure that users maintain control over their environment and are not inadvertently compromised by policies defined in a cloned repository. Key Changes: - Swapped Tier 2 (now Project) and Tier 3 (now User). - Updated documentation to reflect the new hierarchy. - Updated all built-in policy TOML files with correct tier information. - Adjusted all tests and integration test expectations to match new priority values.
…ture changes from rebase
Adds a security mechanism to detect and prompt for confirmation when project-level policies are added or modified. This prevents unauthorized policy changes from being applied silently. - PolicyIntegrityManager calculates and persists policy directory hashes. - Config integrates integrity checks during startup. - PolicyUpdateDialog prompts users in interactive mode. - --accept-changed-policies flag supports non-interactive workflows. - toml-loader refactored to expose file reading logic.
…tegration tests - Refactored `PolicyUpdateDialog` to remove side effects (`process.exit`, `relaunchApp`) and delegate logic to parent. - Updated `AppContainer` to handle relaunch logic. - Added comprehensive unit tests for `PolicyUpdateDialog`. - Fixed `project-policy-cli.test.ts` to correctly mock `PolicyIntegrityManager`. - Fixed typo in `packages/core/src/policy/config.ts`.
Updates config.test.ts to fix createPolicyEngineConfig mock expectations and expands project-policy-cli.test.ts to cover integrity check scenarios (NEW, MISMATCH) and interactive confirmation flows.
Updates the terminology and configuration for the intermediate policy tier from "Project" to "Workspace" to better align with the Gemini CLI ecosystem. Key changes: - Renamed `PROJECT_POLICY_TIER` to `WORKSPACE_POLICY_TIER`. - Renamed `getProjectPoliciesDir` to `getWorkspacePoliciesDir`. - Updated integrity scope from `project` to `workspace`. - Updated UI dialogs and documentation. - Renamed related test files.
This change eliminates the need for a CLI restart when a user accepts new or changed project-level policies. Workspace rules are now dynamically injected into the active PolicyEngine instance. Key improvements: - Added Config.loadWorkspacePolicies() to handle mid-session rule injection. - Fully encapsulated acceptance and integrity logic within PolicyUpdateDialog. - Integrated centralized keybindings (Command.ESCAPE) for dialog dismissal. - Refactored PolicyIntegrityManager tests to use a real temporary directory instead of filesystem mocks for improved reliability. - Updated copyright headers to 2026 across affected files. - Added UI snapshot tests for the policy update dialog. Addresses review feedback from PR #18682.
Simplified createPolicyEngineConfig signature by moving workspacePoliciesDir into the PolicySettings interface. Updated all core and CLI call sites and tests to align with the consolidated settings structure.
Centralized the workspace policy discovery and integrity verification logic into a new 'resolveWorkspacePolicyState' helper in the policy module. This significantly simplifies 'loadCliConfig' in config.ts, reducing its imperative bloat and removing low-level core dependencies from the main configuration flow. - Moved workspace integrity check and directory discovery to policy.ts - Refactored loadCliConfig to use the new declarative resolver - Added comprehensive unit tests for the resolver using real temp dirs - Cleaned up redundant function arguments in core and CLI calls - Verified project integrity with 'npm run preflight'
- Adds 'general.plan' configuration object for plan settings (directory). - Updates 'experimental.plan' to a boolean flag for enablement. - Implements dynamic high-priority policy for custom plan directories in core. - Adds migration logic for previous configuration formats. - Updates documentation and schema.
45fcd98 to
e62362f
Compare
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant and valuable enhancements to Plan Mode, making it more extensible and configurable. The ability to define a custom plan directory and override default tool restrictions with policies is a great improvement. The implementation of workspace-level policies with integrity checks is a solid security addition. The code changes are extensive but well-structured, and the inclusion of new tests is appreciated. I've found a couple of issues: one in the documentation regarding security validation for the custom plan directory, and a potential bug in the policy directory loading logic. Please see my detailed comments.
| Add the `plan.directory` setting to your `~/.gemini/settings.json` file. This | ||
| path can be **absolute** or **relative** to your project root, and **can be | ||
| located outside your project directory**. |
There was a problem hiding this comment.
The documentation states that the custom plan directory can be located outside the project directory. However, the implementation in packages/core/src/tools/enter-plan-mode.ts includes a validation step (config.validatePathAccess) that ensures the directory is within the workspace for security reasons. If a path outside the workspace is configured, entering plan mode will fail. The documentation should be updated to reflect this security constraint to avoid user confusion and misconfiguration.
There was a problem hiding this comment.
@jerop what is the ideal behavior here? for conductor it will always be within the workspace but want to confirm
Manually resolved merge conflicts in CLI and Core config files that occurred during the rebase of the extensible plan mode feature branch onto `abhijit-2592/read-proj-dir-policy-file`.
e62362f to
6f0d7b8
Compare
|
It seems the 'configurable plan directory' part is now done separately #19577 . |
Summary
This PR enhances Plan Mode by making it more extensible and configurable. It introduces the ability to specify a custom directory for plans and leverages the policy engine to selectively enable tools (like
write_file) that are normally restricted. This allows for the creation of "Plan & Execute" workflows where the agent can manage specific files within a designated area while the broader workspace remains safely read-only.Key Changes
Configurable Plan Directory:
general.plan.directorysetting, allowing users to define a custom location (e.g.,conductor/) for storing implementation plans.Policy-Driven Plan Mode Overrides:
allowrules in user or workspace policies.How to Test
Configure Directory:
Add to
.gemini/settings.json:{ "general": { "plan": { "directory": "conductor" } } }Define Policy:
Create a policy file (e.g., in
.gemini/policies/) to allowwrite_filewithin theconductordirectory during plan mode:Verify Behavior:
/planconductor/test.md. Result: Should be Allowed.src/code.ts. Result: Should be Denied.Verification
npm run preflightpasses.