AI Actions
Wing provides quick access to several AI agent-driven actions. These compose a detailed request from the relevant context and submit it to an agent session automatically. The results are either reported to the user or applied as code changes.
Editor Code Actions
The AI actions icon in the top right of the editor provides a dropdown menu of AI-driven code actions. These send a request to a dedicated agent session that reads the code and either reports findings or makes changes.
Report actions analyze code and report their findings without making any changes:
- Explain Code -- Explains the code's purpose, structure, and key design decisions.
- Review for Code Quality -- Reviews code for quality issues including structure, naming, error handling, maintainability, and clarity.
- Review for Security Risks -- Reviews code for security vulnerabilities including injection, authentication, data exposure, input validation, and other OWASP top 10 risks.
- Find Likely Bugs -- Reviews code for likely bugs such as logic errors, off-by-one and boundary mistakes, incorrect or missing error handling, and unhandled edge cases.
Fix actions modify the code to address the requested issue:
- Fix Code Warnings -- Fixes code issues that would cause warnings, such as unused imports, undefined names, type errors, and style issues.
- Refactor for Readability -- Refactors code to be more readable and maintainable, with clearer names, simpler control flow, and less duplication, without changing its external behavior.
- Optimize Code -- Optimizes code for performance by identifying and fixing inefficiencies, unnecessary allocations, and algorithmic improvements.
- Add Type Annotations -- Adds or refines type annotations for parameters, return types, and variables where they aid clarity, without changing code behavior.
- Add Error Handling -- Adds input validation and handling for currently-unhandled failure cases, without adding unnecessary or overly broad exception handling.
- Update Comments & Docstrings -- Adds or updates docstrings and comments to accurately describe the code's purpose and behavior.
Choosing a Scope
When the cursor is inside a class or function, each action offers a submenu to choose the scope:
- Whole File -- Applies the action to the entire file.
- Scope names -- One entry for each enclosing scope at the cursor position. For example, if the cursor is inside MyClass.my_method, the submenu offers both MyClass and MyClass.my_method.
- Current Selection -- Available when text spanning multiple lines is selected. Applies the action only to the selected code.
When no scopes are available and there is no selection, clicking the action applies it to the whole file directly without a submenu.
Custom Actions
You can define your own code actions using Manage Actions... at the bottom of the dropdown menu. Each custom action has a name, a type (report or fix), and a description that serves as the instruction sent to the agent.
Custom report actions appear alongside the built-in report actions, and custom fix actions appear alongside the built-in fix actions.
One-Click Fixes
Other parts of Wing's user interface also offer options for sending targeted fix requests to your AI agent, for common problems encountered during development. These create a dedicated agent session with a descriptive tab label (Fix Test, Fix Bug, Fix Warning, or Write Tests) and automatically submit the request:
- Fix This Test / Fix Tests -- Available from the Testing tool when one or more failed tests are selected, and from the Fix Failed Tests command in the Testing menu. When a single test is selected, sends the test failure details, exception, and output to the agent and asks it to analyze and fix the code. When multiple failed tests are selected, sends the list of failing tests and asks the agent to work through them one at a time, running each test to get failure details, fixing the code, and moving on to the next. See Fixing Tests.
- Fix This Bug -- Available from the Exceptions tool and the AI menu when the debugger is stopped at an exception. Sends the exception and traceback to the agent and asks it to fix the underlying bug. See Fixing Exceptions. This action reuses the existing session, since it often contains relevant context.
- Fix This Warning -- Available from the Code Warnings tool and editor warning tooltips. Sends the warning details and source context to the agent and asks it to fix the underlying issue. See Fixing Code Warnings.
- Write Tests -- Available from the Testing menu when the active editor contains a Python file. Sends the file contents and project test framework configuration to the agent and asks it to write unit tests. When text spanning one or more complete scopes (functions or classes) is selected, only the selected code is sent.
Which Session Takes the Fix
Fix This Bug, Fix Failed Tests, fixing code warnings and Write Tests prompt you to select where the work should be done. This can be any idle session that is able to take it on, or a new session. When the project is set up for more than one agent, the new-session choice is a submenu of the available agents. Note that user-defined custom code actions are configured once instead, to use a dedicated session, the active one, or to ask each time.
When the agent is waiting on a prompt and cannot yet take the request, Wing will show a dialog in the AI Agent tool before retrying the fix request.
Fix Completion Action
Fix actions from both the editor code actions and the one-click fixes follow the Fix Completion Action preference, which controls what happens after a fix completes (review changes, commit, or do nothing). See Configuration for details.
Concurrent Fix Warning
If a fix action or task is already running when you start another fix action, Wing warns you that running multiple fix actions at once may cause conflicts, and lets you choose whether to proceed or cancel. This warning can be disabled with the Warn on Concurrent Task Execution preference. See Configuration for details.
Concurrently running agent sessions working on the same code may overwrite each other's changes or be confused by ongoing changes.
Running concurrently is, however, not a problem if the fixes are not working on the same code files.
