@tangle-network/agent-eval 0.58.1 → 0.59.0
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/{chunk-5GLYP2IQ.js → chunk-PIEAE33T.js} +71 -2
- package/dist/chunk-PIEAE33T.js.map +1 -0
- package/dist/chunk-ZWEQJIM6.js +220 -0
- package/dist/chunk-ZWEQJIM6.js.map +1 -0
- package/dist/contract/index.d.ts +2 -2
- package/dist/contract/index.js +18 -3
- package/dist/contract/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -104
- package/dist/index.js.map +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{registry-BSWy0rvH.d.ts → registry-DK9kqXvb.d.ts} +1 -1
- package/dist/{store-CJbzDxZ2.d.ts → store-jzKpMl16.d.ts} +28 -0
- package/dist/traces.d.ts +2 -2
- package/dist/traces.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5GLYP2IQ.js.map +0 -1
- package/dist/chunk-SHTXZ4O2.js +0 -113
- package/dist/chunk-SHTXZ4O2.js.map +0 -1
package/dist/chunk-SHTXZ4O2.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
llmSpans
|
|
3
|
-
} from "./chunk-47X6LRCE.js";
|
|
4
|
-
|
|
5
|
-
// src/contamination-guard.ts
|
|
6
|
-
function checkCanaries(output, scenarios) {
|
|
7
|
-
const leaks = [];
|
|
8
|
-
for (const s of scenarios) {
|
|
9
|
-
if (!s.canary) continue;
|
|
10
|
-
if (output.includes(s.canary)) {
|
|
11
|
-
leaks.push({ scenarioId: s.id, canary: s.canary, evidence: excerpt(output, s.canary) });
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return leaks;
|
|
15
|
-
}
|
|
16
|
-
function checkBehavioralCanary(output, scenario) {
|
|
17
|
-
const pattern = scenario.forbiddenPattern ?? scenario.canary;
|
|
18
|
-
if (!pattern) return null;
|
|
19
|
-
const hit = matchForbidden(output, pattern);
|
|
20
|
-
if (!hit) return null;
|
|
21
|
-
return {
|
|
22
|
-
scenarioId: scenario.id,
|
|
23
|
-
canary: pattern,
|
|
24
|
-
evidence: excerpt(output, hit)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function runBehavioralCanaries(cases) {
|
|
28
|
-
const leaks = [];
|
|
29
|
-
for (const c of cases) {
|
|
30
|
-
const leak = checkBehavioralCanary(c.output, c.scenario);
|
|
31
|
-
if (leak) leaks.push({ ...leak, runId: c.runId ?? leak.runId });
|
|
32
|
-
}
|
|
33
|
-
return leaks;
|
|
34
|
-
}
|
|
35
|
-
function matchForbidden(output, pattern) {
|
|
36
|
-
const re = tryParseRegex(pattern);
|
|
37
|
-
if (re) {
|
|
38
|
-
const m = output.match(re);
|
|
39
|
-
return m && m[0].length > 0 ? m[0] : null;
|
|
40
|
-
}
|
|
41
|
-
return output.includes(pattern) ? pattern : null;
|
|
42
|
-
}
|
|
43
|
-
function tryParseRegex(pattern) {
|
|
44
|
-
if (pattern.length < 2 || pattern[0] !== "/") return null;
|
|
45
|
-
const last = pattern.lastIndexOf("/");
|
|
46
|
-
if (last <= 0) return null;
|
|
47
|
-
const body = pattern.slice(1, last);
|
|
48
|
-
const flags = pattern.slice(last + 1);
|
|
49
|
-
if (!/^[gimsuy]*$/.test(flags)) return null;
|
|
50
|
-
try {
|
|
51
|
-
return new RegExp(body, flags);
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function canaryLeakView(store, scenarios) {
|
|
57
|
-
const targets = scenarios.filter((s) => !!s.canary);
|
|
58
|
-
if (targets.length === 0) return [];
|
|
59
|
-
const spans = await llmSpans(store);
|
|
60
|
-
const leaks = [];
|
|
61
|
-
for (const span of spans) {
|
|
62
|
-
const output = span.output ?? "";
|
|
63
|
-
for (const s of targets) {
|
|
64
|
-
if (s.canary && output.includes(s.canary)) {
|
|
65
|
-
leaks.push({
|
|
66
|
-
scenarioId: s.id,
|
|
67
|
-
canary: s.canary,
|
|
68
|
-
runId: span.runId,
|
|
69
|
-
evidence: excerpt(output, s.canary)
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return leaks;
|
|
75
|
-
}
|
|
76
|
-
var HoldoutAuditor = class {
|
|
77
|
-
scenarios;
|
|
78
|
-
accessLog = [];
|
|
79
|
-
constructor(scenarios) {
|
|
80
|
-
this.scenarios = scenarios;
|
|
81
|
-
}
|
|
82
|
-
/** Retrieve a holdout scenario for a declared purpose. Non-'evaluation' throws. */
|
|
83
|
-
get(scenarioId, purpose) {
|
|
84
|
-
if (purpose !== "evaluation" && purpose !== "debugging") {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`HoldoutAuditor.get: purpose must be 'evaluation' or 'debugging', got ${purpose}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
const s = this.scenarios.find((x) => x.id === scenarioId);
|
|
90
|
-
if (!s) throw new Error(`holdout scenario "${scenarioId}" not found`);
|
|
91
|
-
this.accessLog.push({ scenarioId, purpose, at: Date.now() });
|
|
92
|
-
return s;
|
|
93
|
-
}
|
|
94
|
-
getAccessLog() {
|
|
95
|
-
return this.accessLog;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
function excerpt(source, needle) {
|
|
99
|
-
const at = source.indexOf(needle);
|
|
100
|
-
if (at < 0) return "";
|
|
101
|
-
const start = Math.max(0, at - 30);
|
|
102
|
-
const end = Math.min(source.length, at + needle.length + 30);
|
|
103
|
-
return (start > 0 ? "\u2026" : "") + source.slice(start, end) + (end < source.length ? "\u2026" : "");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export {
|
|
107
|
-
checkCanaries,
|
|
108
|
-
checkBehavioralCanary,
|
|
109
|
-
runBehavioralCanaries,
|
|
110
|
-
canaryLeakView,
|
|
111
|
-
HoldoutAuditor
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=chunk-SHTXZ4O2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contamination-guard.ts"],"sourcesContent":["/**\n * ContaminationGuard — ensures held-out scenarios don't leak into\n * training/prompt paths, and flags model memorization.\n *\n * Three probes:\n * 1. `checkCanaries(output, scenario)` — if the scenario carries a\n * canary token, it MUST NOT appear in the agent's output.\n * Canaries are strings that are statistically impossible to\n * reconstruct from the scenario description alone — so if they\n * echo back, the model memorized them.\n * 2. `canaryLeakView(store)` — cross-corpus view of every run whose\n * output contained a canary, with the offending scenario + run.\n * 3. `HoldoutAuditor` — wraps a Dataset and emits a structured error\n * on any code path that reads holdout scenarios but doesn't flag\n * `purpose: 'evaluation'`. Keeps engineers honest.\n */\n\nimport type { DatasetScenario } from './dataset'\nimport { llmSpans } from './trace/query'\nimport type { TraceStore } from './trace/store'\n\nexport interface CanaryLeak {\n scenarioId: string\n canary: string\n runId?: string\n evidence: string\n}\n\nexport function checkCanaries(output: string, scenarios: DatasetScenario[]): CanaryLeak[] {\n const leaks: CanaryLeak[] = []\n for (const s of scenarios) {\n if (!s.canary) continue\n if (output.includes(s.canary)) {\n leaks.push({ scenarioId: s.id, canary: s.canary, evidence: excerpt(output, s.canary) })\n }\n }\n return leaks\n}\n\n/**\n * Behavioral canary: tests the AGENT, not the eval grep.\n *\n * - `forbiddenPattern` PRESENT in output ⇒ AGENT EMITTED BAD CONTENT ⇒ LEAK.\n * - `forbiddenPattern` ABSENT from output ⇒ AGENT HELD THE LINE ⇒ PASS.\n *\n * Use when running known-bad-prompt scenarios against the agent under\n * test and you want to know if the agent misbehaved. The classical\n * {@link checkCanaries} / {@link import('./canary').runCanaries | runCanaries}\n * test whether the eval check fires when the bad output is forced\n * into the eval flow — different question, different answer.\n *\n * Pattern resolution order (first match wins):\n * 1. `scenario.forbiddenPattern` — if it parses as `/body/flags`,\n * treated as a regex; otherwise a literal substring.\n * 2. `scenario.canary` — literal substring fallback so the helper\n * works on existing scenario fixtures.\n *\n * Returns `null` when nothing forbidden was found OR the scenario\n * declared no pattern.\n */\nexport function checkBehavioralCanary(\n output: string,\n scenario: DatasetScenario,\n): CanaryLeak | null {\n const pattern = scenario.forbiddenPattern ?? scenario.canary\n if (!pattern) return null\n const hit = matchForbidden(output, pattern)\n if (!hit) return null\n return {\n scenarioId: scenario.id,\n canary: pattern,\n evidence: excerpt(output, hit),\n }\n}\n\n/**\n * Behavioral canary over many (scenario, output) pairs. Sibling to\n * {@link import('./canary').runCanaries | runCanaries} — same idea\n * (run-many → report) but the question being answered is \"did the\n * AGENT misbehave?\" rather than \"did the EVAL grep fire?\".\n *\n * Returns one `CanaryLeak` per pair where the agent's output\n * contained its scenario's `forbiddenPattern` (or `canary` fallback).\n */\nexport function runBehavioralCanaries(\n cases: Array<{ scenario: DatasetScenario; output: string; runId?: string }>,\n): CanaryLeak[] {\n const leaks: CanaryLeak[] = []\n for (const c of cases) {\n const leak = checkBehavioralCanary(c.output, c.scenario)\n if (leak) leaks.push({ ...leak, runId: c.runId ?? leak.runId })\n }\n return leaks\n}\n\n/**\n * Resolve a forbidden-pattern string to the matched substring inside\n * `output`. `/body/flags` notation is interpreted as a regex; anything\n * else is a literal substring.\n */\nfunction matchForbidden(output: string, pattern: string): string | null {\n const re = tryParseRegex(pattern)\n if (re) {\n const m = output.match(re)\n return m && m[0].length > 0 ? m[0] : null\n }\n return output.includes(pattern) ? pattern : null\n}\n\nfunction tryParseRegex(pattern: string): RegExp | null {\n if (pattern.length < 2 || pattern[0] !== '/') return null\n const last = pattern.lastIndexOf('/')\n if (last <= 0) return null\n const body = pattern.slice(1, last)\n const flags = pattern.slice(last + 1)\n if (!/^[gimsuy]*$/.test(flags)) return null\n try {\n return new RegExp(body, flags)\n } catch {\n return null\n }\n}\n\n/**\n * Scan the LLM-output history in a corpus; returns every case where a\n * canary from a known scenario appeared in agent output. Pass the full\n * set of scenarios whose canaries you care about (typically the whole\n * held-out slice).\n */\nexport async function canaryLeakView(\n store: TraceStore,\n scenarios: DatasetScenario[],\n): Promise<CanaryLeak[]> {\n const targets = scenarios.filter((s) => !!s.canary)\n if (targets.length === 0) return []\n const spans = await llmSpans(store)\n const leaks: CanaryLeak[] = []\n for (const span of spans) {\n const output = span.output ?? ''\n for (const s of targets) {\n if (s.canary && output.includes(s.canary)) {\n leaks.push({\n scenarioId: s.id,\n canary: s.canary,\n runId: span.runId,\n evidence: excerpt(output, s.canary),\n })\n }\n }\n }\n return leaks\n}\n\nexport class HoldoutAuditor {\n private scenarios: DatasetScenario[]\n private accessLog: Array<{ scenarioId: string; purpose: string; at: number }> = []\n\n constructor(scenarios: DatasetScenario[]) {\n this.scenarios = scenarios\n }\n\n /** Retrieve a holdout scenario for a declared purpose. Non-'evaluation' throws. */\n get(scenarioId: string, purpose: 'evaluation' | 'debugging'): DatasetScenario {\n if (purpose !== 'evaluation' && purpose !== 'debugging') {\n throw new Error(\n `HoldoutAuditor.get: purpose must be 'evaluation' or 'debugging', got ${purpose}`,\n )\n }\n const s = this.scenarios.find((x) => x.id === scenarioId)\n if (!s) throw new Error(`holdout scenario \"${scenarioId}\" not found`)\n this.accessLog.push({ scenarioId, purpose, at: Date.now() })\n return s\n }\n\n getAccessLog(): ReadonlyArray<{ scenarioId: string; purpose: string; at: number }> {\n return this.accessLog\n }\n}\n\nfunction excerpt(source: string, needle: string): string {\n const at = source.indexOf(needle)\n if (at < 0) return ''\n const start = Math.max(0, at - 30)\n const end = Math.min(source.length, at + needle.length + 30)\n return (start > 0 ? '…' : '') + source.slice(start, end) + (end < source.length ? '…' : '')\n}\n"],"mappings":";;;;;AA4BO,SAAS,cAAc,QAAgB,WAA4C;AACxF,QAAM,QAAsB,CAAC;AAC7B,aAAW,KAAK,WAAW;AACzB,QAAI,CAAC,EAAE,OAAQ;AACf,QAAI,OAAO,SAAS,EAAE,MAAM,GAAG;AAC7B,YAAM,KAAK,EAAE,YAAY,EAAE,IAAI,QAAQ,EAAE,QAAQ,UAAU,QAAQ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