oh-my-promptfoo 1.34.2 → 1.34.3
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/assertions.cjs +66 -14
- package/dist/assertions.cjs.map +1 -1
- package/dist/assertions.js +66 -15
- package/dist/assertions.js.map +1 -1
- package/dist/delegate-runner.js +26 -15
- package/dist/delegate-runner.js.map +1 -1
- package/dist/providers.js +1 -1
- package/package.json +1 -1
package/dist/assertions.cjs
CHANGED
|
@@ -8,6 +8,7 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
8
8
|
let node_os = require("node:os");
|
|
9
9
|
let node_module = require("node:module");
|
|
10
10
|
let node_util = require("node:util");
|
|
11
|
+
require("node:crypto");
|
|
11
12
|
// packages/oh-my-promptfoo/src/rubric-contract.ts
|
|
12
13
|
const PROMPTFOO_TEMPLATE_SLOT = /\{\{-?\s*(output|rubric)\b/;
|
|
13
14
|
let templateEngine;
|
|
@@ -1048,6 +1049,15 @@ function withAssertions(configuration) {
|
|
|
1048
1049
|
return result;
|
|
1049
1050
|
}
|
|
1050
1051
|
// packages/oh-my-promptfoo/src/shell-selector.ts
|
|
1052
|
+
const descriptorRedirects = /* @__PURE__ */ new Set([">&", "<&"]);
|
|
1053
|
+
const redirects = /* @__PURE__ */ new Set([
|
|
1054
|
+
">",
|
|
1055
|
+
">>",
|
|
1056
|
+
"<",
|
|
1057
|
+
"&>",
|
|
1058
|
+
"&>>",
|
|
1059
|
+
...descriptorRedirects
|
|
1060
|
+
]);
|
|
1051
1061
|
function tokens(source) {
|
|
1052
1062
|
const result = [];
|
|
1053
1063
|
let word = "", active = false, quote = "", unquoted = true, assignment = false;
|
|
@@ -1113,9 +1123,15 @@ function tokens(source) {
|
|
|
1113
1123
|
].includes(c)) {
|
|
1114
1124
|
op += c;
|
|
1115
1125
|
i++;
|
|
1116
|
-
}
|
|
1117
|
-
if (
|
|
1118
|
-
|
|
1126
|
+
} else if (source[i + 1] === "&" && (c === ">" || c === "<")) op += source[++i];
|
|
1127
|
+
else if (c === "&" && source[i + 1] === ">") {
|
|
1128
|
+
op += source[++i];
|
|
1129
|
+
if (source[i + 1] === ">") op += source[++i];
|
|
1130
|
+
} else if (c === "|" && source[i + 1] === "&") i++;
|
|
1131
|
+
if (op === "&" || op === "<<") throw new Error("Background commands and heredocs are not supported");
|
|
1132
|
+
const previous = result.at(-1);
|
|
1133
|
+
const isRedirectTarget = previous && "op" in previous && redirects.has(previous.op);
|
|
1134
|
+
if (redirects.has(op) && !op.startsWith("&") && !isRedirectTarget && unquoted && /^\d+$/.test(word)) {
|
|
1119
1135
|
word = "";
|
|
1120
1136
|
active = false;
|
|
1121
1137
|
}
|
|
@@ -1140,9 +1156,9 @@ const reserved = /^(?:if|then|else|elif|fi|for|while|until|do|done|case|esac|fun
|
|
|
1140
1156
|
const executionBuiltins = /^(?:eval|source|\.|builtin|trap|alias|unalias|enable|hash|bind|fc)$/;
|
|
1141
1157
|
/**
|
|
1142
1158
|
* Static simple-command subset, not a shell interpreter. Supports quotes/escapes,
|
|
1143
|
-
* leading assignments,
|
|
1144
|
-
* exec [--]. Expansions, control groups, backgrounding,
|
|
1145
|
-
*
|
|
1159
|
+
* leading assignments, file and literal descriptor redirects, pipes/lists,
|
|
1160
|
+
* command [-p] [--] and exec [--]. Expansions, control groups, backgrounding,
|
|
1161
|
+
* heredocs and unmodeled execution/resolution-changing builtins fail closed.
|
|
1146
1162
|
* External wrappers, interpreters and scripts are not recursively interpreted.
|
|
1147
1163
|
*/
|
|
1148
1164
|
function parseShell(source, { stopAfterExec = false } = {}) {
|
|
@@ -1191,12 +1207,10 @@ function parseShell(source, { stopAfterExec = false } = {}) {
|
|
|
1191
1207
|
requiresCommand = false;
|
|
1192
1208
|
continue;
|
|
1193
1209
|
}
|
|
1194
|
-
if (
|
|
1195
|
-
|
|
1196
|
-
"
|
|
1197
|
-
"
|
|
1198
|
-
].includes(token.op)) {
|
|
1199
|
-
if (!input[i + 1] || !("word" in input[i + 1])) throw new Error("Shell redirection requires a target");
|
|
1210
|
+
if (redirects.has(token.op)) {
|
|
1211
|
+
const target = input[i + 1];
|
|
1212
|
+
if (!target || !("word" in target)) throw new Error("Shell redirection requires a target");
|
|
1213
|
+
if (descriptorRedirects.has(token.op) && !/^(?:\d+|-)$/.test(target.word)) throw new Error("Shell descriptor redirection requires a literal descriptor or '-'");
|
|
1200
1214
|
i++;
|
|
1201
1215
|
continue;
|
|
1202
1216
|
}
|
|
@@ -1252,6 +1266,43 @@ function shellMatcher(value) {
|
|
|
1252
1266
|
return !regex || regex([command.program, ...command.args].join(" "));
|
|
1253
1267
|
};
|
|
1254
1268
|
}
|
|
1269
|
+
// packages/oh-my-promptfoo/src/skill-evidence.ts
|
|
1270
|
+
function literalWords(command, powershell) {
|
|
1271
|
+
if (/[\r\n\0$`;&|<>()[\]{}*?#!,]/.test(command) || !powershell && command.includes("\\")) return;
|
|
1272
|
+
if (powershell && /[‘’“”]/.test(command)) return;
|
|
1273
|
+
const words = [];
|
|
1274
|
+
let rest = command.trim();
|
|
1275
|
+
while (rest) {
|
|
1276
|
+
const match = /^(?:"([^"]*)"|'([^']*)'|([^\s'"]+))(?=[ \t]|$)/.exec(rest);
|
|
1277
|
+
if (!match) return;
|
|
1278
|
+
if (powershell && (match[1] ?? match[2])?.startsWith("-")) return;
|
|
1279
|
+
words.push(match[1] ?? match[2] ?? match[3]);
|
|
1280
|
+
if (words.length > 8) return;
|
|
1281
|
+
rest = rest.slice(match[0].length).replace(/^[ \t]+/, "");
|
|
1282
|
+
}
|
|
1283
|
+
return words;
|
|
1284
|
+
}
|
|
1285
|
+
function literalPowerShellReadPath(command) {
|
|
1286
|
+
if (command.length > 8192 || !/^get-content[ \t]/i.test(command.trim())) return;
|
|
1287
|
+
const words = literalWords(command, true);
|
|
1288
|
+
if (!words) return;
|
|
1289
|
+
let path;
|
|
1290
|
+
let raw = false;
|
|
1291
|
+
for (let i = 1; i < words.length; i++) {
|
|
1292
|
+
const word = words[i];
|
|
1293
|
+
const option = word.toLowerCase();
|
|
1294
|
+
if (option === "-raw" && !raw) {
|
|
1295
|
+
raw = true;
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
if (path) return;
|
|
1299
|
+
const operand = option === "-path" || option === "-literalpath" ? words[++i] : word;
|
|
1300
|
+
if (!operand || /^[-@~–—―]/.test(operand)) return;
|
|
1301
|
+
if (operand.replace(/^[A-Za-z]:[\\/]/, "").includes(":")) return;
|
|
1302
|
+
path = operand;
|
|
1303
|
+
}
|
|
1304
|
+
return path;
|
|
1305
|
+
}
|
|
1255
1306
|
// packages/oh-my-promptfoo/src/tool-assertions.ts
|
|
1256
1307
|
function error(reason) {
|
|
1257
1308
|
return {
|
|
@@ -1437,11 +1488,12 @@ function fileRead(_output, context) {
|
|
|
1437
1488
|
const { path, command } = args;
|
|
1438
1489
|
const direct = filesystemReadTools.has(call.name) && typeof path === "string" && (0, node_path.basename)(path) === filename;
|
|
1439
1490
|
const shell = call.name === "bash" && typeof command === "string" && bashReadsFile(command, filename);
|
|
1440
|
-
|
|
1491
|
+
const powerShellPath = call.name === "powershell" && typeof command === "string" ? literalPowerShellReadPath(command) : void 0;
|
|
1492
|
+
if (!direct && !shell && (!powerShellPath || node_path.win32.basename(powerShellPath) !== filename)) continue;
|
|
1441
1493
|
return {
|
|
1442
1494
|
pass: true,
|
|
1443
1495
|
score: 1,
|
|
1444
|
-
reason:
|
|
1496
|
+
reason: shell ? `Successful Bash call contained a cat read of ${filename}` : `Read ${filename}`,
|
|
1445
1497
|
tokensUsed: { ...noGraderUsage },
|
|
1446
1498
|
metadata: { matchedCallIds: [call.id] }
|
|
1447
1499
|
};
|