Class TextResourceReplacements

java.lang.Object
uno.anahata.asi.toolkit.resources.text.AbstractTextResourceWrite
uno.anahata.asi.toolkit.resources.text.TextResourceReplacements

public class TextResourceReplacements extends AbstractTextResourceWrite
Represents a set of text replacement operations for a specific file. Extends AbstractTextFileWrite to inherit path and optimistic locking.
Author:
anahata
  • Field Details

    • replacements

      private List<TextReplacement> replacements
      The list of replacements to perform in this file.
  • Constructor Details

    • TextResourceReplacements

      public TextResourceReplacements(String resourceUuid, long lastModified, List<TextReplacement> replacements)
      Constructs a new TextResourceReplacements using the builder pattern.
      Parameters:
      resourceUuid - The unique identifier of the target text resource.
      lastModified - Optimistic locking: the expected last modified timestamp of the file.
      replacements - The list of text replacements to perform.
  • Method Details

    • doCalculateResultingContent

      protected String doCalculateResultingContent(Agi agi) throws Exception
      Performs the actual, tool-specific calculation of the resulting content.
      Specified by:
      doCalculateResultingContent in class AbstractTextResourceWrite
      Parameters:
      agi - The parent agi session.
      Returns:
      The calculated resulting content as a String.
      Throws:
      Exception - if the calculation logic fails.
    • validate

      public void validate(Agi agi) throws Exception
      Performs pre-flight validation of the update operation. Note: This method ensures state is captured.
      Overrides:
      validate in class AbstractTextResourceWrite
      Parameters:
      agi - The parent agi session.
      Throws:
      Exception - if validation fails.
    • getTruncatedHint

      private String getTruncatedHint(Agi agi)
      Helper to construct a viewport truncation diagnostic hint if the resource view in the RAG prompt is currently truncated.
      Parameters:
      agi - The active Agi session.
      Returns:
      The formatted hint string, or empty string if not truncated.
    • normalizeForComparison

      private String normalizeForComparison(String s)
      Normalizes a string for comparison by standardizing line endings to LF. Whitespace is preserved exactly to prevent silent destruction of indentation.
      Parameters:
      s - The string to normalize.
      Returns:
      The normalized string.
    • normalizeWhitespaces

      private String normalizeWhitespaces(String s)
      Normalizes a string by standardizing line endings and removing trailing whitespace from each line for lenient diagnostic comparison.
      Parameters:
      s - The string to normalize.
      Returns:
      The normalized string.