Class LLMAssistedCodemod

java.lang.Object
io.codemodder.RawFileChanger
io.codemodder.SarifPluginRawFileChanger
io.codemodder.plugins.llm.LLMAssistedCodemod
All Implemented Interfaces:
io.codemodder.CodeChanger

public abstract class LLMAssistedCodemod extends io.codemodder.SarifPluginRawFileChanger
An extension of SarifPluginRawFileChanger that uses large language models (LLMs) to analyze and fix the files found by the static analysis tool.
  • Field Summary

    Fields inherited from class io.codemodder.RawFileChanger

    reporter
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    LLMAssistedCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Returns a class resource as a String.
    protected abstract String
    Instructs the LLM on how to fix the threat.
    protected abstract String
    Instructs the LLM on how to assess the risk of the threat.
    protected abstract boolean
    isPatchExpected(com.github.difflib.patch.Patch<String> patch)
    Returns whether the patch returned by the LLM is within the expectations of this codemod.
    List<io.codemodder.CodemodChange>
    onFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results)
     

    Methods inherited from class io.codemodder.SarifPluginRawFileChanger

    visitFile

    Methods inherited from class io.codemodder.RawFileChanger

    getDescription, getIndividualChangeDescription, getReferences, getSourceControlUrl, getSummary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LLMAssistedCodemod

      protected LLMAssistedCodemod(io.codemodder.RuleSarif sarif, OpenAIService openAI)
  • Method Details

    • onFileFound

      public List<io.codemodder.CodemodChange> onFileFound(io.codemodder.CodemodInvocationContext context, List<com.contrastsecurity.sarif.Result> results)
      Specified by:
      onFileFound in class io.codemodder.SarifPluginRawFileChanger
    • getThreatPrompt

      protected abstract String getThreatPrompt()
      Instructs the LLM on how to assess the risk of the threat.
      Returns:
      The prompt.
    • getFixPrompt

      protected abstract String getFixPrompt()
      Instructs the LLM on how to fix the threat.
      Returns:
      The prompt.
    • isPatchExpected

      protected abstract boolean isPatchExpected(com.github.difflib.patch.Patch<String> patch)
      Returns whether the patch returned by the LLM is within the expectations of this codemod.
      Returns:
      true if the patch is expected; otherwise, false.
    • getClassResourceAsString

      protected String getClassResourceAsString(String relativeName)
      Returns a class resource as a String.

      The absolute name of the class resource is of the following form:

      /modifiedPackageName/className/relativeName
      Where the modifiedPackageName is the package name of this object with '/' substituted for '.'.
      Parameters:
      relativeName - The relative name of the resource.
      Returns:
      The resource as a String.
      Throws:
      MissingResourceException - If the resource was not found.