@ancha-labs/cli 0.4.31 → 0.4.32
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/lib/ancha.mjs +193 -49
- package/lib/assets/SKILL.md +10 -9
- package/lib/assets/agents-section.md +10 -9
- package/lib/assets/docs/cloud.md +10 -9
- package/lib/assets/docs/scenes.md +13 -1
- package/lib/assets/docs/setup.md +10 -9
- package/lib/assets/harbor/companion.mjs +108 -6
- package/lib/assets/ui/app.js +6 -2
- package/lib/mcp-entry.mjs +8 -1
- package/lib/worker.mjs +110 -8
- package/lib/world-server.mjs +108 -6
- package/package.json +1 -1
package/lib/worker.mjs
CHANGED
|
@@ -20705,6 +20705,9 @@ var init_zod = __esm({
|
|
|
20705
20705
|
|
|
20706
20706
|
// packages/core/src/answer.ts
|
|
20707
20707
|
function readNumbers(text26) {
|
|
20708
|
+
return readNumberSpans(text26).map(({ start: _start, end: _end, ...number7 }) => number7);
|
|
20709
|
+
}
|
|
20710
|
+
function readNumberSpans(text26) {
|
|
20708
20711
|
const numbers2 = [];
|
|
20709
20712
|
for (const match3 of text26.normalize("NFKC").matchAll(NUMBER)) {
|
|
20710
20713
|
const { open: open4, sign: sign3, before, minus, inner, digits, after, close } = match3.groups;
|
|
@@ -20713,6 +20716,8 @@ function readNumbers(text26) {
|
|
|
20713
20716
|
const negative = sign3 !== void 0 && sign3 !== "+" || minus !== void 0 || parenthesized && amount4;
|
|
20714
20717
|
const value4 = Number(digits.replaceAll(",", ""));
|
|
20715
20718
|
numbers2.push({
|
|
20719
|
+
start: match3.index,
|
|
20720
|
+
end: match3.index + match3[0].length,
|
|
20716
20721
|
value: negative && value4 !== 0 ? -value4 : value4,
|
|
20717
20722
|
decimals: digits.split(".")[1]?.length ?? 0,
|
|
20718
20723
|
text: match3[0].trim(),
|
|
@@ -20744,6 +20749,93 @@ function expectedNumber(number7) {
|
|
|
20744
20749
|
const read6 = typeof number7.value === "number" ? { value: number7.value, decimals: decimalsOf(number7.value) } : readNumbers(number7.value)[0];
|
|
20745
20750
|
return { value: read6.value, tolerance: number7.tolerance ?? 0.5 * 10 ** -read6.decimals };
|
|
20746
20751
|
}
|
|
20752
|
+
function answerTokens(text26) {
|
|
20753
|
+
const tokens4 = [];
|
|
20754
|
+
let cursor4 = 0;
|
|
20755
|
+
const quotes = [];
|
|
20756
|
+
const gap8 = (end) => {
|
|
20757
|
+
for (const match3 of text26.slice(cursor4, end).matchAll(/[\p{L}\p{M}]+|[^\s]/gu)) {
|
|
20758
|
+
const start2 = cursor4 + match3.index, word = match3[0];
|
|
20759
|
+
const apostrophe = (word === "'" || word === "\u2019") && (WORD_CHAR.test(text26[start2 - 1] ?? "") && (WORD_CHAR.test(text26[start2 + 1] ?? "") || quotes.at(-1) !== word) || text26[start2 - 1] === "." && /^s\b/i.test(text26.slice(start2 + 1)));
|
|
20760
|
+
const quote2 = !apostrophe && ['"', "'", "\u201C", "\u201D", "\u2018", "\u2019"].includes(word);
|
|
20761
|
+
tokens4.push({ text: word.toLowerCase(), start: start2, end: start2 + word.length, quoted: quotes.length > 0 || quote2 });
|
|
20762
|
+
if (quote2) {
|
|
20763
|
+
if (quotes.at(-1) === word) quotes.pop();
|
|
20764
|
+
else if (word !== "\u201D" && word !== "\u2019") quotes.push(word === "\u201C" ? "\u201D" : word === "\u2018" ? "\u2019" : word);
|
|
20765
|
+
}
|
|
20766
|
+
}
|
|
20767
|
+
};
|
|
20768
|
+
for (const number7 of readNumberSpans(text26)) {
|
|
20769
|
+
gap8(number7.start);
|
|
20770
|
+
tokens4.push({ text: number7.text, start: number7.start, end: number7.end, number: number7, quoted: quotes.length > 0 });
|
|
20771
|
+
cursor4 = number7.end;
|
|
20772
|
+
}
|
|
20773
|
+
gap8(text26.length);
|
|
20774
|
+
return tokens4;
|
|
20775
|
+
}
|
|
20776
|
+
function distinctLabels(labels2) {
|
|
20777
|
+
return labels2.every((label7, i) => labels2.every((other, j) => i === j || !labelPattern(label7).test(other)));
|
|
20778
|
+
}
|
|
20779
|
+
function fieldRows(text26) {
|
|
20780
|
+
return text26.split("\n").map((line2) => {
|
|
20781
|
+
const lead = /^\s*\|?/.exec(line2)[0].length, end = line2.length - /\|?\s*$/.exec(line2)[0].length;
|
|
20782
|
+
const inner = line2.slice(lead, end), at4 = inner.indexOf("|");
|
|
20783
|
+
if (at4 < 0 || inner.includes("|", at4 + 1) || !inner.slice(0, at4).trim() || !inner.slice(at4 + 1).trim() || /^[\s:-]+$/.test(inner.replace("|", ""))) return line2;
|
|
20784
|
+
return `${line2.slice(0, lead + at4)}:${line2.slice(lead + at4 + 1)}`;
|
|
20785
|
+
}).join("\n");
|
|
20786
|
+
}
|
|
20787
|
+
function readLabelEvidence(text26, labels2) {
|
|
20788
|
+
text26 = fieldRows(text26.normalize("NFKC"));
|
|
20789
|
+
const tokens4 = answerTokens(text26);
|
|
20790
|
+
const occurrences2 = labels2.flatMap((label7) => [...text26.matchAll(labelPattern(normalizedLabel(label7)))].map((match3) => ({ label: label7, start: match3.index, end: match3.index + match3[0].length }))).sort((a, b) => a.start - b.start);
|
|
20791
|
+
const evidence2 = [];
|
|
20792
|
+
occurrences2.forEach((occurrence, index) => {
|
|
20793
|
+
const next2 = occurrences2[index + 1]?.start ?? text26.length;
|
|
20794
|
+
const after = tokens4.filter((token4) => token4.start >= occurrence.end && token4.start < next2);
|
|
20795
|
+
const clause2 = [];
|
|
20796
|
+
let previous = occurrence.end;
|
|
20797
|
+
for (const token4 of after) {
|
|
20798
|
+
if (/[\r\n]/.test(text26.slice(previous, token4.start)) || !token4.number && (/^[.!?;,|]$/.test(token4.text) || CLAUSE_WORDS.has(token4.text))) break;
|
|
20799
|
+
clause2.push(token4);
|
|
20800
|
+
previous = token4.end;
|
|
20801
|
+
}
|
|
20802
|
+
let links3 = 0;
|
|
20803
|
+
for (let i = 0; i < clause2.length; i++) {
|
|
20804
|
+
const token4 = clause2[i];
|
|
20805
|
+
if (token4.number) {
|
|
20806
|
+
evidence2.push({
|
|
20807
|
+
label: occurrence.label,
|
|
20808
|
+
number: token4.number,
|
|
20809
|
+
clauseNumbers: clause2.flatMap((t) => t.number ? [t.number] : []),
|
|
20810
|
+
quoted: token4.quoted || tokens4.some((t) => t.start >= occurrence.start && t.start < occurrence.end && t.quoted)
|
|
20811
|
+
});
|
|
20812
|
+
break;
|
|
20813
|
+
}
|
|
20814
|
+
if (CURRENCY_TOKEN.test(token4.text) || /^[*_]$/.test(token4.text)) continue;
|
|
20815
|
+
if (token4.text === "stands" && clause2[i + 1]?.text === "at" || ["comes", "came"].includes(token4.text) && clause2[i + 1]?.text === "to") i++;
|
|
20816
|
+
else if (!LINK_WORDS.has(token4.text) && token4.text !== ":" && token4.text !== "=") break;
|
|
20817
|
+
if (++links3 > 3) break;
|
|
20818
|
+
}
|
|
20819
|
+
});
|
|
20820
|
+
return evidence2;
|
|
20821
|
+
}
|
|
20822
|
+
function swappedAnswerNumbers(text26, numbers2) {
|
|
20823
|
+
const labelled = numbers2.filter((n2) => n2.label !== void 0);
|
|
20824
|
+
if (labelled.length < 2 || !distinctLabels(labelled.map((n2) => normalizedLabel(n2.label)))) return [];
|
|
20825
|
+
const evidence2 = readLabelEvidence(text26, labelled.map((n2) => n2.label));
|
|
20826
|
+
const matches10 = (actual, expected) => {
|
|
20827
|
+
const { value: value4, tolerance } = expectedNumber(expected);
|
|
20828
|
+
return numberMatches(actual, value4, tolerance);
|
|
20829
|
+
};
|
|
20830
|
+
return labelled.flatMap((expected) => {
|
|
20831
|
+
if (evidence2.some((e) => e.label === expected.label && matches10(e.number, expected))) return [];
|
|
20832
|
+
return labelled.flatMap((under) => {
|
|
20833
|
+
if (under === expected || matches10({ value: expectedNumber(under).value, decimals: 0, text: "" }, expected) || matches10({ value: expectedNumber(expected).value, decimals: 0, text: "" }, under)) return [];
|
|
20834
|
+
const wrong = evidence2.find((e) => e.label === under.label && !e.quoted && matches10(e.number, expected) && !matches10(e.number, under) && !e.clauseNumbers.some((n2) => n2.start !== e.number.start && numbers2.some((want) => matches10(n2, want))));
|
|
20835
|
+
return wrong ? [{ expected, under, stated: wrong.number }] : [];
|
|
20836
|
+
});
|
|
20837
|
+
});
|
|
20838
|
+
}
|
|
20747
20839
|
function decimalsOf(value4) {
|
|
20748
20840
|
const [mantissa, exponent] = String(Math.abs(value4)).split("e");
|
|
20749
20841
|
return Math.max(0, (mantissa.split(".")[1]?.length ?? 0) - Number(exponent ?? 0));
|
|
@@ -20752,7 +20844,7 @@ function comparableText(text26, sensitive = false) {
|
|
|
20752
20844
|
const plain4 = text26.normalize("NFKC").replace(/[‘’‛′]/g, "'").replace(/[“”„″]/g, '"').replace(/[‐‑‒–—−]/g, "-").replace(/\s+/g, " ").trim();
|
|
20753
20845
|
return sensitive ? plain4 : plain4.toLowerCase();
|
|
20754
20846
|
}
|
|
20755
|
-
var SYMBOLS, CODES, CURRENCY, NUMBER, AnswerNumberSchema, texts, AnswerRowSchema, AnswerRowsSchema, AnswerCheckSchema;
|
|
20847
|
+
var SYMBOLS, CODES, CURRENCY, NUMBER, AnswerNumberSchema, texts, AnswerRowSchema, AnswerRowsSchema, AnswerCheckSchema, LINK_WORDS, CLAUSE_WORDS, CURRENCY_TOKEN, WORD_CHAR, escapeRegex2, labelPattern, normalizedLabel;
|
|
20756
20848
|
var init_answer = __esm({
|
|
20757
20849
|
"packages/core/src/answer.ts"() {
|
|
20758
20850
|
"use strict";
|
|
@@ -20820,7 +20912,8 @@ var init_answer = __esm({
|
|
|
20820
20912
|
);
|
|
20821
20913
|
AnswerNumberSchema = external_exports.strictObject({
|
|
20822
20914
|
value: external_exports.union([external_exports.number(), external_exports.string().refine((text26) => readNumbers(text26).length === 1, 'a number, or one number written as text, e.g. "1,240.00" or "(300.00)"')]).describe('The number the answer must state: a number, or one number as text ("1,240.00") to keep its decimal places'),
|
|
20823
|
-
tolerance: external_exports.number().nonnegative().optional().describe("How far the stated number may be from value; default: half the last decimal place of value (1200.00 \u2192 0.005, 1240.5 \u2192 0.05, 1200 \u2192 0.5)")
|
|
20915
|
+
tolerance: external_exports.number().nonnegative().optional().describe("How far the stated number may be from value; default: half the last decimal place of value (1200.00 \u2192 0.005, 1240.5 \u2192 0.05, 1200 \u2192 0.5)"),
|
|
20916
|
+
label: external_exports.string().trim().min(1).max(40).optional().describe("The name of this number, such as balance or credit limit; detects expected values stated under another label")
|
|
20824
20917
|
});
|
|
20825
20918
|
texts = external_exports.union([external_exports.string().min(1), external_exports.array(external_exports.string().min(1)).min(1)]);
|
|
20826
20919
|
AnswerRowSchema = external_exports.record(external_exports.string().min(1), external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean(), external_exports.null()])).superRefine((row2, ctx) => {
|
|
@@ -20850,6 +20943,13 @@ var init_answer = __esm({
|
|
|
20850
20943
|
if (check3[key4] !== void 0) ctx.addIssue({ code: "custom", path: [key4], message: `rows is mutually exclusive with ${key4}` });
|
|
20851
20944
|
}
|
|
20852
20945
|
}).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or what it prints on stdout): text and numbers, or exact structured rows");
|
|
20946
|
+
LINK_WORDS = /* @__PURE__ */ new Set(["is", "was", "are", "were", "of", "at", "to", "totals"]);
|
|
20947
|
+
CLAUSE_WORDS = /* @__PURE__ */ new Set(["and", "but", "while", "whereas", "with"]);
|
|
20948
|
+
CURRENCY_TOKEN = new RegExp(`^(?:${CURRENCY})$`, "iu");
|
|
20949
|
+
WORD_CHAR = /[\p{L}\p{N}_]/u;
|
|
20950
|
+
escapeRegex2 = (text26) => text26.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
20951
|
+
labelPattern = (label7) => new RegExp(`(?<![\\p{L}\\p{N}_])${escapeRegex2(label7)}(?![\\p{L}\\p{N}_])`, "giu");
|
|
20952
|
+
normalizedLabel = (label7) => label7.normalize("NFKC").toLowerCase();
|
|
20853
20953
|
}
|
|
20854
20954
|
});
|
|
20855
20955
|
|
|
@@ -87174,10 +87274,10 @@ function evaluateAnswerRows(check3, answer) {
|
|
|
87174
87274
|
function evaluateAnswer(check3, trace) {
|
|
87175
87275
|
if (check3.rows !== void 0) return evaluateAnswerRows(check3.rows, finalAnswer(trace));
|
|
87176
87276
|
const contains3 = asList(check3.contains), absent = asList(check3.not_contains), sensitive = check3.case === "sensitive";
|
|
87177
|
-
const numbers2 = (check3.numbers ?? []).map((number7) => ({ ...expectedNumber(number7), written: typeof number7.value === "string" ? number7.value : plainNumber(number7.value) }));
|
|
87277
|
+
const numbers2 = (check3.numbers ?? []).map((number7) => ({ ...expectedNumber(number7), label: number7.label, written: typeof number7.value === "string" ? number7.value : plainNumber(number7.value) }));
|
|
87178
87278
|
const parts3 = [
|
|
87179
87279
|
...contains3.length ? [`contains ${quoted2(contains3)}`] : [],
|
|
87180
|
-
...numbers2.length ? [`states ${numbers2.map((n2) => `${n2.written} (\xB1${plainNumber(n2.tolerance)})`).join(", ")}`] : [],
|
|
87280
|
+
...numbers2.length ? [`states ${numbers2.map((n2) => `${n2.written} (${n2.label ? `${n2.label}, ` : ""}\xB1${plainNumber(n2.tolerance)})`).join(", ")}`] : [],
|
|
87181
87281
|
...absent.length ? [`does not contain ${quoted2(absent)}`] : []
|
|
87182
87282
|
];
|
|
87183
87283
|
const expected = parts3.length ? `the final answer ${parts3.join("; ")}` : "a final answer";
|
|
@@ -87205,9 +87305,10 @@ function evaluateAnswer(check3, trace) {
|
|
|
87205
87305
|
const missing7 = contains3.filter((piece2) => !text26.includes(comparableText(piece2, sensitive)));
|
|
87206
87306
|
const unstated = numbers2.filter((n2) => !stated.some((number7) => numberMatches(number7, n2.value, n2.tolerance)));
|
|
87207
87307
|
const present2 = absent.filter((piece2) => text26.includes(comparableText(piece2, sensitive)));
|
|
87308
|
+
const swaps = swappedAnswerNumbers(answer.text, check3.numbers ?? []);
|
|
87208
87309
|
const line2 = answer.text.replace(/\s+/g, " ").trim();
|
|
87209
87310
|
const actual = `"${line2.length > ANSWER_QUOTE ? `${line2.slice(0, ANSWER_QUOTE - 1)}\u2026` : line2}"`;
|
|
87210
|
-
if (!missing7.length && !unstated.length && !present2.length) {
|
|
87311
|
+
if (!missing7.length && !unstated.length && !present2.length && !swaps.length) {
|
|
87211
87312
|
return { passed: true, expected, actual, explanation: parts3.length ? "The final answer states everything the check asks for." : "The agent gave a final answer.", evidence: [answer.seq] };
|
|
87212
87313
|
}
|
|
87213
87314
|
const said = stated.length ? `the numbers it states are ${list3(stated.map((number7) => number7.text))}` : "it states no numbers";
|
|
@@ -87215,6 +87316,7 @@ function evaluateAnswer(check3, trace) {
|
|
|
87215
87316
|
...missing7.length ? [`The final answer does not contain ${quoted2(missing7)}.`] : [],
|
|
87216
87317
|
...unstated.length ? [`It states no number within ${unstated.map((n2) => `${plainNumber(n2.tolerance)} of ${n2.written}`).join(", nor within ")}: ${said}.`] : [],
|
|
87217
87318
|
...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : [],
|
|
87319
|
+
...swaps.map((swap) => `It states ${swap.stated.text} after \u201C${swap.under.label}\u201D, but the expected \u201C${swap.under.label}\u201D is ${typeof swap.under.value === "string" ? swap.under.value : plainNumber(swap.under.value)} and ${typeof swap.expected.value === "string" ? swap.expected.value : plainNumber(swap.expected.value)} is the expected \u201C${swap.expected.label}\u201D.`),
|
|
87218
87320
|
...answer.source === "stdout" ? ["Its answer is everything it printed on stdout."] : answer.source === "reply" ? ["Its answer is its HTTP reply."] : []
|
|
87219
87321
|
].join(" ");
|
|
87220
87322
|
return { passed: false, expected, actual, explanation, evidence: [answer.seq] };
|
|
@@ -170499,7 +170601,7 @@ function dateModel(model) {
|
|
|
170499
170601
|
function parseDate2(value4, model) {
|
|
170500
170602
|
const parts3 = dateModel(model), tokens4 = [];
|
|
170501
170603
|
const pattern = parts3.map((p2) => {
|
|
170502
|
-
if (!p2.token) return
|
|
170604
|
+
if (!p2.token) return escapeRegex3(p2.literal);
|
|
170503
170605
|
if (p2.token === "FM") return "";
|
|
170504
170606
|
tokens4.push(p2.token);
|
|
170505
170607
|
return p2.token === "YYYY" ? "(\\d{4})" : ["MON", "MONTH"].includes(p2.token) ? "([A-Za-z]+)" : ["AM", "PM"].includes(p2.token) ? "(AM|PM)" : "(\\d{1,2})";
|
|
@@ -171070,7 +171172,7 @@ function scan(db3, query10, page18, opts) {
|
|
|
171070
171172
|
throw error64;
|
|
171071
171173
|
}
|
|
171072
171174
|
}
|
|
171073
|
-
var SuiteqlError, SuiteqlResultSizeError, MAX_TOKENS, MAX_NODES, MAX_DEPTH2, MAX_JOINS, MAX_RESULTS, RESERVED, Parser, subqueryOf, isRownum, quote, param3, key3, numeric3, dated2, textLiteral, family, commonType, direction, JOINS, SET_OPERATORS, AGGREGATES2, RANKING, MATH, ARITIES, OTHER_FUNCTIONS, Compiler, pad2, MONTHS2,
|
|
171175
|
+
var SuiteqlError, SuiteqlResultSizeError, MAX_TOKENS, MAX_NODES, MAX_DEPTH2, MAX_JOINS, MAX_RESULTS, RESERVED, Parser, subqueryOf, isRownum, quote, param3, key3, numeric3, dated2, textLiteral, family, commonType, direction, JOINS, SET_OPERATORS, AGGREGATES2, RANKING, MATH, ARITIES, OTHER_FUNCTIONS, Compiler, pad2, MONTHS2, escapeRegex3, str3, num3, textOrNull, finite2, outOfRange, timestamp3, sameShape2, DAYS2, POSIX, nth;
|
|
171074
171176
|
var init_suiteql = __esm({
|
|
171075
171177
|
"packages/server/src/twins/netsuite/suiteql.ts"() {
|
|
171076
171178
|
"use strict";
|
|
@@ -172106,7 +172208,7 @@ var init_suiteql = __esm({
|
|
|
172106
172208
|
};
|
|
172107
172209
|
pad2 = (n2, width = 2) => String(n2).padStart(width, "0");
|
|
172108
172210
|
MONTHS2 = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
172109
|
-
|
|
172211
|
+
escapeRegex3 = (s2) => s2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
172110
172212
|
str3 = (v) => typeof v === "number" ? cleanNumber(v) : String(v);
|
|
172111
172213
|
num3 = (v) => numericValue(v);
|
|
172112
172214
|
textOrNull = (s2) => s2 === "" ? null : s2;
|
package/lib/world-server.mjs
CHANGED
|
@@ -92054,6 +92054,9 @@ var NUMBER = new RegExp(
|
|
|
92054
92054
|
"gu"
|
|
92055
92055
|
);
|
|
92056
92056
|
function readNumbers(text25) {
|
|
92057
|
+
return readNumberSpans(text25).map(({ start: _start, end: _end, ...number7 }) => number7);
|
|
92058
|
+
}
|
|
92059
|
+
function readNumberSpans(text25) {
|
|
92057
92060
|
const numbers2 = [];
|
|
92058
92061
|
for (const match3 of text25.normalize("NFKC").matchAll(NUMBER)) {
|
|
92059
92062
|
const { open: open2, sign: sign3, before, minus, inner, digits, after, close } = match3.groups;
|
|
@@ -92062,6 +92065,8 @@ function readNumbers(text25) {
|
|
|
92062
92065
|
const negative = sign3 !== void 0 && sign3 !== "+" || minus !== void 0 || parenthesized && amount4;
|
|
92063
92066
|
const value4 = Number(digits.replaceAll(",", ""));
|
|
92064
92067
|
numbers2.push({
|
|
92068
|
+
start: match3.index,
|
|
92069
|
+
end: match3.index + match3[0].length,
|
|
92065
92070
|
value: negative && value4 !== 0 ? -value4 : value4,
|
|
92066
92071
|
decimals: digits.split(".")[1]?.length ?? 0,
|
|
92067
92072
|
text: match3[0].trim(),
|
|
@@ -92091,7 +92096,8 @@ ${text25}` : `${key4}: ${text25}`).join("\n");
|
|
|
92091
92096
|
}
|
|
92092
92097
|
var AnswerNumberSchema = external_exports.strictObject({
|
|
92093
92098
|
value: external_exports.union([external_exports.number(), external_exports.string().refine((text25) => readNumbers(text25).length === 1, 'a number, or one number written as text, e.g. "1,240.00" or "(300.00)"')]).describe('The number the answer must state: a number, or one number as text ("1,240.00") to keep its decimal places'),
|
|
92094
|
-
tolerance: external_exports.number().nonnegative().optional().describe("How far the stated number may be from value; default: half the last decimal place of value (1200.00 \u2192 0.005, 1240.5 \u2192 0.05, 1200 \u2192 0.5)")
|
|
92099
|
+
tolerance: external_exports.number().nonnegative().optional().describe("How far the stated number may be from value; default: half the last decimal place of value (1200.00 \u2192 0.005, 1240.5 \u2192 0.05, 1200 \u2192 0.5)"),
|
|
92100
|
+
label: external_exports.string().trim().min(1).max(40).optional().describe("The name of this number, such as balance or credit limit; detects expected values stated under another label")
|
|
92095
92101
|
});
|
|
92096
92102
|
var texts = external_exports.union([external_exports.string().min(1), external_exports.array(external_exports.string().min(1)).min(1)]);
|
|
92097
92103
|
var AnswerRowSchema = external_exports.record(external_exports.string().min(1), external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean(), external_exports.null()])).superRefine((row2, ctx) => {
|
|
@@ -92125,6 +92131,100 @@ function expectedNumber(number7) {
|
|
|
92125
92131
|
const read6 = typeof number7.value === "number" ? { value: number7.value, decimals: decimalsOf(number7.value) } : readNumbers(number7.value)[0];
|
|
92126
92132
|
return { value: read6.value, tolerance: number7.tolerance ?? 0.5 * 10 ** -read6.decimals };
|
|
92127
92133
|
}
|
|
92134
|
+
var LINK_WORDS = /* @__PURE__ */ new Set(["is", "was", "are", "were", "of", "at", "to", "totals"]);
|
|
92135
|
+
var CLAUSE_WORDS = /* @__PURE__ */ new Set(["and", "but", "while", "whereas", "with"]);
|
|
92136
|
+
var CURRENCY_TOKEN = new RegExp(`^(?:${CURRENCY})$`, "iu");
|
|
92137
|
+
var WORD_CHAR = /[\p{L}\p{N}_]/u;
|
|
92138
|
+
function answerTokens(text25) {
|
|
92139
|
+
const tokens4 = [];
|
|
92140
|
+
let cursor4 = 0;
|
|
92141
|
+
const quotes = [];
|
|
92142
|
+
const gap8 = (end) => {
|
|
92143
|
+
for (const match3 of text25.slice(cursor4, end).matchAll(/[\p{L}\p{M}]+|[^\s]/gu)) {
|
|
92144
|
+
const start2 = cursor4 + match3.index, word = match3[0];
|
|
92145
|
+
const apostrophe = (word === "'" || word === "\u2019") && (WORD_CHAR.test(text25[start2 - 1] ?? "") && (WORD_CHAR.test(text25[start2 + 1] ?? "") || quotes.at(-1) !== word) || text25[start2 - 1] === "." && /^s\b/i.test(text25.slice(start2 + 1)));
|
|
92146
|
+
const quote2 = !apostrophe && ['"', "'", "\u201C", "\u201D", "\u2018", "\u2019"].includes(word);
|
|
92147
|
+
tokens4.push({ text: word.toLowerCase(), start: start2, end: start2 + word.length, quoted: quotes.length > 0 || quote2 });
|
|
92148
|
+
if (quote2) {
|
|
92149
|
+
if (quotes.at(-1) === word) quotes.pop();
|
|
92150
|
+
else if (word !== "\u201D" && word !== "\u2019") quotes.push(word === "\u201C" ? "\u201D" : word === "\u2018" ? "\u2019" : word);
|
|
92151
|
+
}
|
|
92152
|
+
}
|
|
92153
|
+
};
|
|
92154
|
+
for (const number7 of readNumberSpans(text25)) {
|
|
92155
|
+
gap8(number7.start);
|
|
92156
|
+
tokens4.push({ text: number7.text, start: number7.start, end: number7.end, number: number7, quoted: quotes.length > 0 });
|
|
92157
|
+
cursor4 = number7.end;
|
|
92158
|
+
}
|
|
92159
|
+
gap8(text25.length);
|
|
92160
|
+
return tokens4;
|
|
92161
|
+
}
|
|
92162
|
+
var escapeRegex2 = (text25) => text25.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
92163
|
+
var labelPattern = (label7) => new RegExp(`(?<![\\p{L}\\p{N}_])${escapeRegex2(label7)}(?![\\p{L}\\p{N}_])`, "giu");
|
|
92164
|
+
var normalizedLabel = (label7) => label7.normalize("NFKC").toLowerCase();
|
|
92165
|
+
function distinctLabels(labels2) {
|
|
92166
|
+
return labels2.every((label7, i) => labels2.every((other, j) => i === j || !labelPattern(label7).test(other)));
|
|
92167
|
+
}
|
|
92168
|
+
function fieldRows(text25) {
|
|
92169
|
+
return text25.split("\n").map((line2) => {
|
|
92170
|
+
const lead = /^\s*\|?/.exec(line2)[0].length, end = line2.length - /\|?\s*$/.exec(line2)[0].length;
|
|
92171
|
+
const inner = line2.slice(lead, end), at4 = inner.indexOf("|");
|
|
92172
|
+
if (at4 < 0 || inner.includes("|", at4 + 1) || !inner.slice(0, at4).trim() || !inner.slice(at4 + 1).trim() || /^[\s:-]+$/.test(inner.replace("|", ""))) return line2;
|
|
92173
|
+
return `${line2.slice(0, lead + at4)}:${line2.slice(lead + at4 + 1)}`;
|
|
92174
|
+
}).join("\n");
|
|
92175
|
+
}
|
|
92176
|
+
function readLabelEvidence(text25, labels2) {
|
|
92177
|
+
text25 = fieldRows(text25.normalize("NFKC"));
|
|
92178
|
+
const tokens4 = answerTokens(text25);
|
|
92179
|
+
const occurrences2 = labels2.flatMap((label7) => [...text25.matchAll(labelPattern(normalizedLabel(label7)))].map((match3) => ({ label: label7, start: match3.index, end: match3.index + match3[0].length }))).sort((a, b) => a.start - b.start);
|
|
92180
|
+
const evidence2 = [];
|
|
92181
|
+
occurrences2.forEach((occurrence, index) => {
|
|
92182
|
+
const next2 = occurrences2[index + 1]?.start ?? text25.length;
|
|
92183
|
+
const after = tokens4.filter((token4) => token4.start >= occurrence.end && token4.start < next2);
|
|
92184
|
+
const clause2 = [];
|
|
92185
|
+
let previous = occurrence.end;
|
|
92186
|
+
for (const token4 of after) {
|
|
92187
|
+
if (/[\r\n]/.test(text25.slice(previous, token4.start)) || !token4.number && (/^[.!?;,|]$/.test(token4.text) || CLAUSE_WORDS.has(token4.text))) break;
|
|
92188
|
+
clause2.push(token4);
|
|
92189
|
+
previous = token4.end;
|
|
92190
|
+
}
|
|
92191
|
+
let links3 = 0;
|
|
92192
|
+
for (let i = 0; i < clause2.length; i++) {
|
|
92193
|
+
const token4 = clause2[i];
|
|
92194
|
+
if (token4.number) {
|
|
92195
|
+
evidence2.push({
|
|
92196
|
+
label: occurrence.label,
|
|
92197
|
+
number: token4.number,
|
|
92198
|
+
clauseNumbers: clause2.flatMap((t) => t.number ? [t.number] : []),
|
|
92199
|
+
quoted: token4.quoted || tokens4.some((t) => t.start >= occurrence.start && t.start < occurrence.end && t.quoted)
|
|
92200
|
+
});
|
|
92201
|
+
break;
|
|
92202
|
+
}
|
|
92203
|
+
if (CURRENCY_TOKEN.test(token4.text) || /^[*_]$/.test(token4.text)) continue;
|
|
92204
|
+
if (token4.text === "stands" && clause2[i + 1]?.text === "at" || ["comes", "came"].includes(token4.text) && clause2[i + 1]?.text === "to") i++;
|
|
92205
|
+
else if (!LINK_WORDS.has(token4.text) && token4.text !== ":" && token4.text !== "=") break;
|
|
92206
|
+
if (++links3 > 3) break;
|
|
92207
|
+
}
|
|
92208
|
+
});
|
|
92209
|
+
return evidence2;
|
|
92210
|
+
}
|
|
92211
|
+
function swappedAnswerNumbers(text25, numbers2) {
|
|
92212
|
+
const labelled = numbers2.filter((n2) => n2.label !== void 0);
|
|
92213
|
+
if (labelled.length < 2 || !distinctLabels(labelled.map((n2) => normalizedLabel(n2.label)))) return [];
|
|
92214
|
+
const evidence2 = readLabelEvidence(text25, labelled.map((n2) => n2.label));
|
|
92215
|
+
const matches10 = (actual, expected) => {
|
|
92216
|
+
const { value: value4, tolerance } = expectedNumber(expected);
|
|
92217
|
+
return numberMatches(actual, value4, tolerance);
|
|
92218
|
+
};
|
|
92219
|
+
return labelled.flatMap((expected) => {
|
|
92220
|
+
if (evidence2.some((e) => e.label === expected.label && matches10(e.number, expected))) return [];
|
|
92221
|
+
return labelled.flatMap((under) => {
|
|
92222
|
+
if (under === expected || matches10({ value: expectedNumber(under).value, decimals: 0, text: "" }, expected) || matches10({ value: expectedNumber(expected).value, decimals: 0, text: "" }, under)) return [];
|
|
92223
|
+
const wrong = evidence2.find((e) => e.label === under.label && !e.quoted && matches10(e.number, expected) && !matches10(e.number, under) && !e.clauseNumbers.some((n2) => n2.start !== e.number.start && numbers2.some((want) => matches10(n2, want))));
|
|
92224
|
+
return wrong ? [{ expected, under, stated: wrong.number }] : [];
|
|
92225
|
+
});
|
|
92226
|
+
});
|
|
92227
|
+
}
|
|
92128
92228
|
function decimalsOf(value4) {
|
|
92129
92229
|
const [mantissa, exponent] = String(Math.abs(value4)).split("e");
|
|
92130
92230
|
return Math.max(0, (mantissa.split(".")[1]?.length ?? 0) - Number(exponent ?? 0));
|
|
@@ -111169,10 +111269,10 @@ function evaluateAnswerRows(check3, answer) {
|
|
|
111169
111269
|
function evaluateAnswer(check3, trace) {
|
|
111170
111270
|
if (check3.rows !== void 0) return evaluateAnswerRows(check3.rows, finalAnswer(trace));
|
|
111171
111271
|
const contains3 = asList(check3.contains), absent = asList(check3.not_contains), sensitive = check3.case === "sensitive";
|
|
111172
|
-
const numbers2 = (check3.numbers ?? []).map((number7) => ({ ...expectedNumber(number7), written: typeof number7.value === "string" ? number7.value : plainNumber(number7.value) }));
|
|
111272
|
+
const numbers2 = (check3.numbers ?? []).map((number7) => ({ ...expectedNumber(number7), label: number7.label, written: typeof number7.value === "string" ? number7.value : plainNumber(number7.value) }));
|
|
111173
111273
|
const parts3 = [
|
|
111174
111274
|
...contains3.length ? [`contains ${quoted2(contains3)}`] : [],
|
|
111175
|
-
...numbers2.length ? [`states ${numbers2.map((n2) => `${n2.written} (\xB1${plainNumber(n2.tolerance)})`).join(", ")}`] : [],
|
|
111275
|
+
...numbers2.length ? [`states ${numbers2.map((n2) => `${n2.written} (${n2.label ? `${n2.label}, ` : ""}\xB1${plainNumber(n2.tolerance)})`).join(", ")}`] : [],
|
|
111176
111276
|
...absent.length ? [`does not contain ${quoted2(absent)}`] : []
|
|
111177
111277
|
];
|
|
111178
111278
|
const expected = parts3.length ? `the final answer ${parts3.join("; ")}` : "a final answer";
|
|
@@ -111200,9 +111300,10 @@ function evaluateAnswer(check3, trace) {
|
|
|
111200
111300
|
const missing7 = contains3.filter((piece2) => !text25.includes(comparableText(piece2, sensitive)));
|
|
111201
111301
|
const unstated = numbers2.filter((n2) => !stated.some((number7) => numberMatches(number7, n2.value, n2.tolerance)));
|
|
111202
111302
|
const present2 = absent.filter((piece2) => text25.includes(comparableText(piece2, sensitive)));
|
|
111303
|
+
const swaps = swappedAnswerNumbers(answer.text, check3.numbers ?? []);
|
|
111203
111304
|
const line2 = answer.text.replace(/\s+/g, " ").trim();
|
|
111204
111305
|
const actual = `"${line2.length > ANSWER_QUOTE ? `${line2.slice(0, ANSWER_QUOTE - 1)}\u2026` : line2}"`;
|
|
111205
|
-
if (!missing7.length && !unstated.length && !present2.length) {
|
|
111306
|
+
if (!missing7.length && !unstated.length && !present2.length && !swaps.length) {
|
|
111206
111307
|
return { passed: true, expected, actual, explanation: parts3.length ? "The final answer states everything the check asks for." : "The agent gave a final answer.", evidence: [answer.seq] };
|
|
111207
111308
|
}
|
|
111208
111309
|
const said = stated.length ? `the numbers it states are ${list3(stated.map((number7) => number7.text))}` : "it states no numbers";
|
|
@@ -111210,6 +111311,7 @@ function evaluateAnswer(check3, trace) {
|
|
|
111210
111311
|
...missing7.length ? [`The final answer does not contain ${quoted2(missing7)}.`] : [],
|
|
111211
111312
|
...unstated.length ? [`It states no number within ${unstated.map((n2) => `${plainNumber(n2.tolerance)} of ${n2.written}`).join(", nor within ")}: ${said}.`] : [],
|
|
111212
111313
|
...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : [],
|
|
111314
|
+
...swaps.map((swap) => `It states ${swap.stated.text} after \u201C${swap.under.label}\u201D, but the expected \u201C${swap.under.label}\u201D is ${typeof swap.under.value === "string" ? swap.under.value : plainNumber(swap.under.value)} and ${typeof swap.expected.value === "string" ? swap.expected.value : plainNumber(swap.expected.value)} is the expected \u201C${swap.expected.label}\u201D.`),
|
|
111213
111315
|
...answer.source === "stdout" ? ["Its answer is everything it printed on stdout."] : answer.source === "reply" ? ["Its answer is its HTTP reply."] : []
|
|
111214
111316
|
].join(" ");
|
|
111215
111317
|
return { passed: false, expected, actual, explanation, evidence: [answer.seq] };
|
|
@@ -167765,11 +167867,11 @@ function dateModel(model) {
|
|
|
167765
167867
|
}
|
|
167766
167868
|
return parts3;
|
|
167767
167869
|
}
|
|
167768
|
-
var
|
|
167870
|
+
var escapeRegex3 = (s2) => s2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
167769
167871
|
function parseDate2(value4, model) {
|
|
167770
167872
|
const parts3 = dateModel(model), tokens4 = [];
|
|
167771
167873
|
const pattern = parts3.map((p2) => {
|
|
167772
|
-
if (!p2.token) return
|
|
167874
|
+
if (!p2.token) return escapeRegex3(p2.literal);
|
|
167773
167875
|
if (p2.token === "FM") return "";
|
|
167774
167876
|
tokens4.push(p2.token);
|
|
167775
167877
|
return p2.token === "YYYY" ? "(\\d{4})" : ["MON", "MONTH"].includes(p2.token) ? "([A-Za-z]+)" : ["AM", "PM"].includes(p2.token) ? "(AM|PM)" : "(\\d{1,2})";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, each attempt on a fresh cloud machine in your app.ancha.io workspace, or on your computer.",
|
|
6
6
|
"bugs": {
|