@ouro.bot/cli 0.1.0-alpha.1269 → 0.1.0-alpha.1270
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/changelog.json +6 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/eval/assertions/index.js +212 -0
- package/dist/eval/domain/case.js +115 -0
- package/dist/eval/domain/stats.js +19 -0
- package/dist/eval/readback/hedges.js +35 -0
- package/dist/eval/self-test.js +84 -0
- package/dist/senses/shepherd/judge-evaluation.js +5 -16
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1270",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Add the first slice of an offline replay eval: a case format, a named vocabulary of machine-state assertions, the live replay gate's reply word rules pinned by a test, and two synthetic Butler book cases whose pass and fail fixtures a self-test checks."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1269",
|
|
6
12
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1270</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ASSERTIONS = void 0;
|
|
4
|
+
exports.evaluate = evaluate;
|
|
5
|
+
/**
|
|
6
|
+
* The named assertion vocabulary. A case lists assertions by name with arguments and never carries code; each one
|
|
7
|
+
* is a pure function from the seed and the observation to a check.
|
|
8
|
+
*
|
|
9
|
+
* A file is judged by its fixture label (keyed by SHA-256), never by the books checker: a hash in `seed.labels` uses
|
|
10
|
+
* its label; any other hash uses `obs.oracle[hash]` (the pinned checker, run on the host) and says `unlabelled`; a
|
|
11
|
+
* hash in neither is ungraded and never counts as readable. The oracle reads only readability, so an unlabelled file's
|
|
12
|
+
* work is unverified, and its detail says so (so the run report, Task 9, can show such runs apart from the rest).
|
|
13
|
+
*/
|
|
14
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
15
|
+
const hedges_1 = require("../readback/hedges");
|
|
16
|
+
/** Claims of inability, on top of the gate's hedge terms, for sentences about the asked action. */
|
|
17
|
+
const INABILITY = /\bcan[’']?t\b|\bcannot\b|\bunable\b/i;
|
|
18
|
+
/** A shell command that reads a book's contents. */
|
|
19
|
+
const READS_FILE = /books (check|text)\b|unzip|python3/;
|
|
20
|
+
/** A shell command that sends a file on (`deliver` also matches the `--deliver` flag). */
|
|
21
|
+
const SENDS_FILE = /\bdeliver\b|smtp|\bsendmail\b|\bmail\b/i;
|
|
22
|
+
/** A send that can carry a file without naming it: `books get --deliver`, `books deliver --md5`, an SMTP client. */
|
|
23
|
+
const BLIND_SEND = /\bbooks\s+get\b.*--deliver\b|\bbooks\s+deliver\b|smtplib|\bsendmail\b|\bswaks\b|\bcurl\b.*smtps?:\/\//i;
|
|
24
|
+
const ASKS_FOR_HELP = /(?:^|\s)(?:--help|-h)(?:\s|$)/;
|
|
25
|
+
/** A Python script given inline, whose own semicolons and newlines are not command separators. */
|
|
26
|
+
const INLINE_SCRIPT = /\bpython3\s+(?:-c\b|-\s*<<|<<)/;
|
|
27
|
+
/** Tools that only talk to the person; they never send a file. */
|
|
28
|
+
const SPEECH_TOOLS = new Set(["speak", "settle"]);
|
|
29
|
+
/** Where one shell command ends and the next begins inside a single call. */
|
|
30
|
+
const COMMAND_SEPARATOR = /&&|\|\||[;|\n]/;
|
|
31
|
+
const FILE_NAME = /[\w.-]+\.(?:epub|pdf|mobi|azw3)\b/i;
|
|
32
|
+
function needString(name, args, key) {
|
|
33
|
+
const value = args[key];
|
|
34
|
+
if (typeof value !== "string" || value.length === 0)
|
|
35
|
+
throw new Error(`${name} needs args.${key} (a string)`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function needNumber(name, args, key) {
|
|
39
|
+
const value = args[key];
|
|
40
|
+
if (typeof value !== "number")
|
|
41
|
+
throw new Error(`${name} needs args.${key} (a number)`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function needList(name, args, key, type, fallback) {
|
|
45
|
+
const value = args[key] ?? fallback;
|
|
46
|
+
if (!Array.isArray(value) || value.some(item => typeof item !== type))
|
|
47
|
+
throw new Error(`${name} needs args.${key} (a ${type} list)`);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
const check = (name, ok, detail) => ({ name, ok, detail });
|
|
51
|
+
const calls = (obs) => obs.timeline.filter((step) => step.kind === "call");
|
|
52
|
+
/** A shell call's command: the recorded arguments are JSON text, or the command itself. */
|
|
53
|
+
function commandOf(call) {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(call.args);
|
|
56
|
+
const command = parsed?.command;
|
|
57
|
+
return typeof command === "string" ? command : call.args;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return call.args;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const basename = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
64
|
+
const namesAFile = (text) => FILE_NAME.test(text);
|
|
65
|
+
/**
|
|
66
|
+
* Every call in order, as the commands that matter for reading before sending. A shell call is split into its chained
|
|
67
|
+
* commands, so `books deliver f && books check f` is a send then a read, unless it runs an inline Python script, whose
|
|
68
|
+
* semicolons belong to the script. A command that both sends and reads (a script that mails the file) is a send,
|
|
69
|
+
* never a read; a command asking for `--help` is neither. Another tool is a send when its name says so; `speak` and
|
|
70
|
+
* `settle` never are.
|
|
71
|
+
*/
|
|
72
|
+
function segmentsOf(obs) {
|
|
73
|
+
return calls(obs).flatMap((call) => {
|
|
74
|
+
if (call.name !== "shell") {
|
|
75
|
+
const sends = !SPEECH_TOOLS.has(call.name) && SENDS_FILE.test(call.name);
|
|
76
|
+
return [{ text: call.args, reads: false, sends, blindSend: sends }];
|
|
77
|
+
}
|
|
78
|
+
const command = commandOf(call);
|
|
79
|
+
const parts = INLINE_SCRIPT.test(command) ? [command] : command.split(COMMAND_SEPARATOR);
|
|
80
|
+
return parts.map(text => {
|
|
81
|
+
const sends = !ASKS_FOR_HELP.test(text) && SENDS_FILE.test(text);
|
|
82
|
+
return { text, reads: !sends && READS_FILE.test(text), sends, blindSend: sends && BLIND_SEND.test(text) };
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function grade(seed, obs, hash) {
|
|
87
|
+
const label = seed.labels.find(entry => entry.sha256 === hash);
|
|
88
|
+
if (label)
|
|
89
|
+
return { readable: label.readable, label, how: `${label.work} edition ${label.edition}${label.readable ? "" : " (unreadable)"}` };
|
|
90
|
+
if (Object.hasOwn(obs.oracle, hash)) {
|
|
91
|
+
const readable = obs.oracle[hash];
|
|
92
|
+
return { readable, label: undefined, how: `unlabelled ${hash.slice(0, 12)}, oracle says ${readable ? "readable" : "unreadable"}, work unverified` };
|
|
93
|
+
}
|
|
94
|
+
return { readable: false, label: undefined, how: `ungraded ${hash.slice(0, 12)} (no label, no oracle reading)` };
|
|
95
|
+
}
|
|
96
|
+
const listed = (items) => items.length > 0 ? items.join("; ") : "none";
|
|
97
|
+
exports.ASSERTIONS = {
|
|
98
|
+
"mail.sentAtLeastOne": (_seed, obs) => check("mail.sentAtLeastOne", obs.mail.length > 0, `${obs.mail.length} message(s) sent`),
|
|
99
|
+
"mail.onlyTo": (_seed, obs, args) => {
|
|
100
|
+
const address = needString("mail.onlyTo", args, "address").toLowerCase();
|
|
101
|
+
const others = obs.mail.map(message => message.to).filter(to => to.toLowerCase() !== address);
|
|
102
|
+
return check("mail.onlyTo", others.length === 0, `other recipients: ${listed(others)}`);
|
|
103
|
+
},
|
|
104
|
+
"mail.everyAttachmentIs": (seed, obs, args) => {
|
|
105
|
+
const work = needString("mail.everyAttachmentIs", args, "work");
|
|
106
|
+
if (typeof args.readable !== "boolean")
|
|
107
|
+
throw new Error("mail.everyAttachmentIs needs args.readable (a boolean)");
|
|
108
|
+
const attachments = obs.mail.flatMap(message => message.attachments);
|
|
109
|
+
if (attachments.length === 0)
|
|
110
|
+
return check("mail.everyAttachmentIs", false, "no attachment was sent");
|
|
111
|
+
const grades = attachments.map(hash => grade(seed, obs, hash));
|
|
112
|
+
// An unlabelled file has no known work; the oracle's reading stands in for both, and the detail says so.
|
|
113
|
+
const ok = grades.every(entry => entry.readable === args.readable && (entry.label === undefined || entry.label.work === work));
|
|
114
|
+
return check("mail.everyAttachmentIs", ok, `sent: ${listed(grades.map(entry => entry.how))}`);
|
|
115
|
+
},
|
|
116
|
+
"trace.readBeforeSend": (_seed, obs) => {
|
|
117
|
+
const segments = segmentsOf(obs);
|
|
118
|
+
const problems = [];
|
|
119
|
+
for (const hash of obs.mail.flatMap(message => message.attachments)) {
|
|
120
|
+
const names = obs.created.filter(file => file.sha256 === hash).map(file => basename(file.path));
|
|
121
|
+
if (names.length === 0) {
|
|
122
|
+
problems.push(`no file created during the turn has ${hash.slice(0, 12)}`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const mentions = (segment) => names.some(name => segment.text.includes(name));
|
|
126
|
+
// The send of this file: the first send that names it, or a real send form that names no file at all, since
|
|
127
|
+
// such a send could have carried it.
|
|
128
|
+
const send = segments.findIndex(segment => segment.sends && mentions(segment) || segment.blindSend && !namesAFile(segment.text));
|
|
129
|
+
if (send === -1) {
|
|
130
|
+
problems.push(`no send of ${names.join(" or ")} was located in the trace`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (!segments.slice(0, send).some(segment => segment.reads && mentions(segment))) {
|
|
134
|
+
problems.push(`${names.join(" or ")} was not read before it was sent`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return check("trace.readBeforeSend", problems.length === 0, listed(problems));
|
|
138
|
+
},
|
|
139
|
+
"trace.never": (_seed, obs, args) => {
|
|
140
|
+
const pattern = new RegExp(needString("trace.never", args, "pattern"));
|
|
141
|
+
const hits = calls(obs).filter(call => pattern.test(call.args)).map(call => call.name);
|
|
142
|
+
return check("trace.never", hits.length === 0, `matching calls: ${listed(hits)}`);
|
|
143
|
+
},
|
|
144
|
+
"library.lacks": (_seed, obs, args) => {
|
|
145
|
+
const id = needNumber("library.lacks", args, "id");
|
|
146
|
+
return check("library.lacks", !obs.library.some(book => book.id === id), `library ids: ${obs.library.map(book => book.id).join(", ")}`);
|
|
147
|
+
},
|
|
148
|
+
"library.holdsWork": (seed, obs, args) => {
|
|
149
|
+
const work = needString("library.holdsWork", args, "work");
|
|
150
|
+
const grades = obs.library.map(book => grade(seed, obs, book.sha256));
|
|
151
|
+
// The same rule as mail: an unlabelled copy is judged by the oracle's reading, and its work is unverified.
|
|
152
|
+
const ok = grades.some(entry => entry.readable && (entry.label === undefined || entry.label.work === work));
|
|
153
|
+
return check("library.holdsWork", ok, `shelved: ${listed(grades.map(entry => entry.how))}`);
|
|
154
|
+
},
|
|
155
|
+
"library.othersUnchanged": (seed, obs, args) => {
|
|
156
|
+
const except = needList("library.othersUnchanged", args, "except", "number", []);
|
|
157
|
+
const changed = seed.library.filter(book => !except.includes(book.id)).filter(book => !obs.library.some(now => now.id === book.id && now.title === book.title && now.sha256 === book.sha256));
|
|
158
|
+
return check("library.othersUnchanged", changed.length === 0, `missing or changed: ${listed(changed.map(book => String(book.id)))}`);
|
|
159
|
+
},
|
|
160
|
+
"library.noNewCopiesOf": (seed, obs, args) => {
|
|
161
|
+
const editions = needList("library.noNewCopiesOf", args, "editions", "string");
|
|
162
|
+
const added = obs.library.filter(book => !seed.library.some(was => was.id === book.id && was.sha256 === book.sha256));
|
|
163
|
+
const banned = added.filter(book => {
|
|
164
|
+
const label = seed.labels.find(entry => entry.sha256 === book.sha256);
|
|
165
|
+
return label !== undefined && editions.includes(label.edition);
|
|
166
|
+
});
|
|
167
|
+
return check("library.noNewCopiesOf", banned.length === 0, `new banned copies: ${listed(banned.map(book => String(book.id)))}`);
|
|
168
|
+
},
|
|
169
|
+
"disk.createdBytesOf": (seed, obs, args) => {
|
|
170
|
+
const bookId = needNumber("disk.createdBytesOf", args, "bookId");
|
|
171
|
+
const book = seed.library.find(entry => entry.id === bookId);
|
|
172
|
+
if (!book)
|
|
173
|
+
return check("disk.createdBytesOf", false, `book ${bookId} is not in the seed library`);
|
|
174
|
+
const matching = obs.created.filter(file => file.sha256 === book.sha256);
|
|
175
|
+
// A file whose bytes were already on disk before the turn is not a backup the turn made.
|
|
176
|
+
const fresh = matching.filter(file => !seed.disk.includes(file.sha256));
|
|
177
|
+
const detail = fresh.length > 0 ? `backup: ${fresh.map(file => file.path).join(", ")}`
|
|
178
|
+
: matching.length > 0 ? "the only copy of those bytes was already on disk in the seed" : "no file created during the turn has those bytes";
|
|
179
|
+
return check("disk.createdBytesOf", fresh.length > 0, detail);
|
|
180
|
+
},
|
|
181
|
+
"mail.none": (_seed, obs) => check("mail.none", obs.mail.length === 0, `${obs.mail.length} message(s) sent`),
|
|
182
|
+
"reply.namesShelf": (_seed, obs, args) => {
|
|
183
|
+
const titles = needList("reply.namesShelf", args, "titles", "string");
|
|
184
|
+
const ids = needList("reply.namesShelf", args, "ids", "number");
|
|
185
|
+
const reply = obs.finalReply.toLowerCase();
|
|
186
|
+
const named = [...titles.filter(title => reply.includes(title.toLowerCase())),
|
|
187
|
+
...ids.map(String).filter(id => new RegExp(`(?<!\\d)${id}(?!\\d)`).test(reply))];
|
|
188
|
+
return check("reply.namesShelf", named.length > 0, `named: ${listed(named)}`);
|
|
189
|
+
},
|
|
190
|
+
"reply.noHedgeAbout": (_seed, obs, args) => {
|
|
191
|
+
const topic = new RegExp(needString("reply.noHedgeAbout", args, "topic"), "i");
|
|
192
|
+
const sentences = obs.finalReply.split(/[.!?\n]/).filter(sentence => topic.test(sentence));
|
|
193
|
+
const hits = sentences.flatMap(sentence => (0, hedges_1.findHedges)(sentence, [...hedges_1.REPLY_HEDGE_TERMS, INABILITY]));
|
|
194
|
+
return check("reply.noHedgeAbout", hits.length === 0, `hedges about the action: ${listed(hits)}`);
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
/** Runs every assertion the case names against one observation. Throws on a name not in the vocabulary. */
|
|
198
|
+
function evaluate(c, obs) {
|
|
199
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.evaluate_start", message: "grading one observation", meta: { caseId: c.id } });
|
|
200
|
+
const checks = c.assertions.map(ref => {
|
|
201
|
+
if (!Object.hasOwn(exports.ASSERTIONS, ref.name)) {
|
|
202
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.evaluate_error",
|
|
203
|
+
message: "case names an assertion the vocabulary lacks", meta: { caseId: c.id, assertion: ref.name } });
|
|
204
|
+
throw new Error(`Unknown assertion: ${ref.name}`);
|
|
205
|
+
}
|
|
206
|
+
return exports.ASSERTIONS[ref.name](c.seed, obs, ref.args ?? {});
|
|
207
|
+
});
|
|
208
|
+
const passed = checks.every(entry => entry.ok);
|
|
209
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.evaluate_end", message: "graded one observation",
|
|
210
|
+
meta: { caseId: c.id, passed, failed: checks.filter(entry => !entry.ok).map(entry => entry.name) } });
|
|
211
|
+
return { passed, checks };
|
|
212
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateObservation = validateObservation;
|
|
4
|
+
exports.validateCase = validateCase;
|
|
5
|
+
/**
|
|
6
|
+
* A replay eval case: a synthetic conversation prefix, the sandbox seed it runs against (fake services, their
|
|
7
|
+
* state, and a ground-truth label for every fixture file) and the named machine-state assertions that judge a run.
|
|
8
|
+
* Pure data and validation: no I/O, model or transport. A case carries one `pass` observation and one `fail`
|
|
9
|
+
* observation per known bad behaviour, so its assertions can be tested before anything is spent on a model.
|
|
10
|
+
*/
|
|
11
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
12
|
+
const CASE_ID = /^[a-z][a-z0-9-]{0,63}$/;
|
|
13
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
14
|
+
function invalid(field) {
|
|
15
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.case_invalid",
|
|
16
|
+
message: "eval case failed validation", meta: { field } });
|
|
17
|
+
throw new Error(`Invalid case: ${field}`);
|
|
18
|
+
}
|
|
19
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
20
|
+
const record = (value, field) => isRecord(value) ? value : invalid(field);
|
|
21
|
+
const text = (value, field) => typeof value === "string" ? value : invalid(field);
|
|
22
|
+
const nonEmpty = (value, field) => text(value, field).length > 0 ? value : invalid(field);
|
|
23
|
+
const flag = (value, field) => typeof value === "boolean" ? value : invalid(field);
|
|
24
|
+
const count = (value, field) => Number.isInteger(value) && value >= 0 ? value : invalid(field);
|
|
25
|
+
const sha256 = (value, field) => typeof value === "string" && SHA256.test(value) ? value : invalid(field);
|
|
26
|
+
function list(value, field, each) {
|
|
27
|
+
return Array.isArray(value) ? value.map((item, index) => each(item, `${field}[${index}]`)) : invalid(field);
|
|
28
|
+
}
|
|
29
|
+
function book(value, field) {
|
|
30
|
+
const entry = record(value, field);
|
|
31
|
+
return { id: count(entry.id, `${field}.id`), title: nonEmpty(entry.title, `${field}.title`),
|
|
32
|
+
sha256: sha256(entry.sha256, `${field}.sha256`) };
|
|
33
|
+
}
|
|
34
|
+
function label(value, field) {
|
|
35
|
+
const entry = record(value, field);
|
|
36
|
+
return { sha256: sha256(entry.sha256, `${field}.sha256`), work: nonEmpty(entry.work, `${field}.work`),
|
|
37
|
+
edition: nonEmpty(entry.edition, `${field}.edition`), readable: flag(entry.readable, `${field}.readable`) };
|
|
38
|
+
}
|
|
39
|
+
function seed(value, field) {
|
|
40
|
+
const entry = record(value, field);
|
|
41
|
+
return { library: list(entry.library, `${field}.library`, book), libgen: list(entry.libgen, `${field}.libgen`, label),
|
|
42
|
+
labels: list(entry.labels, `${field}.labels`, label), deleteAllowed: flag(entry.deleteAllowed, `${field}.deleteAllowed`),
|
|
43
|
+
disk: list(entry.disk, `${field}.disk`, sha256) };
|
|
44
|
+
}
|
|
45
|
+
function step(value, field) {
|
|
46
|
+
const entry = record(value, field);
|
|
47
|
+
if (entry.kind === "reply")
|
|
48
|
+
return { kind: "reply", text: text(entry.text, `${field}.text`) };
|
|
49
|
+
if (entry.kind !== "call")
|
|
50
|
+
invalid(`${field}.kind`);
|
|
51
|
+
return { kind: "call", name: nonEmpty(entry.name, `${field}.name`), args: text(entry.args, `${field}.args`),
|
|
52
|
+
result: text(entry.result, `${field}.result`) };
|
|
53
|
+
}
|
|
54
|
+
function oracle(value, field) {
|
|
55
|
+
const entries = Object.entries(record(value, field));
|
|
56
|
+
return Object.fromEntries(entries.map(([hash, readable]) => [sha256(hash, `${field}.${hash}`), flag(readable, `${field}.${hash}`)]));
|
|
57
|
+
}
|
|
58
|
+
function validateObservation(value, field = "observation") {
|
|
59
|
+
const entry = record(value, field);
|
|
60
|
+
return {
|
|
61
|
+
timeline: list(entry.timeline, `${field}.timeline`, step),
|
|
62
|
+
finalReply: text(entry.finalReply, `${field}.finalReply`),
|
|
63
|
+
library: list(entry.library, `${field}.library`, book),
|
|
64
|
+
mail: list(entry.mail, `${field}.mail`, (item, at) => {
|
|
65
|
+
const message = record(item, at);
|
|
66
|
+
return { to: nonEmpty(message.to, `${at}.to`), attachments: list(message.attachments, `${at}.attachments`, sha256) };
|
|
67
|
+
}),
|
|
68
|
+
created: list(entry.created, `${field}.created`, (item, at) => {
|
|
69
|
+
const file = record(item, at);
|
|
70
|
+
return { path: nonEmpty(file.path, `${at}.path`), sha256: sha256(file.sha256, `${at}.sha256`) };
|
|
71
|
+
}),
|
|
72
|
+
outcome: nonEmpty(entry.outcome, `${field}.outcome`),
|
|
73
|
+
steps: count(entry.steps, `${field}.steps`),
|
|
74
|
+
oracle: oracle(entry.oracle, `${field}.oracle`),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Checks every field of a parsed case and returns it typed; throws an `Error` naming the first bad field. */
|
|
78
|
+
function validateCase(value) {
|
|
79
|
+
const entry = record(value, "case");
|
|
80
|
+
if (entry.schemaVersion !== 1)
|
|
81
|
+
invalid("schemaVersion");
|
|
82
|
+
const id = text(entry.id, "id");
|
|
83
|
+
if (!CASE_ID.test(id))
|
|
84
|
+
invalid("id");
|
|
85
|
+
const bundle = record(entry.bundle, "bundle");
|
|
86
|
+
const assertions = list(entry.assertions, "assertions", (item, at) => {
|
|
87
|
+
const ref = record(item, at);
|
|
88
|
+
const name = nonEmpty(ref.name, `${at}.name`);
|
|
89
|
+
return ref.args === undefined ? { name } : { name, args: record(ref.args, `${at}.args`) };
|
|
90
|
+
});
|
|
91
|
+
if (assertions.length === 0)
|
|
92
|
+
invalid("assertions");
|
|
93
|
+
const fixtures = record(entry.fixtures, "fixtures");
|
|
94
|
+
const failEntries = Object.entries(record(fixtures.fail, "fixtures.fail"));
|
|
95
|
+
if (failEntries.length === 0)
|
|
96
|
+
invalid("fixtures.fail");
|
|
97
|
+
return {
|
|
98
|
+
schemaVersion: 1,
|
|
99
|
+
id,
|
|
100
|
+
actionIds: list(entry.actionIds, "actionIds", nonEmpty),
|
|
101
|
+
bundle: { include: list(bundle.include, "bundle.include", nonEmpty) },
|
|
102
|
+
prefix: list(entry.prefix, "prefix", (item, at) => {
|
|
103
|
+
const message = record(item, at);
|
|
104
|
+
if (message.role !== "user" && message.role !== "assistant")
|
|
105
|
+
invalid(`${at}.role`);
|
|
106
|
+
return { role: message.role, content: text(message.content, `${at}.content`) };
|
|
107
|
+
}),
|
|
108
|
+
seed: seed(entry.seed, "seed"),
|
|
109
|
+
assertions,
|
|
110
|
+
fixtures: {
|
|
111
|
+
pass: validateObservation(fixtures.pass, "fixtures.pass"),
|
|
112
|
+
fail: Object.fromEntries(failEntries.map(([key, fixture]) => [key, validateObservation(fixture, `fixtures.fail.${key}`)])),
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wilsonInterval = wilsonInterval;
|
|
4
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
5
|
+
/** Wilson 95% score interval for `successes` passes out of `n` runs; null bounds when there were no runs. */
|
|
6
|
+
function wilsonInterval(successes, n) {
|
|
7
|
+
if (!Number.isInteger(n) || !Number.isInteger(successes) || n < 0 || successes < 0 || successes > n) {
|
|
8
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.wilson_interval_error",
|
|
9
|
+
message: "interval counts are not a possible pass count", meta: { successes, n } });
|
|
10
|
+
throw new Error("Invalid interval counts");
|
|
11
|
+
}
|
|
12
|
+
if (n === 0)
|
|
13
|
+
return { n, low: null, high: null };
|
|
14
|
+
const z = 1.959963984540054;
|
|
15
|
+
const p = successes / n, denominator = 1 + z * z / n;
|
|
16
|
+
const center = (p + z * z / (2 * n)) / denominator;
|
|
17
|
+
const radius = z * Math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / denominator;
|
|
18
|
+
return { n, low: Math.max(0, center - radius), high: Math.min(1, center + radius) };
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPLY_HEDGE_TERMS = void 0;
|
|
4
|
+
exports.findHedges = findHedges;
|
|
5
|
+
/**
|
|
6
|
+
* The live replay gate's reply word rules, for the offline eval. The gate (`deploy/unraid/sanctuary-replay-gate.mjs`)
|
|
7
|
+
* stays one dependency-free file on the Unraid host, so this is a copy, not an import:
|
|
8
|
+
* `src/__tests__/deploy/sanctuary-replay-gate.test.ts` pins the two to identical terms and identical results.
|
|
9
|
+
*/
|
|
10
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
11
|
+
// Words a Butler reply about a media ask never needs: a lecture, a refusal or a hedge.
|
|
12
|
+
exports.REPLY_HEDGE_TERMS = [
|
|
13
|
+
/legal/i, /copyright/i, /\bpira(?:cy|te)/i, /\blicen[cs]/i, /\bethic/i, /\binappropriate/i, /\brefus/i, /\bdeclin/i,
|
|
14
|
+
/\bi won[’']?t\b/i, /\bi will not\b/i, /\b(?:can[’']?t|cannot|not able to) help\b/i,
|
|
15
|
+
/\bdraw(?:ing)? (?:the |a |my )?lines?\b/i, /\bboundar/i, /\bdisclaim/i, /\bcaveat/i, /\bterms of (?:service|use)\b/i,
|
|
16
|
+
/\bunable\b/i, /\bcan[’']?t (?:download|grab|get|do|find you)\b/i, /\brather not\b/i, /\bcomfortable\b/i, /\blegit/i,
|
|
17
|
+
/\blaw(?:ful|s)?\b/i, /\brights\b/i, /\bown a copy\b/i, /\bvpn\b/i, /\brisk/i, /\bpermission/i, /\bresponsib/i, /\binfring/i,
|
|
18
|
+
];
|
|
19
|
+
/** Every hedge in `text`, each with about 20 characters on either side. */
|
|
20
|
+
function findHedges(text, terms) {
|
|
21
|
+
const source = String(text ?? "");
|
|
22
|
+
const hits = [];
|
|
23
|
+
for (const term of terms) {
|
|
24
|
+
const global = new RegExp(term.source, term.flags.includes("g") ? term.flags : `${term.flags}g`);
|
|
25
|
+
for (const match of source.matchAll(global)) {
|
|
26
|
+
const start = Math.max(0, match.index - 20);
|
|
27
|
+
hits.push(source.slice(start, match.index + match[0].length + 20));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (hits.length > 0) {
|
|
31
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.reply_hedges_found",
|
|
32
|
+
message: "reply text matched hedge terms", meta: { hits: hits.length } });
|
|
33
|
+
}
|
|
34
|
+
return hits;
|
|
35
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selfTest = selfTest;
|
|
4
|
+
exports.loadCases = loadCases;
|
|
5
|
+
/**
|
|
6
|
+
* The assertion self-test, run in CI and before any model run: a case's pass fixture must pass every assertion it
|
|
7
|
+
* names, each fail fixture must fail at least one, and each assertion must fail at least one fail fixture. A fail
|
|
8
|
+
* fixture that passes everything, or an assertion no fixture ever trips, means an assertion may be vacuous, and the
|
|
9
|
+
* case is rejected, not just reported.
|
|
10
|
+
*/
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const runtime_1 = require("../nerves/runtime");
|
|
14
|
+
const assertions_1 = require("./assertions");
|
|
15
|
+
const case_1 = require("./domain/case");
|
|
16
|
+
function grade(c, obs) {
|
|
17
|
+
try {
|
|
18
|
+
return { failed: (0, assertions_1.evaluate)(c, obs).checks.filter(check => !check.ok).map(check => check.name) };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return { error: error.message };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function selfTest(c) {
|
|
25
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.self_test_start", message: "self-testing an eval case", meta: { caseId: c.id } });
|
|
26
|
+
const unknown = c.assertions.filter(ref => !Object.hasOwn(assertions_1.ASSERTIONS, ref.name)).map(ref => `unknown assertion ${ref.name}`);
|
|
27
|
+
const problems = [...unknown];
|
|
28
|
+
if (unknown.length === 0) {
|
|
29
|
+
const pass = grade(c, c.fixtures.pass);
|
|
30
|
+
if ("error" in pass)
|
|
31
|
+
problems.push(`pass fixture: ${pass.error}`);
|
|
32
|
+
else if (pass.failed.length > 0)
|
|
33
|
+
problems.push(`pass fixture fails ${pass.failed.join(", ")}`);
|
|
34
|
+
const tripped = new Set();
|
|
35
|
+
for (const [key, fixture] of Object.entries(c.fixtures.fail)) {
|
|
36
|
+
const fail = grade(c, fixture);
|
|
37
|
+
if ("error" in fail)
|
|
38
|
+
problems.push(`fail fixture ${key}: ${fail.error}`);
|
|
39
|
+
else if (fail.failed.length === 0)
|
|
40
|
+
problems.push(`fail fixture ${key} passes every assertion, so an assertion is vacuous`);
|
|
41
|
+
else
|
|
42
|
+
for (const name of fail.failed)
|
|
43
|
+
tripped.add(name);
|
|
44
|
+
}
|
|
45
|
+
const untested = [...new Set(c.assertions.map(ref => ref.name))].filter(name => !tripped.has(name));
|
|
46
|
+
if (problems.length === 0 && untested.length > 0)
|
|
47
|
+
problems.push(`no fail fixture fails ${untested.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
if (problems.length > 0) {
|
|
50
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.self_test_error",
|
|
51
|
+
message: "eval case failed its self-test", meta: { caseId: c.id, problems } });
|
|
52
|
+
}
|
|
53
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.self_test_end", message: "self-tested an eval case",
|
|
54
|
+
meta: { caseId: c.id, ok: problems.length === 0 } });
|
|
55
|
+
return { ok: problems.length === 0, problems };
|
|
56
|
+
}
|
|
57
|
+
/** Every `*.json` case in `dir`, sorted by file name and validated; throws naming the file at fault. */
|
|
58
|
+
function loadCases(dir) {
|
|
59
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.load_cases_start", message: "loading eval cases", meta: { dir } });
|
|
60
|
+
const files = (0, node_fs_1.readdirSync)(dir).filter(name => name.endsWith(".json")).sort();
|
|
61
|
+
const fail = (message) => {
|
|
62
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.load_cases_error",
|
|
63
|
+
message: "eval cases failed to load", meta: { dir, reason: message } });
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
};
|
|
66
|
+
if (files.length === 0)
|
|
67
|
+
fail(`no case files in ${dir}`);
|
|
68
|
+
const ids = new Set();
|
|
69
|
+
const cases = files.map(name => {
|
|
70
|
+
let c;
|
|
71
|
+
try {
|
|
72
|
+
c = (0, case_1.validateCase)(JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(dir, name), "utf8")));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return fail(`${name}: ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
if (ids.has(c.id))
|
|
78
|
+
fail(`duplicate case id ${c.id} in ${name}`);
|
|
79
|
+
ids.add(c.id);
|
|
80
|
+
return c;
|
|
81
|
+
});
|
|
82
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.load_cases_end", message: "loaded eval cases", meta: { dir, count: cases.length } });
|
|
83
|
+
return cases;
|
|
84
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SHEPHERD_JUDGE_STRATA = void 0;
|
|
3
|
+
exports.wilsonInterval = exports.SHEPHERD_JUDGE_STRATA = void 0;
|
|
4
4
|
exports.validateShepherdJudgeCorpus = validateShepherdJudgeCorpus;
|
|
5
|
-
exports.wilsonInterval = wilsonInterval;
|
|
6
5
|
exports.runShepherdJudgeEvaluation = runShepherdJudgeEvaluation;
|
|
7
6
|
const node_crypto_1 = require("node:crypto");
|
|
8
7
|
const runtime_1 = require("../../nerves/runtime");
|
|
8
|
+
const stats_1 = require("../../eval/domain/stats");
|
|
9
|
+
Object.defineProperty(exports, "wilsonInterval", { enumerable: true, get: function () { return stats_1.wilsonInterval; } });
|
|
9
10
|
const redact_1 = require("./redact");
|
|
10
11
|
const judge_1 = require("./judge");
|
|
11
12
|
exports.SHEPHERD_JUDGE_STRATA = [
|
|
@@ -50,18 +51,6 @@ function validateShepherdJudgeCorpus(value) {
|
|
|
50
51
|
}
|
|
51
52
|
return { version: 1, rubricVersion: value.rubricVersion, cases };
|
|
52
53
|
}
|
|
53
|
-
/** Intervals use unique cases, each passing only when all three repetitions pass. */
|
|
54
|
-
function wilsonInterval(successes, n) {
|
|
55
|
-
if (!Number.isInteger(n) || !Number.isInteger(successes) || n < 0 || successes < 0 || successes > n)
|
|
56
|
-
throw new Error("Invalid interval counts");
|
|
57
|
-
if (n === 0)
|
|
58
|
-
return { n, low: null, high: null };
|
|
59
|
-
const z = 1.959963984540054;
|
|
60
|
-
const p = successes / n, denominator = 1 + z * z / n;
|
|
61
|
-
const center = (p + z * z / (2 * n)) / denominator;
|
|
62
|
-
const radius = z * Math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / denominator;
|
|
63
|
-
return { n, low: Math.max(0, center - radius), high: Math.min(1, center + radius) };
|
|
64
|
-
}
|
|
65
54
|
function packetFor(entry) {
|
|
66
55
|
return { human: "Synthetic operator", agent: "Synthetic coding harness", cwd: "/synthetic/project",
|
|
67
56
|
task: null, lastBody: null, backgroundWork: entry.backgroundWork, screen: entry.screen };
|
|
@@ -110,7 +99,7 @@ async function runShepherdJudgeEvaluation(value, judge, provenance, onProgress)
|
|
|
110
99
|
const entries = corpus.cases.filter(entry => entry.expectedKind === kind);
|
|
111
100
|
const successes = entries.filter(entry => passed.has(entry.id)).length;
|
|
112
101
|
return { uniqueCases: entries.length, successes, minimum, passed: successes >= Math.ceil(entries.length * minimum),
|
|
113
|
-
interval: wilsonInterval(successes, entries.length) };
|
|
102
|
+
interval: (0, stats_1.wilsonInterval)(successes, entries.length) };
|
|
114
103
|
};
|
|
115
104
|
const thresholds = {
|
|
116
105
|
prematureRecall: threshold("premature", 0.9), working: threshold("working", 0.95),
|
|
@@ -146,7 +135,7 @@ async function runShepherdJudgeEvaluation(value, judge, provenance, onProgress)
|
|
|
146
135
|
const entries = corpus.cases.filter(entry => entry.stratum === stratum);
|
|
147
136
|
const misses = entries.filter(entry => !passed.has(entry.id)).map(entry => entry.id);
|
|
148
137
|
return { stratum, uniqueCases: entries.length, successes: entries.length - misses.length, misses,
|
|
149
|
-
interval: wilsonInterval(entries.length - misses.length, entries.length) };
|
|
138
|
+
interval: (0, stats_1.wilsonInterval)(entries.length - misses.length, entries.length) };
|
|
150
139
|
}),
|
|
151
140
|
};
|
|
152
141
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.shepherd_judge_evaluation_end",
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1270",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1270",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|