This PR introduces support for diff-based file modifications in CodeWhisper's AI-assisted task implementation and restructures the parsing logic for improved modularity. These enhancements allow for more efficient handling of large edits within token limits and provide a more flexible, maintainable parsing system.
Changes
Restructured parsing logic into separate modules for improved modularity and maintainability
Updated src/ai/parse-ai-codegen-response.ts to handle diff-based modifications
Modified src/git/apply-changes.ts to apply diffs when available
Updated src/types/index.ts to include diff information in AIFileInfo
Added --diff flag to the task command for opt-in diff-based updates
Added -c, --context flag to the taskcommand and task options to allow automation and improved library usage
Updated relevant test files to cover new functionality
New Features
Users can now use the --diff flag with the task command to enable diff-based updates
CodeWhisper now supports both full content replacement and diff-based modifications for changed files
New modular parsing system allows for easier maintenance and extension of parsing capabilities
Implementation Details
Created new files for parsing logic:
src/ai/parsers/common-parser.ts: Common parsing functions used across different modes
src/ai/parsers/full-content-parser.ts: Parser for full content mode
src/ai/parsers/diff-parser.ts: Parser for diff-based mode
Utilized the diff library for parsing and applying patches
Enhanced error handling for cases where patches cannot be applied
Updated the dry run output to show diff previews when available
Parser Restructuring
Separated parsing logic into distinct modules to improve code organization and maintainability
Implemented a strategy pattern to switch between full content and diff-based parsing modes
Ensured backward compatibility with existing full content parsing while adding support for diff-based parsing
Testing
Added new tests to cover diff-based modification scenarios
Updated existing tests to reflect changes in file operation behavior
Created new tests for the restructured parsing modules
Documentation
Updated README.md and USAGE.md to include information about the new --diff option
Added examples demonstrating the use of diff-based updates in the documentation
Potential Impact
This change should significantly improve CodeWhisper's ability to handle larger code modifications, especially in cases where the full file content might exceed token limits. It provides users with more flexibility in how they want CodeWhisper to process and apply changes. The restructured parsing system will make it easier to maintain and extend CodeWhisper's parsing capabilities in the future.
Overview
This PR introduces support for diff-based file modifications in CodeWhisper's AI-assisted task implementation and restructures the parsing logic for improved modularity. These enhancements allow for more efficient handling of large edits within token limits and provide a more flexible, maintainable parsing system.
Changes
src/ai/parse-ai-codegen-response.ts
to handle diff-based modificationssrc/git/apply-changes.ts
to apply diffs when availablesrc/types/index.ts
to include diff information inAIFileInfo
--diff
flag to thetask
command for opt-in diff-based updates-c, --context
flag to thetask
command and task options to allow automation and improved library usageNew Features
--diff
flag with thetask
command to enable diff-based updatesImplementation Details
src/ai/parsers/common-parser.ts
: Common parsing functions used across different modessrc/ai/parsers/full-content-parser.ts
: Parser for full content modesrc/ai/parsers/diff-parser.ts
: Parser for diff-based modediff
library for parsing and applying patchesParser Restructuring
Testing
Documentation
--diff
optionPotential Impact
This change should significantly improve CodeWhisper's ability to handle larger code modifications, especially in cases where the full file content might exceed token limits. It provides users with more flexibility in how they want CodeWhisper to process and apply changes. The restructured parsing system will make it easier to maintain and extend CodeWhisper's parsing capabilities in the future.
Closes #56