<commit_before>(function(){
  'use strict';
  const hostName = "com.theironyard.newlinecli.hw";
  let connection;
  let pendingPromises = [];

  function connect() {
    console.log("Connecting to native messaging host", hostName);
    connection = chrome.runtime.connectNative(hostName);
    connection.onMessage.addListener(onNativeMessage);
    connection.onDisconnect.addListener(onDisconnected);
  }

  function onNativeMessage(msg) {
    console.log("Message from host", msg);
    if (msg.message_at) {
      let findByMessageId = function (el) { return msg.message_at === el.message_at; };
      let itemInQueue = pendingPromises.find(findByMessageId);
      let itemIndex = pendingPromises.findIndex(findByMessageId);
      if (itemInQueue) {

        if (msg.status === "ok") {
          itemInQueue.resolve(msg);
        } else  {
          itemInQueue.reject(msg);
        }

        itemInQueue.complete = true;
        pendingPromises.splice(itemIndex, 1);
      }
    }
  }

  function sendNativeMessage(event, data) {
    if (!connection) {
      connect();
    }
    const at = Date.now();
    let resolve;
    let reject;

    let promise  = new Promise(function (res, rej){
      const payload = { event: event, message_at: at,  data: data };
      console.log("Sending Data to NewlineHW", payload);
      connection.postMessage(payload);
      resolve = res;
      reject = rej;
    });

    let item = {<commit_msg>Log if message is sent with improper structure.<commit_after>(function(){
  'use strict';
  const hostName = "com.theironyard.newlinecli.hw";
  let connection;
  let pendingPromises = [];

  function connect() {
    console.log("Connecting to native messaging host", hostName);
    connection = chrome.runtime.connectNative(hostName);
    connection.onMessage.addListener(onNativeMessage);
    connection.onDisconnect.addListener(onDisconnected);
  }

  function onNativeMessage(msg) {
    console.log("Message from host", msg);
    if (msg.message_at) {
      let findByMessageId = function (el) { return msg.message_at === el.message_at; };
      let itemInQueue = pendingPromises.find(findByMessageId);
      let itemIndex = pendingPromises.findIndex(findByMessageId);
      if (itemInQueue) {

        if (msg.status === "ok") {
          itemInQueue.resolve(msg);
        } else  {
          itemInQueue.reject(msg);
        }

        itemInQueue.complete = true;
        pendingPromises.splice(itemIndex, 1);
      } else {
        console.error("Message does not have a message_at. callback cannot be completed");
      }
    }
  }

  function sendNativeMessage(event, data) {
    if (!connection) {
      connect();
    }
    const at = Date.now();
    let resolve;
    let reject;

    let promise  = new Promise(function (res, rej){
      const payload = { event: event, message_at: at,  data: data };
      console.log("Sending Data to NewlineHW", payload);
      connection.postMessage(payload);
      resolve = res;
      reject = rej;
    });

    let item = {
{'fraction_non_alphanumeric': 0.11827242524916944, 'fraction_numerical': 0.000664451827242525, 'mean_word_length': 2.8901808785529717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6579352', 'n_tokens_mistral': 902, 'n_tokens_neox': 880, 'n_words': 207}