Skip to content

feat(core): Tool Confirmation Message Bus foundation (PR 1 of 3)#7835

Merged
allenhutchison merged 13 commits intomainfrom
adh/issue-7231
Sep 11, 2025
Merged

feat(core): Tool Confirmation Message Bus foundation (PR 1 of 3)#7835
allenhutchison merged 13 commits intomainfrom
adh/issue-7231

Conversation

@allenhutchison
Copy link
Copy Markdown
Contributor

Summary

This PR implements the foundation for the Tool Confirmation Message Bus as described in issue #7231. This is the first of three PRs that will fully implement the feature.

What this PR does

  • Introduces a pub/sub MessageBus class for decoupled tool confirmation handling
  • Implements a PolicyEngine with configurable rules for tool execution control
  • Integrates both components into the Config class
  • Adds comprehensive unit tests with 100% coverage

Key Features

  • Message Bus: Event-driven publish/subscribe pattern for tool confirmation messages
  • Policy Engine: Priority-based rules with tool name and args pattern matching
  • Non-interactive mode: Automatic conversion of ASK_USER to DENY
  • Error handling: Robust validation and error event emission
  • Type safety: Full TypeScript support with discriminated unions

Testing

  • ✅ 25 new unit tests covering all functionality
  • ✅ All existing tests pass (1964 total)
  • ✅ TypeScript compilation passes
  • ✅ ESLint checks pass
  • ✅ Preflight checks pass

Next Steps

  • PR 2: Core Tool Integration - Modify shell tool to use the message bus
  • PR 3: TUI Integration - Wire up UI to handle confirmation requests

Fixes part of #7231

Introduces a pub/sub message bus architecture to decouple tool confirmation
logic from core tool implementation. This is the first PR in a series to
implement the Tool Confirmation Message Bus as described in issue #7231.

## Changes
- Add MessageBus class with event-driven publish/subscribe pattern
- Implement PolicyEngine with configurable rules for tool execution control
- Integrate MessageBus and PolicyEngine into Config class
- Add comprehensive unit tests for both components

## Features
- Priority-based policy rules with tool name and args pattern matching
- Non-interactive mode support (ASK_USER becomes DENY)
- Error handling and message validation
- Support for multiple message types (confirmation, rejection, execution)

## Testing
- 25 new unit tests covering all functionality
- Full test suite passes (1964 total tests)
- TypeScript compilation and linting checks pass
@allenhutchison allenhutchison requested a review from a team as a code owner September 5, 2025 22:37
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @allenhutchison, 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 establishes the foundational architecture for a robust tool confirmation system. It introduces a message bus for event-driven communication and a policy engine to enforce rules around tool execution. This initial phase sets the stage for future enhancements that will enable fine-grained control and auditing of how AI agents interact with external tools, significantly improving security and operational transparency.

Highlights

  • Foundation for Tool Confirmation Message Bus: Introduces core components for managing tool execution confirmations, laying the groundwork for controlled tool usage.
  • Decoupled Communication: Implements a pub/sub MessageBus for flexible, event-driven handling of tool confirmation messages, promoting modularity.
  • Configurable Policy Enforcement: Adds a PolicyEngine to control tool execution based on priority-based rules, including tool name and argument pattern matching, enhancing security.
  • Integration with Core Configuration: The new MessageBus and PolicyEngine are integrated into the Config class, making them accessible and configurable throughout the application.
  • Robust Testing and Type Safety: Includes comprehensive unit tests for both new components and provides full TypeScript support for enhanced reliability and maintainability.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 5, 2025

Size Change: +7.18 kB (+0.05%)

Total Size: 13.2 MB

