assertUsageArtifactHygiene function

void assertUsageArtifactHygiene(
  1. String artifact, {
  2. Iterable<String> forbiddenSecrets = const [],
  3. Iterable<String> forbiddenContent = const [],
})

Asserts that artifact contains none of forbiddenSecrets (configured keys/tokens) and none of forbiddenContent (prompt-content substrings from the session).

Empty needles are ignored. Throws UsageHygieneException on the first hit.

Implementation

void assertUsageArtifactHygiene(
  String artifact, {
  Iterable<String> forbiddenSecrets = const [],
  Iterable<String> forbiddenContent = const [],
}) {
  for (final needle in forbiddenSecrets) {
    if (needle.isEmpty) continue;
    final offset = artifact.indexOf(needle);
    if (offset >= 0) {
      throw UsageHygieneException(offset: offset, length: needle.length);
    }
  }
  for (final needle in forbiddenContent) {
    if (needle.length < 8) continue;
    final offset = artifact.indexOf(needle);
    if (offset >= 0) {
      throw UsageHygieneException(offset: offset, length: needle.length);
    }
  }
}