Class AbstractTextResourceWrite

java.lang.Object
uno.anahata.asi.toolkit.resources.text.AbstractTextResourceWrite
Direct Known Subclasses:
CodeRefinementBatch, CodeRefinementBatchPolymorphic, FullTextResourceUpdate, TextResourceLineEdits, TextResourceReplacements

public abstract class AbstractTextResourceWrite extends Object
Base DTO for text file operations, providing common fields for path, historical content preservation, and optimistic locking.
Author:
anahata
  • Field Details

    • resourceUuid

      protected String resourceUuid
      The absolute path to the file to be updated.
    • lastModified

      protected long lastModified
      Optimistic locking: the expected last modified timestamp of the file on disk.
    • originalContent

      protected String originalContent
      The original content of the file before this operation was applied. This is captured during the first render to support historical diff views.
    • originalResourceName

      protected String originalResourceName
      The name of the resource at the time of capture.
    • resultingContent

      protected String resultingContent
      The final content of the file after the operation was successfully applied. Captured during execution to support static historical diff views.
    • manualOverride

      protected String manualOverride
      A manual override of the resulting content. If provided, the standard calculation logic is bypassed.
  • Constructor Details

    • AbstractTextResourceWrite

      public AbstractTextResourceWrite(String uuid, long lastModified)
      Minimal constructor for standard tool invocation and builder support.
      Parameters:
      uuid - The resource uuid.
      lastModified - The locking timestamp.
  • Method Details

    • captureOriginalContent

      public void captureOriginalContent(Agi agi) throws Exception
      Authoritatively captures the current state of the resource from the resource manager. This is the mandatory first step before validation, calculation, or diffing.
      Parameters:
      agi - The parent agi session.
      Throws:
      Exception - if the resource cannot be resolved or is not textual.
    • calculateResultingContent

      public final String calculateResultingContent(Agi agi) throws Exception
      Calculates the resulting content of the resource based on the captured originalContent.

      This base implementation handles the primary short-circuits: 1. If resultingContent is set (Historical view), it is returned. 2. If manualOverride is set (User tweak), it is returned. 3. Otherwise, it delegates to doCalculateResultingContent(Agi) for tool-specific logic.

      Parameters:
      agi - The parent agi session.
      Returns:
      The resulting content.
      Throws:
      Exception - if the calculation fails or original content is missing.
    • doCalculateResultingContent

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

      public String getUnifiedDiff(Agi agi) throws Exception
      Generates a unified diff of the proposed changes against the captured original content.
      Parameters:
      agi - The parent agi session.
      Returns:
      The unified diff string.
      Throws:
      Exception - if original content is missing or diff generation fails.
    • validate

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

      protected void validateStructuralState(Agi agi) throws Exception
      Validates the basic structural requirements and optimistic locking.
      Parameters:
      agi - The parent agi session.
      Throws:
      Exception - if validation fails.
    • validateIdenticalContent

      protected void validateIdenticalContent(Agi agi) throws Exception
      Validates that the resulting content is not identical to the original.
      Parameters:
      agi - The parent agi session.
      Throws:
      Exception - if the content is identical.