Filename Size Change
./bundle/gemini.js 13.2 MB +7.18 kB (+0.05%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 830 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a solid foundation for a tool confirmation message bus and a policy engine. The new components are well-designed, typed, and thoroughly tested. The integration into the existing configuration management appears correct. I have identified one critical issue in the PolicyEngine's argument matching logic that could lead to security policies being bypassed. I've included a specific code suggestion to address this vulnerability. Apart from this, the changes are excellent.

@gemini-cli gemini-cli bot added kind/enhancement priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Sep 5, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 5, 2025

Code Coverage Summary

Package Lines Statements Functions Branches
CLI 75.82% 75.82% 76.63% 80.17%
Core 79.33% 79.33% 78.5% 84.9%
CLI Package - Full Text Report
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   75.82 |    80.17 |   76.63 |   75.82 |                   
 src               |   65.77 |    68.91 |   57.14 |   65.77 |                   
  gemini.tsx       |   52.66 |    43.75 |   55.55 |   52.66 | ...21,432-440,454 
  ...ractiveCli.ts |    91.3 |       80 |   33.33 |    91.3 | ...7-70,96-97,127 
  ...ActiveAuth.ts |     100 |      100 |     100 |     100 |                   
 src/commands      |   70.45 |      100 |      25 |   70.45 |                   
  extensions.tsx   |   55.55 |      100 |       0 |   55.55 | 21-31,35          
  mcp.ts           |   94.11 |      100 |      50 |   94.11 | 26                
 ...nds/extensions |   43.61 |    93.75 |   28.57 |   43.61 |                   
  disable.ts       |    28.2 |      100 |       0 |    28.2 | 17-27,33-44,46-50 
  enable.ts        |    23.4 |      100 |       0 |    23.4 | 17-35,41-52,54-58 
  install.ts       |   42.02 |    66.66 |   33.33 |   42.02 | 21-56,81,84-89    
  link.ts          |   28.57 |      100 |       0 |   28.57 | 19-33,40-45,47-50 
  list.ts          |   32.14 |      100 |       0 |   32.14 | 11-27,34-35       
  new.ts           |     100 |      100 |     100 |     100 |                   
  uninstall.ts     |   45.71 |      100 |   33.33 |   45.71 | 15-23,35-40,43-46 
  update.ts        |   19.64 |      100 |       0 |   19.64 | 21-46,53-68,70-74 
 ...les/mcp-server |       0 |        0 |       0 |       0 |                   
  example.ts       |       0 |        0 |       0 |       0 | 1-60              
 src/commands/mcp  |   95.62 |       80 |    90.9 |   95.62 |                   
  add.ts           |    97.4 |    83.33 |     100 |    97.4 | 109-112,119       
  list.ts          |   90.56 |    80.76 |      80 |   90.56 | ...07-109,134-135 
  remove.ts        |     100 |    66.66 |     100 |     100 | 19-23             
 src/config        |   91.26 |    84.82 |   87.67 |   91.26 |                   
  auth.ts          |     100 |      100 |     100 |     100 |                   
  config.ts        |   97.25 |     90.5 |      80 |   97.25 | ...15,557,680-684 
  extension.ts     |   77.63 |    82.22 |   82.14 |   77.63 | ...37-742,748-751 
  keyBindings.ts   |     100 |      100 |     100 |     100 |                   
  sandboxConfig.ts |   54.16 |    23.07 |   66.66 |   54.16 | ...44,54-68,73-89 
  settings.ts      |   88.88 |    82.92 |   95.23 |   88.88 | ...13,615,617-618 
  ...ingsSchema.ts |     100 |      100 |     100 |     100 |                   
  ...tedFolders.ts |   92.96 |    91.17 |     100 |   92.96 | ...56-157,170-175 
 ...fig/extensions |   92.85 |    82.35 |     100 |   92.85 |                   
  ...ableSchema.ts |     100 |      100 |     100 |     100 |                   
  variables.ts     |   90.69 |    82.35 |     100 |   90.69 | 30-31,64-65       
 src/core          |   81.63 |    42.85 |     100 |   81.63 |                   
  auth.ts          |   56.25 |       50 |     100 |   56.25 | 27-36             
  initializer.ts   |     100 |       50 |     100 |     100 | 37                
  theme.ts         |      80 |    33.33 |     100 |      80 | 18-19             
 src/generated     |     100 |      100 |     100 |     100 |                   
  git-commit.ts    |     100 |      100 |     100 |     100 |                   
 src/patches       |       0 |        0 |       0 |       0 |                   
  is-in-ci.ts      |       0 |        0 |       0 |       0 | 1-17              
 src/services      |   68.61 |    90.66 |   92.85 |   68.61 |                   
  ...mandLoader.ts |     100 |      100 |     100 |     100 |                   
  ...andService.ts |     100 |      100 |     100 |     100 |                   
  ...mandLoader.ts |   89.44 |    91.11 |     100 |   89.44 | ...85-190,273-280 
  ...omptLoader.ts |   29.68 |    81.25 |   66.66 |   29.68 | ...40-241,244-248 
  types.ts         |     100 |      100 |     100 |     100 |                   
 ...mpt-processors |   97.03 |     93.5 |     100 |   97.03 |                   
  ...tProcessor.ts |     100 |      100 |     100 |     100 |                   
  ...eProcessor.ts |   94.44 |    84.21 |     100 |   94.44 | 43-44,90-91       
  ...tionParser.ts |     100 |      100 |     100 |     100 |                   
  ...lProcessor.ts |   96.96 |    94.87 |     100 |   96.96 | 93-96             
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/test-utils    |   91.22 |    83.33 |      80 |   91.22 |                   
  ...omMatchers.ts |   69.69 |       50 |      50 |   69.69 | 32-35,37-39,45-47 
  ...andContext.ts |     100 |      100 |     100 |     100 |                   
  render.tsx       |     100 |      100 |     100 |     100 |                   
 src/ui            |   70.33 |    67.52 |   48.71 |   70.33 |                   
  App.tsx          |     100 |      100 |     100 |     100 |                   
  AppContainer.tsx |   71.28 |       50 |   30.76 |   71.28 | ...89-842,874-877 
  ...tionNudge.tsx |    9.58 |      100 |       0 |    9.58 | 26-98             
  colors.ts        |   59.18 |      100 |   33.33 |   59.18 | ...46,48-49,54-55 
  constants.ts     |     100 |      100 |     100 |     100 |                   
  keyMatchers.ts   |   95.65 |    95.65 |     100 |   95.65 | 25-26             
  ...tic-colors.ts |     100 |      100 |     100 |     100 |                   
  textConstants.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/ui/auth       |   60.22 |      100 |      50 |   60.22 |                   
  AuthDialog.tsx   |     100 |      100 |     100 |     100 |                   
  ...nProgress.tsx |   16.66 |      100 |       0 |   16.66 | 19-63             
  useAuth.ts       |      10 |      100 |       0 |      10 | 15-26,29-96       
 src/ui/commands   |   85.85 |    81.89 |   88.88 |   85.85 |                   
  aboutCommand.ts  |   95.65 |    58.33 |     100 |   95.65 | 52-53             
  authCommand.ts   |     100 |      100 |     100 |     100 |                   
  bugCommand.ts    |   79.48 |       40 |     100 |   79.48 | 33-36,78-87,93-94 
  chatCommand.ts   |   94.23 |    83.33 |     100 |   94.23 | ...11-212,214-215 
  clearCommand.ts  |     100 |      100 |     100 |     100 |                   
  ...essCommand.ts |     100 |    88.88 |     100 |     100 | 73                
  copyCommand.ts   |     100 |      100 |     100 |     100 |                   
  corgiCommand.ts  |     100 |      100 |     100 |     100 |                   
  ...ryCommand.tsx |   69.27 |    73.07 |     100 |   69.27 | ...25-126,161-169 
  docsCommand.ts   |     100 |      100 |     100 |     100 |                   
  editorCommand.ts |     100 |      100 |     100 |     100 |                   
  ...onsCommand.ts |     100 |      100 |     100 |     100 |                   
  helpCommand.ts   |     100 |      100 |     100 |     100 |                   
  ideCommand.ts    |   62.25 |       60 |   54.54 |   62.25 | ...52-266,274-288 
  initCommand.ts   |     100 |      100 |     100 |     100 |                   
  mcpCommand.ts    |   81.97 |    82.95 |   83.33 |   81.97 | ...85-386,436-443 
  memoryCommand.ts |   99.11 |    81.25 |     100 |   99.11 | 90                
  ...acyCommand.ts |     100 |      100 |     100 |     100 |                   
  quitCommand.ts   |     100 |      100 |     100 |     100 |                   
  ...oreCommand.ts |      92 |    87.09 |     100 |      92 | ...,82-87,128-129 
  ...ngsCommand.ts |     100 |      100 |     100 |     100 |                   
  ...hubCommand.ts |   83.66 |    66.66 |     100 |   83.66 | ...54-157,160-163 
  statsCommand.ts  |   84.48 |       75 |     100 |   84.48 | 25-33             
  ...tupCommand.ts |     100 |      100 |     100 |     100 |                   
  themeCommand.ts  |     100 |      100 |     100 |     100 |                   
  toolsCommand.ts  |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
  vimCommand.ts    |   44.44 |      100 |       0 |   44.44 | 15-25             
 src/ui/components |      70 |    75.34 |   64.61 |      70 |                   
  AboutBox.tsx     |     100 |       50 |     100 |     100 | 104               
  AppHeader.tsx    |   36.36 |      100 |       0 |   36.36 | 19-35             
  AsciiArt.ts      |     100 |      100 |     100 |     100 |                   
  ...Indicator.tsx |   15.15 |      100 |       0 |   15.15 | 17-47             
  Composer.tsx     |   99.35 |    76.47 |     100 |   99.35 | 115               
  ...itDisplay.tsx |   62.16 |      100 |      50 |   62.16 | 21-32,36-37       
  ...ryDisplay.tsx |   21.05 |      100 |       0 |   21.05 | 17-35             
  ...ryDisplay.tsx |   87.91 |    62.06 |     100 |   87.91 | ...48-49,79-84,89 
  ...geDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...gProfiler.tsx |      24 |      100 |       0 |      24 | 13-36             
  ...esDisplay.tsx |   10.34 |      100 |       0 |   10.34 | 24-83             
  ...ogManager.tsx |   13.54 |      100 |       0 |   13.54 | 29-183            
  ...ngsDialog.tsx |    6.99 |      100 |       0 |    6.99 | 30-181            
  ...ustDialog.tsx |     100 |      100 |     100 |     100 |                   
  Footer.tsx       |   81.89 |    79.41 |     100 |   81.89 | ...40-147,150-153 
  ...ngSpinner.tsx |   54.28 |       50 |      50 |   54.28 | 31-48,61          
  Header.tsx       |   87.23 |    57.14 |     100 |   87.23 | 36-39,55,64       
  Help.tsx         |   98.46 |       60 |     100 |   98.46 | 77,131            
  ...emDisplay.tsx |   71.01 |    43.75 |     100 |   71.01 | ...56-61,82-88,91 
  InputPrompt.tsx  |   78.55 |    78.14 |     100 |   78.55 | ...39-841,849-860 
  ...Indicator.tsx |     100 |      100 |     100 |     100 |                   
  MainContent.tsx  |   16.66 |      100 |       0 |   16.66 | 16-64             
  ...geDisplay.tsx |   22.58 |      100 |       0 |   22.58 | 15-41             
  ...tsDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...fications.tsx |   17.02 |      100 |       0 |   17.02 | 15-62             
  PrepareLabel.tsx |      50 |       20 |     100 |      50 | 28-30,35-48       
  ...otaDialog.tsx |     100 |      100 |     100 |     100 |                   
  ...ngDisplay.tsx |   23.07 |      100 |       0 |   23.07 | 13-37             
  ...ryDisplay.tsx |     100 |      100 |     100 |     100 |                   
  ...ngsDialog.tsx |    59.9 |    71.81 |      75 |    59.9 | ...26-727,765,776 
  ...ionDialog.tsx |   85.91 |      100 |   33.33 |   85.91 | 35-38,43-50       
  ...Indicator.tsx |   44.44 |      100 |       0 |   44.44 | 12-17             
  ...MoreLines.tsx |      28 |      100 |       0 |      28 | 18-40             
  StatsDisplay.tsx |   98.58 |    93.33 |     100 |   98.58 | 193-195           
  ...nsDisplay.tsx |   88.31 |     62.5 |     100 |   88.31 | 38-43,85,110-112  
  ThemeDialog.tsx  |   91.08 |    48.27 |      75 |   91.08 | ...13-114,156-158 
  Tips.tsx         |   19.23 |      100 |       0 |   19.23 | 17-45             
  ...tsDisplay.tsx |     100 |     87.5 |     100 |     100 | 30-31             
  ...ification.tsx |   36.36 |      100 |       0 |   36.36 | 15-22             
  ...ionDialog.tsx |    8.64 |      100 |       0 |    8.64 | 20-112            
 ...nents/messages |   80.47 |     85.8 |   57.14 |   80.47 |                   
  ...onMessage.tsx |   20.68 |      100 |       0 |   20.68 | 23-51             
  DiffRenderer.tsx |   93.03 |    85.55 |     100 |   93.03 | ...02,228-229,295 
  ErrorMessage.tsx |   22.22 |      100 |       0 |   22.22 | 16-31             
  ...niMessage.tsx |      20 |      100 |       0 |      20 | 21-46             
  ...geContent.tsx |   19.04 |      100 |       0 |   19.04 | 25-43             
  InfoMessage.tsx  |   26.31 |      100 |       0 |   26.31 | 17-32             
  ...onMessage.tsx |   83.18 |       80 |      40 |   83.18 | ...12-127,141-144 
  ...upMessage.tsx |   94.84 |    95.45 |     100 |   94.84 | 124-128           
  ToolMessage.tsx  |   88.35 |       80 |     100 |   88.35 | ...,93-97,175-177 
  UserMessage.tsx  |     100 |      100 |     100 |     100 |                   
  ...llMessage.tsx |   36.36 |      100 |       0 |   36.36 | 17-25             
 ...ponents/shared |   84.02 |    76.88 |   95.55 |   84.02 |                   
  EnumSelector.tsx |     100 |    96.42 |     100 |     100 | 58                
  MaxSizedBox.tsx  |   81.62 |    81.81 |   88.88 |   81.62 | ...07-508,613-614 
  ...tonSelect.tsx |   86.79 |    66.66 |     100 |   86.79 | ...52,155-156,234 
  ...eSelector.tsx |     100 |       50 |     100 |     100 | 35-40             
  text-buffer.ts   |   82.38 |    78.02 |   96.66 |   82.38 | ...1797,1824,1874 
  ...er-actions.ts |   86.71 |    67.79 |     100 |   86.71 | ...07-608,809-811 
 src/ui/contexts   |   83.85 |    80.81 |   86.36 |   83.85 |                   
  AppContext.tsx   |      40 |      100 |       0 |      40 | 17-22             
  ...igContext.tsx |   81.81 |       50 |     100 |   81.81 | 15-16             
  ...ssContext.tsx |   84.82 |    84.67 |     100 |   84.82 | ...87-592,688-690 
  ...owContext.tsx |   89.28 |       80 |   66.66 |   89.28 | 34,47-48,60-62    
  ...onContext.tsx |    91.3 |      100 |     100 |    91.3 | 98-99,103-106     
  ...gsContext.tsx |   83.33 |       50 |     100 |   83.33 | 17-18             
  ...ngContext.tsx |   71.42 |       50 |     100 |   71.42 | 17-20             
  ...nsContext.tsx |   86.66 |       50 |     100 |   86.66 | 53-54             
  ...teContext.tsx |      80 |       50 |     100 |      80 | 116-117           
  ...deContext.tsx |   67.39 |    28.57 |      50 |   67.39 | 47-48,52-59,75-80 
 src/ui/editors    |   93.18 |    85.71 |   66.66 |   93.18 |                   
  ...ngsManager.ts |   93.18 |    85.71 |   66.66 |   93.18 | 48,62-63          
 src/ui/hooks      |   79.25 |    80.94 |   83.52 |   79.25 |                   
  ...dProcessor.ts |   78.76 |    80.19 |     100 |   78.76 | ...47-450,461-479 
  ...dProcessor.ts |   96.34 |    76.31 |     100 |   96.34 | ...12-213,218-219 
  ...dProcessor.ts |   81.22 |    71.59 |   71.42 |   81.22 | ...97-401,462-490 
  ...Completion.ts |   92.77 |    89.28 |     100 |   92.77 | ...85-186,219-222 
  ...tIndicator.ts |     100 |      100 |     100 |     100 |                   
  ...ketedPaste.ts |    23.8 |      100 |       0 |    23.8 | 19-37             
  ...ompletion.tsx |    95.3 |       80 |     100 |    95.3 | ...24-225,227-228 
  useCompletion.ts |    92.4 |     87.5 |     100 |    92.4 | 68-69,93-94,98-99 
  ...leMessages.ts |   98.68 |       95 |     100 |   98.68 | 55                
  ...orSettings.ts |     100 |      100 |     100 |     100 |                   
  useFocus.ts      |     100 |      100 |     100 |     100 |                   
  ...olderTrust.ts |     100 |      100 |     100 |     100 |                   
  ...miniStream.ts |   71.31 |    70.54 |      75 |   71.31 | ...5-896,926-1028 
  ...BranchName.ts |   91.66 |    84.61 |     100 |   91.66 | 57-63             
  ...oryManager.ts |   98.41 |    93.33 |     100 |   98.41 | 43                
  ...stListener.ts |   84.37 |    58.33 |     100 |   84.37 | 19,24,41,43-44    
  ...putHistory.ts |    92.5 |    85.71 |     100 |    92.5 | 62-63,71,93-95    
  ...storyStore.ts |     100 |    94.11 |     100 |     100 | 66                
  useKeypress.ts   |     100 |      100 |     100 |     100 |                   
  ...rdProtocol.ts |   36.36 |      100 |       0 |   36.36 | 24-31             
  ...gIndicator.ts |     100 |      100 |     100 |     100 |                   
  useLogger.ts     |      25 |      100 |       0 |      25 | 15-33             
  ...ssageQueue.ts |     100 |      100 |     100 |     100 |                   
  ...raseCycler.ts |    95.6 |       80 |     100 |    95.6 | ...73-174,190-192 
  ...cySettings.ts |   86.48 |    78.94 |     100 |   86.48 | ...08-109,120-131 
  ...Completion.ts |   40.64 |    56.52 |     100 |   40.64 | ...23-224,226-227 
  ...ndFallback.ts |   98.27 |    96.42 |     100 |   98.27 | 69-71             
  ...lScheduler.ts |   78.92 |    94.44 |     100 |   78.92 | ...01-204,291-301 
  ...oryCommand.ts |       0 |        0 |       0 |       0 | 1-7               
  ...ompletion.tsx |    94.2 |      100 |     100 |    94.2 | 78-81             
  ...ngsCommand.ts |   18.75 |      100 |       0 |   18.75 | 10-25             
  ...ellHistory.ts |   91.66 |    79.41 |     100 |   91.66 | ...69,117-118,128 
  ...oryCommand.ts |       0 |        0 |       0 |       0 | 1-76              
  ...Completion.ts |   77.56 |    79.77 |      90 |   77.56 | ...44-452,473-479 
  ...tateAndRef.ts |   13.63 |      100 |       0 |   13.63 | 16-36             
  ...rminalSize.ts |   18.18 |      100 |       0 |   18.18 | 12-32             
  ...emeCommand.ts |    7.89 |      100 |       0 |    7.89 | 24-101            
  useTimer.ts      |   88.09 |    85.71 |     100 |   88.09 | 44-45,51-53       
  ...eMigration.ts |   11.11 |      100 |       0 |   11.11 | 16-70             
  vim.ts           |   83.57 |     79.5 |     100 |   83.57 | ...38,742-750,759 
 src/ui/privacy    |   14.44 |      100 |       0 |   14.44 |                   
  ...acyNotice.tsx |   10.25 |      100 |       0 |   10.25 | 21-119            
  ...acyNotice.tsx |   14.28 |      100 |       0 |   14.28 | 16-59             
  ...acyNotice.tsx |   12.19 |      100 |       0 |   12.19 | 16-62             
  ...acyNotice.tsx |   30.76 |      100 |       0 |   30.76 | 19-36,39-41       
 src/ui/themes     |   98.99 |    60.43 |     100 |   98.99 |                   
  ansi-light.ts    |     100 |      100 |     100 |     100 |                   
  ansi.ts          |     100 |      100 |     100 |     100 |                   
  atom-one-dark.ts |     100 |      100 |     100 |     100 |                   
  ayu-light.ts     |     100 |      100 |     100 |     100 |                   
  ayu.ts           |     100 |      100 |     100 |     100 |                   
  color-utils.ts   |     100 |      100 |     100 |     100 |                   
  default-light.ts |     100 |      100 |     100 |     100 |                   
  default.ts       |     100 |      100 |     100 |     100 |                   
  dracula.ts       |     100 |      100 |     100 |     100 |                   
  github-dark.ts   |     100 |      100 |     100 |     100 |                   
  github-light.ts  |     100 |      100 |     100 |     100 |                   
  googlecode.ts    |     100 |      100 |     100 |     100 |                   
  no-color.ts      |     100 |      100 |     100 |     100 |                   
  ...tic-tokens.ts |     100 |      100 |     100 |     100 |                   
  ...-of-purple.ts |     100 |      100 |     100 |     100 |                   
  theme-manager.ts |    87.5 |    78.33 |     100 |    87.5 | ...86-292,297-298 
  theme.ts         |     100 |    32.25 |     100 |     100 | 255-437           
  xcode.ts         |     100 |      100 |     100 |     100 |                   
 src/ui/utils      |   65.99 |    80.36 |   79.36 |   65.99 |                   
  ...Colorizer.tsx |   79.31 |    81.25 |     100 |   79.31 | ...51-154,190-216 
  ...olePatcher.ts |      78 |    77.77 |     100 |      78 | 58-69             
  ...nRenderer.tsx |   52.85 |    27.27 |     100 |   52.85 | ...26-132,142-144 
  ...wnDisplay.tsx |   85.62 |    87.69 |     100 |   85.62 | ...73-281,314-339 
  ...eRenderer.tsx |   78.09 |    76.19 |     100 |   78.09 | 55-83             
  ...boardUtils.ts |   32.25 |     37.5 |     100 |   32.25 | ...55-114,129-145 
  commandUtils.ts  |   92.79 |    88.37 |     100 |   92.79 | ...12,116,118-119 
  computeStats.ts  |     100 |      100 |     100 |     100 |                   
  displayUtils.ts  |     100 |      100 |     100 |     100 |                   
  formatters.ts    |   90.47 |    95.83 |     100 |   90.47 | 57-60             
  highlight.ts     |     100 |      100 |     100 |     100 |                   
  isNarrowWidth.ts |     100 |      100 |     100 |     100 |                   
  ...olDetector.ts |    7.89 |      100 |       0 |    7.89 | ...11-112,115-116 
  ...nUtilities.ts |   69.84 |    85.71 |     100 |   69.84 | 75-91,100-101     
  ...mConstants.ts |     100 |      100 |     100 |     100 |                   
  terminalSetup.ts |       4 |      100 |       0 |       4 | 40-342            
  textUtils.ts     |   94.11 |    82.35 |     100 |   94.11 | 17-18             
  updateCheck.ts   |     100 |    80.95 |     100 |     100 | 27-39             
 src/utils         |   52.19 |    91.83 |   90.27 |   52.19 |                   
  checks.ts        |   33.33 |      100 |       0 |   33.33 | 23-28             
  cleanup.ts       |   65.38 |      100 |   66.66 |   65.38 | 28-37             
  deepMerge.ts     |     100 |    89.28 |     100 |     100 | 41-43,49          
  ...ScopeUtils.ts |   79.06 |    66.66 |     100 |   79.06 | 55-64             
  ...arResolver.ts |   96.42 |       96 |     100 |   96.42 | 111-112           
  errors.ts        |     100 |    96.66 |     100 |     100 | 77                
  events.ts        |     100 |      100 |     100 |     100 |                   
  gitUtils.ts      |   94.66 |    82.35 |     100 |   94.66 | 75-78             
  ...AutoUpdate.ts |    51.2 |       95 |      50 |    51.2 | 84-149            
  ...lationInfo.ts |     100 |      100 |     100 |     100 |                   
  package.ts       |   88.88 |       80 |     100 |   88.88 | 33-34             
  readStdin.ts     |   79.24 |       90 |      80 |   79.24 | 31-38,50-52       
  resolvePath.ts   |   66.66 |       25 |     100 |   66.66 | 12-13,16,18-19    
  sandbox.ts       |       0 |        0 |       0 |       0 | 1-950             
  settingsUtils.ts |   87.33 |    94.73 |   96.87 |   87.33 | ...91-418,462-463 
  spawnWrapper.ts  |     100 |      100 |     100 |     100 |                   
  ...upWarnings.ts |   53.84 |    33.33 |     100 |   53.84 | 17-26,38-39       
  ...entEmitter.ts |     100 |      100 |     100 |     100 |                   
  ...upWarnings.ts |     100 |      100 |     100 |     100 |                   
  version.ts       |     100 |       50 |     100 |     100 | 11                
 ...ed-integration |   25.12 |        0 |       0 |   25.12 |                   
  acp.ts           |    3.29 |        0 |       0 |    3.29 | ...53-289,292-339 
  ...temService.ts |   19.35 |      100 |       0 |   19.35 | 15-19,22-34,37-46 
  schema.ts        |     100 |      100 |     100 |     100 |                   
  ...ntegration.ts |    3.15 |        0 |       0 |    3.15 | ...18-865,880-930 
-------------------|---------|----------|---------|---------|-------------------
Core Package - Full Text Report
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   79.33 |     84.9 |    78.5 |   79.33 |                   
 src               |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
 src/__mocks__/fs  |     100 |      100 |     100 |     100 |                   
  promises.ts      |     100 |      100 |     100 |     100 |                   
 src/code_assist   |   78.26 |     83.6 |   80.85 |   78.26 |                   
  codeAssist.ts    |    17.5 |      100 |       0 |    17.5 | 16-38,41-54       
  converter.ts     |    96.2 |    95.55 |     100 |    96.2 | 179-183,197       
  ...al-storage.ts |     100 |    74.07 |     100 |     100 | 39-41,72-75       
  oauth2.ts        |   80.94 |    82.43 |   91.66 |   80.94 | ...87-488,511-512 
  server.ts        |   54.21 |    73.33 |   57.14 |   54.21 | ...30-233,252-253 
  setup.ts         |   86.66 |    78.94 |     100 |   86.66 | ...,92-94,118-124 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/config        |   79.26 |    89.92 |   53.27 |   79.26 |                   
  config.ts        |   78.36 |    89.16 |   47.95 |   78.36 | ...24-925,989-990 
  models.ts        |     100 |      100 |     100 |     100 |                   
  storage.ts       |   84.44 |    94.73 |      75 |   84.44 | ...14-115,118-119 
 ...nfirmation-bus |    95.5 |    90.47 |   85.71 |    95.5 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-8               
  message-bus.ts   |   98.71 |    94.73 |     100 |   98.71 | 74                
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/core          |   80.62 |    84.84 |   76.19 |   80.62 |                   
  baseLlmClient.ts |     100 |      100 |     100 |     100 |                   
  client.ts        |   80.26 |    84.66 |   71.42 |   80.26 | ...97-805,872-880 
  ...tGenerator.ts |    92.7 |    79.16 |     100 |    92.7 | 83-84,135,155-158 
  ...lScheduler.ts |   81.97 |    80.64 |   88.46 |   81.97 | ...1027,1107-1111 
  geminiChat.ts    |    80.3 |    86.61 |   64.51 |    80.3 | ...66-867,870-871 
  geminiRequest.ts |     100 |      100 |     100 |     100 |                   
  logger.ts        |   82.94 |    81.81 |     100 |   82.94 | ...44-348,388-399 
  ...tGenerator.ts |   13.51 |      100 |      10 |   13.51 | ...87-188,191-194 
  ...olExecutor.ts |     100 |      100 |      50 |     100 |                   
  prompts.ts       |   97.77 |      100 |   66.66 |   97.77 | 347-404           
  subagent.ts      |   86.81 |    81.31 |     100 |   86.81 | ...54-662,705-706 
  tokenLimits.ts   |   14.28 |      100 |       0 |   14.28 | 15-32             
  turn.ts          |   87.86 |    88.46 |     100 |   87.86 | ...20,333-334,381 
 src/fallback      |     100 |      100 |     100 |     100 |                   
  handler.ts       |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/generated     |     100 |      100 |     100 |     100 |                   
  git-commit.ts    |     100 |      100 |     100 |     100 |                   
 src/ide           |   75.17 |    83.95 |    74.5 |   75.17 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  detect-ide.ts    |   96.96 |    97.29 |     100 |   96.96 | 63-65             
  ide-client.ts    |      61 |    76.71 |   58.06 |      61 | ...37-645,670-678 
  ide-installer.ts |   91.45 |       84 |     100 |   91.45 | ...95,130-134,147 
  ideContext.ts    |   85.83 |      100 |     100 |   85.83 | 44-60             
  process-utils.ts |   87.09 |    74.19 |     100 |   87.09 | ...25,156,166-167 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/mcp           |   76.59 |    69.13 |   80.48 |   76.59 |                   
  ...h-provider.ts |   86.36 |      100 |   33.33 |   86.36 | ...85,89,93,97-98 
  ...h-provider.ts |   74.52 |    52.17 |     100 |   74.52 | ...03-807,814-816 
  ...en-storage.ts |   97.39 |      100 |      90 |   97.39 | 67-69             
  oauth-utils.ts   |   67.78 |    78.57 |    90.9 |   67.78 | ...61-282,307-330 
 .../token-storage |   88.18 |    86.46 |      95 |   88.18 |                   
  ...en-storage.ts |     100 |      100 |     100 |     100 |                   
  ...en-storage.ts |   82.75 |    82.35 |   92.85 |   82.75 | ...62-172,180-181 
  ...en-storage.ts |     100 |      100 |     100 |     100 |                   
  ...en-storage.ts |   85.71 |    81.81 |      90 |   85.71 | ...25-227,249-250 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/mocks         |     100 |      100 |     100 |     100 |                   
  msw.ts           |     100 |      100 |     100 |     100 |                   
 src/output        |     100 |      100 |     100 |     100 |                   
  ...-formatter.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/policy        |   92.96 |    93.75 |    90.9 |   92.96 |                   
  index.ts         |       0 |        0 |       0 |       0 | 1-8               
  policy-engine.ts |     100 |      100 |     100 |     100 |                   
  ...-stringify.ts |   89.09 |    88.88 |     100 |   89.09 | 63-64,69-70,90-91 
  types.ts         |     100 |      100 |     100 |     100 |                   
 src/prompts       |   26.41 |      100 |      25 |   26.41 |                   
  mcp-prompts.ts   |   18.18 |      100 |       0 |   18.18 | 11-19             
  ...t-registry.ts |   28.57 |      100 |   28.57 |   28.57 | ...42,48-55,68-73 
 src/services      |   90.37 |    84.92 |    91.8 |   90.37 |                   
  ...ingService.ts |   85.27 |    57.14 |     100 |   85.27 | ...13-415,442-444 
  ...eryService.ts |   96.73 |    96.96 |    87.5 |   96.73 | 115,140-141       
  ...temService.ts |     100 |      100 |     100 |     100 |                   
  gitService.ts    |      70 |    93.33 |      60 |      70 | ...15-125,128-132 
  ...ionService.ts |   97.53 |     92.1 |     100 |   97.53 | ...44-345,351-352 
  ...ionService.ts |   92.21 |    88.15 |     100 |   92.21 | ...68-369,446-460 
 src/telemetry     |   68.82 |     82.8 |   72.97 |   68.82 |                   
  constants.ts     |     100 |      100 |     100 |     100 |                   
  ...-exporters.ts |   26.47 |        0 |       0 |   26.47 | ...84,87-88,91-92 
  ...rk-tracker.ts |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  ...t.circular.ts |       0 |        0 |       0 |       0 | 1-63              
  ...t.circular.ts |       0 |        0 |       0 |       0 | 1-128             
  loggers.ts       |   63.15 |    72.72 |   59.09 |   63.15 | ...98-617,620-639 
  metrics.ts       |   63.72 |     93.1 |      50 |   63.72 | ...59-261,267-269 
  rate-limiter.ts  |     100 |      100 |     100 |     100 |                   
  sdk.ts           |   78.37 |    44.44 |     100 |   78.37 | ...83,188-189,191 
  ...etry-utils.ts |     100 |      100 |     100 |     100 |                   
  ...l-decision.ts |     100 |      100 |     100 |     100 |                   
  types.ts         |   77.02 |    79.03 |   80.55 |   77.02 | ...20-431,538-558 
  uiTelemetry.ts   |    99.3 |    95.83 |     100 |    99.3 | 130               
 ...learcut-logger |   72.22 |    78.66 |   62.85 |   72.22 |                   
  ...cut-logger.ts |   68.95 |    78.37 |   62.85 |   68.95 | ...76-977,980-983 
  ...tadata-key.ts |     100 |      100 |     100 |     100 |                   
 src/test-utils    |   76.01 |       96 |   66.66 |   76.01 |                   
  config.ts        |     100 |      100 |     100 |     100 |                   
  index.ts         |     100 |      100 |     100 |     100 |                   
  mock-tool.ts     |   18.64 |      100 |       0 |   18.64 | ...8,61-62,72-115 
  ...aceContext.ts |     100 |      100 |     100 |     100 |                   
  tools.ts         |   95.86 |    95.23 |      80 |   95.86 | 60-61,129,133-134 
 src/tools         |   74.16 |    82.04 |   81.92 |   74.16 |                   
  diffOptions.ts   |     100 |      100 |     100 |     100 |                   
  edit.ts          |   83.02 |    88.37 |   85.71 |   83.02 | ...46-447,537-577 
  glob.ts          |   91.11 |    81.96 |    87.5 |   91.11 | ...29-230,332-333 
  grep.ts          |   59.25 |    82.14 |      80 |   59.25 | ...04-608,618-619 
  ls.ts            |   96.29 |    88.52 |     100 |   96.29 | 140-145,176,180   
  ...nt-manager.ts |   80.89 |    66.66 |      80 |   80.89 | ...12-119,127-128 
  mcp-client.ts    |    31.6 |    78.02 |      50 |    31.6 | ...1367,1371-1374 
  mcp-tool.ts      |    94.9 |    93.05 |   94.11 |    94.9 | 200-210,272-273   
  memoryTool.ts    |   83.15 |    82.97 |   88.88 |   83.15 | ...31-246,357-375 
  ...iable-tool.ts |     100 |    84.61 |     100 |     100 | 99,106            
  read-file.ts     |    98.7 |    97.14 |    87.5 |    98.7 | 63-64             
  ...many-files.ts |   78.78 |    79.41 |   85.71 |   78.78 | ...37-438,445-446 
  ripGrep.ts       |   89.94 |    86.73 |   93.33 |   89.94 | ...52-453,474-475 
  shell.ts         |   85.54 |    77.33 |    90.9 |   85.54 | ...94-395,406-407 
  smart-edit.ts    |   78.93 |    75.24 |   85.71 |   78.93 | ...88-790,802-845 
  tool-error.ts    |     100 |      100 |     100 |     100 |                   
  tool-registry.ts |    72.8 |    66.07 |   77.77 |    72.8 | ...08-410,437-438 
  tools.ts         |   86.34 |    89.13 |      75 |   86.34 | ...68-369,385-391 
  web-fetch.ts     |    60.3 |    54.05 |    90.9 |    60.3 | ...45-346,353-354 
  web-search.ts    |     100 |     93.1 |     100 |     100 | 106-107           
  write-file.ts    |   83.95 |    83.87 |      75 |   83.95 | ...49-452,464-500 
 src/utils         |   87.08 |    88.17 |   88.78 |   87.08 |                   
  LruCache.ts      |   80.64 |       75 |     100 |   80.64 | 28,30-34          
  bfsFileSearch.ts |   89.77 |     92.3 |     100 |   89.77 | 86-94             
  browser.ts       |    7.69 |      100 |       0 |    7.69 | 17-56             
  editCorrector.ts |    77.3 |    61.11 |   91.66 |    77.3 | ...66-678,712,726 
  editor.ts        |   97.63 |    94.54 |     100 |   97.63 | 154,224,227-228   
  ...entContext.ts |     100 |      100 |     100 |     100 |                   
  errorParsing.ts  |     100 |     92.3 |     100 |     100 | 76,80,86          
  ...rReporting.ts |   83.72 |    84.61 |     100 |   83.72 | 82-86,107-115     
  errors.ts        |   55.95 |    71.42 |   41.66 |   55.95 | ...86-102,106-112 
  fetch.ts         |   34.04 |      100 |       0 |   34.04 | 22-27,31-57       
  fileUtils.ts     |   95.32 |    90.37 |     100 |   95.32 | ...36-240,450-456 
  formatters.ts    |   54.54 |       50 |     100 |   54.54 | 12-16             
  ...noreParser.ts |   85.45 |    81.48 |     100 |   85.45 | ...59,65-66,72-73 
  ...eUtilities.ts |    95.4 |    94.87 |     100 |    95.4 | 16-17,45-46       
  ...rStructure.ts |   95.96 |    94.93 |     100 |   95.96 | ...14-117,345-347 
  getPty.ts        |    12.5 |      100 |       0 |    12.5 | 21-34             
  ...noreParser.ts |    92.3 |    89.13 |     100 |    92.3 | ...15-116,186-187 
  gitUtils.ts      |   51.21 |       90 |      50 |   51.21 | 40-41,50-73       
  ide-trust.ts     |      60 |      100 |       0 |      60 | 14-15             
  ...rePatterns.ts |     100 |      100 |     100 |     100 |                   
  ...ionManager.ts |     100 |       90 |     100 |     100 | 23                
  ...-detection.ts |     100 |      100 |     100 |     100 |                   
  ...edit-fixer.ts |     100 |      100 |     100 |     100 |                   
  ...yDiscovery.ts |   85.75 |    75.43 |   77.77 |   85.75 | ...87-388,391-392 
  ...tProcessor.ts |   91.51 |    88.46 |   84.61 |   91.51 | ...02-308,385-386 
  ...Inspectors.ts |     100 |      100 |     100 |     100 |                   
  ...kerChecker.ts |   83.33 |    83.33 |     100 |   83.33 | 64-65,75-80,88-94 
  partUtils.ts     |     100 |      100 |     100 |     100 |                   
  pathReader.ts    |     100 |      100 |     100 |     100 |                   
  paths.ts         |   86.13 |    87.87 |     100 |   86.13 | ...,89-90,101-102 
  ...tIdContext.ts |     100 |      100 |     100 |     100 |                   
  ...rDetection.ts |    64.4 |    76.19 |     100 |    64.4 | ...4,88-89,99-100 
  retry.ts         |   62.55 |    73.21 |     100 |   62.55 | ...58-278,323-338 
  ...nStringify.ts |     100 |      100 |     100 |     100 |                   
  ...aValidator.ts |    82.6 |       50 |     100 |    82.6 | 27-28,30-31       
  ...r-launcher.ts |   76.52 |     87.5 |   66.66 |   76.52 | ...33,135,153-191 
  session.ts       |     100 |      100 |     100 |     100 |                   
  shell-utils.ts   |   96.08 |    93.96 |     100 |   96.08 | ...94-195,242-244 
  summarizer.ts    |     100 |    88.88 |     100 |     100 | 91                
  ...emEncoding.ts |      98 |    94.11 |     100 |      98 | 106-107           
  testUtils.ts     |   84.44 |    72.72 |   83.33 |   84.44 | 27-28,34-35,70-72 
  textUtils.ts     |    12.5 |      100 |       0 |    12.5 | 15-34             
  tool-utils.ts    |   91.48 |    89.47 |     100 |   91.48 | 53-54,57-58       
  ...untManager.ts |   97.14 |    94.59 |     100 |   97.14 | 36-38             
  ...aceContext.ts |   96.82 |    95.12 |    92.3 |   96.82 | 94-95,109-110     
 ...ils/filesearch |   96.17 |     91.4 |     100 |   96.17 |                   
  crawlCache.ts    |     100 |      100 |     100 |     100 |                   
  crawler.ts       |   96.22 |     92.3 |     100 |   96.22 | 66-67             
  fileSearch.ts    |   93.22 |    87.14 |     100 |   93.22 | ...28-229,231-232 
  ignore.ts        |     100 |      100 |     100 |     100 |                   
  result-cache.ts  |     100 |     92.3 |     100 |     100 | 46                
-------------------|---------|----------|---------|---------|-------------------

For detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run.

Fixes the security vulnerability identified by Gemini Code Assist where
JSON.stringify() could produce different output for the same arguments
due to non-deterministic property ordering. This could allow security
policies to be bypassed.

Changes:
- Implement stableStringify() method with sorted keys for consistent output
- Ensure pattern matching works regardless of argument property order
- Add comprehensive tests for order-independent matching
- Test nested objects to ensure deep stability

This ensures PolicyEngine rules cannot be bypassed by reordering
object properties in tool arguments.
@allenhutchison
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a solid foundation for a tool confirmation message bus and a policy engine. The code is well-structured, clearly written, and includes comprehensive unit tests. The new MessageBus and PolicyEngine classes are well-designed and their integration into the Config class is clean. I've found one critical security vulnerability related to a potential denial-of-service in the PolicyEngine's stableStringify method, for which I've provided a detailed comment and a suggested fix. Besides this issue, the implementation is excellent.

…eStringify

Addresses the denial-of-service vulnerability identified in code review where
circular references in tool arguments could cause infinite recursion and
stack overflow in the stableStringify method.

Changes:
- Implement WeakSet tracking to detect and handle circular references
- Replace recursive calls with inner stringify function that tracks visited objects
- Return "[Circular]" placeholder when circular reference detected
- Add comprehensive tests for both shallow and deep circular references
- Use proper TypeScript types instead of 'any' in tests

Security impact:
- Prevents potential DoS attacks via crafted tool arguments
- Ensures PolicyEngine remains robust against malformed input
- Maintains stable stringification while preventing infinite recursion
@allenhutchison
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request lays a solid foundation for the Tool Confirmation Message Bus and Policy Engine. The code is well-structured, clearly written, and accompanied by an excellent and comprehensive suite of unit tests that cover many edge cases. I found one high-severity issue in the stableStringify implementation within the PolicyEngine that could lead to incorrect behavior or errors. My review includes a detailed explanation and a code suggestion to fix it. Overall, this is a great piece of work.

…ringify

Fixed multiple security vulnerabilities identified in code review:
- Correctly handle repeated non-circular objects (no false positives)
- Properly handle undefined and function values per JSON spec
- Use Set with ancestor chain tracking instead of WeakSet
- Ensure generated JSON is always valid
- Add comprehensive test coverage for edge cases

The stableStringify method now:
- Tracks ancestor chain per branch to detect true circular references
- Omits undefined/function values from objects (per JSON spec)
- Converts undefined/functions to null in arrays (per JSON spec)
- Produces deterministic output with sorted keys for consistent pattern matching
@allenhutchison
Copy link
Copy Markdown
Contributor Author

/gemini review

- Wrap array test inputs in objects to match Record<string, unknown> type
- Add explicit type annotation for testCases array
- Ensure all test inputs have correct types for args parameter
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a solid foundation for tool confirmation handling with a new MessageBus and PolicyEngine. The code is well-structured and comes with an impressive and comprehensive set of unit tests. I've found a critical issue in the stableStringify implementation that could lead to incorrect policy enforcement, and a high-severity issue regarding inconsistent use of readonly for a mutable property. Addressing these will make the implementation much more robust and secure.

…mentation

Fixes based on code review:
- Remove readonly modifier from rules array since it's mutated by addRule/removeRulesForTool
- Add support for toJSON methods per JSON.stringify specification
- Add comprehensive documentation for stableStringify method
- Add tests for toJSON handling including edge cases

The stableStringify method now fully respects the JSON specification while
maintaining deterministic output for security policy matching.
@allenhutchison
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a solid foundation for the Tool Confirmation Message Bus. The new MessageBus and PolicyEngine classes are well-designed and provide a decoupled, event-driven way to handle tool confirmations. The PolicyEngine is particularly robust, with a priority-based rule system and a secure, deterministic method for serializing tool arguments. The unit test coverage is excellent and covers many edge cases, including complex object structures and circular references.

I have one high-severity suggestion for the MessageBus implementation to improve its error handling robustness by using a safe JSON stringification method, preventing potential crashes from circular references in tool arguments.

Replace JSON.stringify with safeJsonStringify to handle potential
circular references in message objects. This prevents TypeError
exceptions when logging invalid messages with circular references
in toolCall.args.
Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

These changes look great! Really excited about an event bus. Left a couple of comments. LMK what you think!

import { MessageBusType, type Message } from './types.js';
import { safeJsonStringify } from '../utils/safeJsonStringify.js';

export class MessageBus extends EventEmitter {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thinking out loud, I know we want to eliminate dependencies and things, but if we add this generic messageBus we should probably consider whether or not we should use another library for events/messaging.

RXJS is pretty heavy, but has a lot of utilities for dealing with event streams and the like. It can be a pain to learn, but has a mountain of flexibility.

Signals has also been proposed in TC39 - https://github.com/tc39/proposal-signals . Internally, Wiz and Angular have generalized signal implementations.

While potentially dismissible as overkill, I think we should probably consider solutions for messaging (or eliminate them).

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.

Interesting suggestion and this has been on my mind as well. However I'd prefer we go with EventEmitter for now. RXJS could be interesting to consider in the future and I'm not sure our state is yet complex enough for it to be worth it. I would expect that if we decide to migrate, Gemini CLI could make the migration surprisingly easy in the future so I don't think we need to adopt RXJS until we really have cases where the complexity is worth the costs.

Copy link
Copy Markdown
Member

@richieforeman richieforeman Sep 10, 2025

Choose a reason for hiding this comment

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

(To be clear this is more "commentary" than an ask. No action is expected here for the interim).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I read through the RXJS and the TC39. I really appreciate the pointers and the suggestions. Thank you!

This commit addresses several comments from PR #7835.

- Refactors `removeRulesForTool` in `PolicyEngine` to use `.filter()` for better readability.
- Extracts `stableStringify` into its own utility file and makes `ruleMatches` a file-level function.
- Adds structural types to message objects in `message-bus.test.ts` to improve type safety.
- Makes `ToolExecutionSuccess` and `ToolExecutionFailure` interfaces generic for more flexible typing.
- Fixes failing tests in `message-bus.test.ts`.
Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

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

This looks great! LGTM

import { MessageBusType, type Message } from './types.js';
import { safeJsonStringify } from '../utils/safeJsonStringify.js';

export class MessageBus extends EventEmitter {
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.

Interesting suggestion and this has been on my mind as well. However I'd prefer we go with EventEmitter for now. RXJS could be interesting to consider in the future and I'm not sure our state is yet complex enough for it to be worth it. I would expect that if we decide to migrate, Gemini CLI could make the migration surprisingly easy in the future so I don't think we need to adopt RXJS until we really have cases where the complexity is worth the costs.

return false;
}
// Use stable JSON stringification with sorted keys to ensure consistent matching
const argsString = this.stableStringify(toolCall.args);
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.

should we cache the computation of stableStringify so we don't compute this again for each rule that might match?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}

// Create new ancestors set for this branch
const newAncestors = new Set(ancestors);
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.

performance nit: can you remove ancestors when leaving a branch rather than creating a new set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (Array.isArray(currentObj)) {
const items = currentObj.map((item) => {
// undefined and functions in arrays become null
if (item === undefined || typeof item === 'function') {
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.

nit: also check for null here to avoid recursing for this primitive case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* stableStringify(obj)
* // Returns: '{"safe":"data"}'
*/
private stableStringify(obj: unknown): string {
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.

generally I worry this method is likely 50X slower than the regular stringify method. Might be worth benchmarking this or at least ensuring we don't call it more than once per tool call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Running benchmark with 10000 iterations...

--- simpleObject ---
JSON.stringify: 0.879ms
stableStringify: 7.036ms

--- nestedObject ---
JSON.stringify: 1.212ms
stableStringify: 8.83ms

--- arrayObject ---
JSON.stringify: 1.061ms
stableStringify: 11.287ms

--- complexObject ---
JSON.stringify: 1.396ms
stableStringify: 6.883ms

Yes slower, not 50x, but have made the changes to ensure it isn't called too often.

This commit addresses performance feedback on the `stableStringify` function and its usage within the `PolicyEngine`.

- The `stableStringify` function is optimized to avoid creating new sets for ancestor tracking on each recursion, and to handle nulls from `toJSON` more efficiently.
- The `PolicyEngine` now caches the result of `stableStringify` during a `check` operation, preventing it from being called repeatedly for each policy rule with an argument pattern. This significantly reduces the performance overhead when multiple such rules exist.
Copy link
Copy Markdown
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@jacob314 jacob314 added this pull request to the merge queue Sep 10, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 10, 2025
@abhipatel12 abhipatel12 added this pull request to the merge queue Sep 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 11, 2025
@allenhutchison allenhutchison added this pull request to the merge queue Sep 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 11, 2025
@allenhutchison allenhutchison added this pull request to the merge queue Sep 11, 2025
Merged via the queue into main with commit ba85aa4 Sep 11, 2025
23 checks passed
@allenhutchison allenhutchison deleted the adh/issue-7231 branch September 11, 2025 16:52
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants