<commit_before>part of polymorphic.utils;

typedef void Action();

void debug(Action action) {
  if (DEBUG) {
    action();
  }
}

final bool DEBUG = (() {
  if (Zone.current["debug"] == true) {
    return true;
  }
  
  try {
    assert(false);
  } on AssertionError catch (e) {
    return true;
  }
  return false;
})();

class EnvironmentUtils {
  static const List<String> _compiledHints = const [
    "class DefaultEquality implements Equality {", // from collection package
    "abstract class _UnorderedEquality<E, T extends Iterable<E>> implements Equality<T> {", // from collection package
    "class ScalarEvent extends _ValueEvent {" // from yaml package
  ];
  
  /**
   * Attempts to determine if the root script of this isolate
   * is likely compiled with some sort of tool.
   * 
   * [uncompiledMaxLines] is the maximum number of lines of the root script that you expect when it is not compiled.
   * [compiledLineIndex] is the index of a line in the compiled output that has a large width.
   * [compiledLineWidth] is the minimum length of the line at [compiledLineIndex] that we expect.
   */
  static bool isCompiled({int uncompiledMaxLines: 1000, int compiledLineIndex: 0, int compiledLineWidth: 5000}) {
    var script = Platform.script;
    
    if (script == null || script.scheme != "file") {
      return false;
    }
    
    var file = new File.fromUri(script);
    var lines = file.readAsLinesSync();
    var content = lines.join("\n");
    
    // These are almost always present in some way.
    if (_compiledHints.every((hint) => content.contains(hint))) {
      return true;
    }
    
    return lines.length > uncompiledMaxLines || lines[compiledLineIndex].length >= compiledLineWidth;
  }
  
  static bool isLikelyPlugin() {
    try {
      currentMirrorSystem().findLibrary(#polymorphic.bot);<commit_msg>Work on EnvironmentUtils<commit_after>part of polymorphic.utils;

typedef void Action();

void debug(Action action) {
  if (DEBUG) {
    action();
  }
}

bool get DEBUG {
  if (Zone.current["debug"] == true) {
    return true;
  }
  
  try {
    assert(false);
  } on AssertionError catch (e) {
    return true;
  }
  
  return false;
}

/**
 * Information about the current environment.
 */
class EnvironmentUtils {
  /**
   * Detects when the current isolate has been compiled by a compiler.
   */
  static bool isCompiled() {
    return new bool.fromEnvironment("compiled", defaultValue: false);
  }
  
  /**
   * Detects when the current isolate is more than likely a plugin.
   */
  static bool isPlugin() {
    try {
      currentMirrorSystem().findLibrary(#polymorphic.bot);
{'fraction_non_alphanumeric': 0.10755148741418764, 'fraction_numerical': 0.003432494279176201, 'mean_word_length': 3.137223974763407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7022715', 'n_tokens_mistral': 803, 'n_tokens_neox': 761, 'n_words': 255}