oh-my-promptfoo 1.20.2-next.99 → 1.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -582,10 +582,10 @@ var import_promises2 = require("fs/promises");
582
582
  var import_node_os2 = require("os");
583
583
  var import_node_path2 = require("path");
584
584
 
585
- // node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/index.js
585
+ // node_modules/.bun/diff@9.0.0/node_modules/diff/libesm/index.js
586
586
  init_cjs_shims();
587
587
 
588
- // node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/base.js
588
+ // node_modules/.bun/diff@9.0.0/node_modules/diff/libesm/diff/base.js
589
589
  init_cjs_shims();
590
590
  var Diff = class {
591
591
  diff(oldStr, newStr, options = {}) {
@@ -788,7 +788,7 @@ var Diff = class {
788
788
  }
789
789
  };
790
790
 
791
- // node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/diff/line.js
791
+ // node_modules/.bun/diff@9.0.0/node_modules/diff/libesm/diff/line.js
792
792
  init_cjs_shims();
793
793
  var LineDiff = class extends Diff {
794
794
  constructor() {
@@ -837,8 +837,53 @@ function tokenize(value, options) {
837
837
  return retLines;
838
838
  }
839
839
 
840
- // node_modules/.bun/diff@8.0.3/node_modules/diff/libesm/patch/create.js
840
+ // node_modules/.bun/diff@9.0.0/node_modules/diff/libesm/patch/create.js
841
841
  init_cjs_shims();
842
+ function needsQuoting(s) {
843
+ for (let i = 0; i < s.length; i++) {
844
+ if (s[i] < " " || s[i] > "~" || s[i] === '"' || s[i] === "\\") {
845
+ return true;
846
+ }
847
+ }
848
+ return false;
849
+ }
850
+ function quoteFileNameIfNeeded(s) {
851
+ if (!needsQuoting(s)) {
852
+ return s;
853
+ }
854
+ let result = '"';
855
+ const bytes = new TextEncoder().encode(s);
856
+ let i = 0;
857
+ while (i < bytes.length) {
858
+ const b = bytes[i];
859
+ if (b === 7) {
860
+ result += "\\a";
861
+ } else if (b === 8) {
862
+ result += "\\b";
863
+ } else if (b === 9) {
864
+ result += "\\t";
865
+ } else if (b === 10) {
866
+ result += "\\n";
867
+ } else if (b === 11) {
868
+ result += "\\v";
869
+ } else if (b === 12) {
870
+ result += "\\f";
871
+ } else if (b === 13) {
872
+ result += "\\r";
873
+ } else if (b === 34) {
874
+ result += '\\"';
875
+ } else if (b === 92) {
876
+ result += "\\\\";
877
+ } else if (b >= 32 && b <= 126) {
878
+ result += String.fromCharCode(b);
879
+ } else {
880
+ result += "\\" + b.toString(8).padStart(3, "0");
881
+ }
882
+ i++;
883
+ }
884
+ result += '"';
885
+ return result;
886
+ }
842
887
  var INCLUDE_HEADERS = {
843
888
  includeIndex: true,
844
889
  includeUnderline: true,
@@ -951,35 +996,69 @@ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, ne
951
996
  }
952
997
  }
953
998
  function formatPatch(patch, headerOptions) {
999
+ var _a, _b, _c, _d, _e, _f;
954
1000
  if (!headerOptions) {
955
1001
  headerOptions = INCLUDE_HEADERS;
956
1002
  }
957
1003
  if (Array.isArray(patch)) {
958
- if (patch.length > 1 && !headerOptions.includeFileHeaders) {
1004
+ if (patch.length > 1 && !headerOptions.includeFileHeaders && !patch.every((p) => p.isGit)) {
959
1005
  throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");
960
1006
  }
961
1007
  return patch.map((p) => formatPatch(p, headerOptions)).join("\n");
962
1008
  }
963
1009
  const ret = [];
964
- if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName) {
965
- ret.push("Index: " + patch.oldFileName);
966
- }
967
- if (headerOptions.includeUnderline) {
968
- ret.push("===================================================================");
1010
+ if (patch.isGit) {
1011
+ headerOptions = INCLUDE_HEADERS;
1012
+ if (!patch.oldFileName) {
1013
+ throw new Error("oldFileName must be specified for Git patches");
1014
+ }
1015
+ if (!patch.newFileName) {
1016
+ throw new Error("newFileName must be specified for Git patches");
1017
+ }
1018
+ let gitOldName = patch.oldFileName;
1019
+ let gitNewName = patch.newFileName;
1020
+ if (patch.isCreate && gitOldName === "/dev/null") {
1021
+ gitOldName = gitNewName.replace(/^b\//, "a/");
1022
+ } else if (patch.isDelete && gitNewName === "/dev/null") {
1023
+ gitNewName = gitOldName.replace(/^a\//, "b/");
1024
+ }
1025
+ ret.push("diff --git " + quoteFileNameIfNeeded(gitOldName) + " " + quoteFileNameIfNeeded(gitNewName));
1026
+ if (patch.isDelete) {
1027
+ ret.push("deleted file mode " + ((_a = patch.oldMode) !== null && _a !== void 0 ? _a : "100644"));
1028
+ }
1029
+ if (patch.isCreate) {
1030
+ ret.push("new file mode " + ((_b = patch.newMode) !== null && _b !== void 0 ? _b : "100644"));
1031
+ }
1032
+ if (patch.oldMode && patch.newMode && !patch.isDelete && !patch.isCreate) {
1033
+ ret.push("old mode " + patch.oldMode);
1034
+ ret.push("new mode " + patch.newMode);
1035
+ }
1036
+ if (patch.isRename) {
1037
+ ret.push("rename from " + quoteFileNameIfNeeded(((_c = patch.oldFileName) !== null && _c !== void 0 ? _c : "").replace(/^a\//, "")));
1038
+ ret.push("rename to " + quoteFileNameIfNeeded(((_d = patch.newFileName) !== null && _d !== void 0 ? _d : "").replace(/^b\//, "")));
1039
+ }
1040
+ if (patch.isCopy) {
1041
+ ret.push("copy from " + quoteFileNameIfNeeded(((_e = patch.oldFileName) !== null && _e !== void 0 ? _e : "").replace(/^a\//, "")));
1042
+ ret.push("copy to " + quoteFileNameIfNeeded(((_f = patch.newFileName) !== null && _f !== void 0 ? _f : "").replace(/^b\//, "")));
1043
+ }
1044
+ } else {
1045
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName && patch.oldFileName !== void 0) {
1046
+ ret.push("Index: " + patch.oldFileName);
1047
+ }
1048
+ if (headerOptions.includeUnderline) {
1049
+ ret.push("===================================================================");
1050
+ }
969
1051
  }
970
- if (headerOptions.includeFileHeaders) {
971
- ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
972
- ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
1052
+ const hasHunks = patch.hunks.length > 0;
1053
+ if (headerOptions.includeFileHeaders && patch.oldFileName !== void 0 && patch.newFileName !== void 0 && (!patch.isGit || hasHunks)) {
1054
+ ret.push("--- " + quoteFileNameIfNeeded(patch.oldFileName) + (patch.oldHeader ? " " + patch.oldHeader : ""));
1055
+ ret.push("+++ " + quoteFileNameIfNeeded(patch.newFileName) + (patch.newHeader ? " " + patch.newHeader : ""));
973
1056
  }
974
1057
  for (let i = 0; i < patch.hunks.length; i++) {
975
1058
  const hunk = patch.hunks[i];
976
- if (hunk.oldLines === 0) {
977
- hunk.oldStart -= 1;
978
- }
979
- if (hunk.newLines === 0) {
980
- hunk.newStart -= 1;
981
- }
982
- ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
1059
+ const oldStart = hunk.oldLines === 0 ? hunk.oldStart - 1 : hunk.oldStart;
1060
+ const newStart = hunk.newLines === 0 ? hunk.newStart - 1 : hunk.newStart;
1061
+ ret.push("@@ -" + oldStart + "," + hunk.oldLines + " +" + newStart + "," + hunk.newLines + " @@");
983
1062
  for (const line of hunk.lines) {
984
1063
  ret.push(line);
985
1064
  }