Class PromptGuard

java.lang.Object
io.github.jbastgen.stemma.app.ai.PromptGuard

public final class PromptGuard extends Object
What stands between the repository and an AI service: text that goes out is cleaned of obvious secrets and cut to the configured size, and files that must never be sent can be recognised. This is a safety net, not a guarantee: it finds the usual token formats and password = … lines, not every secret there is.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    The outgoing text and what was done to it.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(String text, boolean redact, int maxChars)
    Cleans text (if redact) and cuts it to maxChars.
    static boolean
    binary(byte[] content)
    Binary content is never sent.
    static boolean
    excluded(String path, List<String> patterns)
    Whether a file must not be sent: its path or its name matches one of the glob patterns (* any characters except /, ** any characters, ? one character; a pattern without / is compared with the file name only).

    Methods inherited from class java.lang.Object

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

    • apply

      public static PromptGuard.Guarded apply(String text, boolean redact, int maxChars)
      Cleans text (if redact) and cuts it to maxChars.
    • excluded

      public static boolean excluded(String path, List<String> patterns)
      Whether a file must not be sent: its path or its name matches one of the glob patterns (* any characters except /, ** any characters, ? one character; a pattern without / is compared with the file name only). Case-insensitive.
    • binary

      public static boolean binary(byte[] content)
      Binary content is never sent.