Skip to content

Better edit#14

Merged
kamilmac merged 2 commits intomainfrom
better-edit
May 24, 2025
Merged

Better edit#14
kamilmac merged 2 commits intomainfrom
better-edit

Conversation

@kamilmac
Copy link
Copy Markdown
Owner

Summary

This PR refactors the LLM provider selection logic, enhances file editing
capabilities with fuzzy matching and improved diff generation, and
introduces provider-specific system prompt extensions.

Changes

  • src/services/llm_providers/default.ts:
    • LLM configuration (llmCfg) selection now uses the new PROVIDER
      constant from src/utils/constants.ts instead of directly
      accessing config.provider.
  • src/services/tools/fs.ts:
    • The applyFileEdits function has been significantly refactored to
      improve robustness and accuracy of file modifications:

      • Edits are now sorted by their position in the file (in reverse
        order) before application to prevent offset issues.

      • Introduced fuzzy matching logic (findBestMatch,
        calculateSimilarity, applyFuzzyEdit) to locate and apply
        edits when exact matches for old_text are not found. This
        includes normalizing line endings and whitespace for matching.

      • Improved diff output formatting with dynamic backtick counting.

      • Added helper functions: normalizeLineEndings,
        normalizeForMatching, formatDiffOutput,
        sortEditsByPosition, findBestMatch, calculateSimilarity,
        applyFuzzyEdit, and getSurroundingContext for better error
        reporting.

    • The read_multiple_files tool description was slightly
      re-formatted (whitespace).

  • src/utils/constants.ts:
    • Added a new PROVIDER constant, which defaults to config.provider
      or "openai".

    • Introduced SYSTEM_PROVIDER_EXTENSION, a record to store
      provider-specific additions to the system prompt (e.g., for
      "gemini").

    • The main SYSTEM prompt now appends the relevant
      SYSTEM_PROVIDER_EXTENSION based on the active PROVIDER.

kamilmac added 2 commits May 23, 2025 18:13
…andling

- Add fuzzy matching algorithm for inexact text matches
- Sort edits by position and apply in reverse order to avoid offset issues
- Enhance error messages with surrounding context for failed matches
- Extract helper functions for better code organization
- Improve similarity scoring with whitespace normalization
@kamilmac kamilmac merged commit 91e1390 into main May 24, 2025
1 check failed
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.

1 participant