@ouro.bot/cli 0.1.0-alpha.1431 → 0.1.0-alpha.1433

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.
Files changed (31) hide show
  1. package/changelog.json +18 -1
  2. package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
  3. package/deploy/unraid/sanctuary.xml +1 -1
  4. package/dist/eval/assertions/index.js +115 -8
  5. package/dist/eval/interview-guest-entry.js +17 -0
  6. package/dist/eval/interviews/allocation.js +64 -0
  7. package/dist/eval/interviews/guest/arms.js +173 -0
  8. package/dist/eval/interviews/guest/ax/ax-command.js +792 -0
  9. package/dist/eval/interviews/guest/ax/effects.js +51 -0
  10. package/dist/eval/interviews/guest/ax/exit-codes.js +51 -0
  11. package/dist/eval/interviews/guest/ax/help.js +181 -0
  12. package/dist/eval/interviews/guest/ax/mcp.js +246 -0
  13. package/dist/eval/interviews/guest/ax/outcome.js +211 -0
  14. package/dist/eval/interviews/guest/ax/output.js +53 -0
  15. package/dist/eval/interviews/guest/ax/precise-copy.js +200 -0
  16. package/dist/eval/interviews/guest/ax/problem.js +95 -0
  17. package/dist/eval/interviews/guest/ax/voice.js +83 -0
  18. package/dist/eval/interviews/guest/ax/wait.js +158 -0
  19. package/dist/eval/interviews/guest/books-core.js +54 -0
  20. package/dist/eval/interviews/guest/cli-shell.js +267 -0
  21. package/dist/eval/interviews/guest/loop.js +78 -0
  22. package/dist/eval/interviews/guest/operations.js +108 -0
  23. package/dist/eval/interviews/guest/run.js +62 -0
  24. package/dist/eval/interviews/latch.js +122 -0
  25. package/dist/eval/interviews/protocol.js +77 -0
  26. package/dist/eval/remote-entry.js +2 -0
  27. package/dist/eval/sandbox/docker.js +23 -6
  28. package/dist/eval/sandbox/remote.js +2 -2
  29. package/dist/nerves/coverage/file-completeness.js +3 -0
  30. package/npm-shrinkwrap.json +2 -2
  31. package/package.json +1 -1
package/changelog.json CHANGED
@@ -1,13 +1,30 @@
1
1
  {
2
2
  "_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.1433",
6
+ "changes": [
7
+ "The eval can now run a blind interview conversation in its sandbox: a neutral tool loop, not the Butler's own turn, with one of three book-tool interfaces (an AX-kit tool set, plain MCP-style tools, or a `books` command behind a single `shell` tool), all doing the same operations with the same results. A conversation can have a follow-up question after the job, and the host scans every model request for brand words and counts it against a per-session call latch before sending it.",
8
+ "The eval's read-before-send check now follows a shell call's own variables, its folder and its wildcards. A run that wrote `B=/…/books; F=/…/copy.epub; $B check \"$F\" && $B send \"$F\"`, or checked every download with `for f in $W/…-get*/*.epub; do $B check \"$f\"; done`, had read the book before sending it, but the check found no send and failed the run.",
9
+ "Variables are written out only within the shell call that sets them. A loop variable is written out once for each of its words, so a loop credits every file it checked. In a call that runs an inline Python script, the files the script opens count, and so do those of any command around it that reads on its own, such as a `books check`; a file that is only copied or listed does not.",
10
+ "Every file a command names, written out or as a wildcard, is resolved against the call's folder: the shell tool's `cwd`, then each plain `cd`. It counts only if it covers the created file's whole path, so a check of a same-named copy in another folder no longer counts.",
11
+ "A wildcard read counts only if no `books get`, `books series`, `curl` or `wget` ran between it and the send.",
12
+ "A send that nothing read first still fails.",
13
+ "Re-grading the stored book-eval reports read-only changes five runs from fail to pass (three in this step's Opus replay, two in round B) and no pass to a fail. One more run's read-before-send check now passes, but that run still fails on another check."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1431",
6
18
  "changes": [
7
- "Phone utterances in the cascade voice path (Twilio Media Stream and Twilio recordings) now end with a recorded outcome; the OpenAI Realtime and SIP engines are not covered yet. Each thing a caller says is recorded before its turn runs. Its speech, and any tool that messages a person, is noted before it goes out, and its turn records it as answered, silent (the agent had nothing to say) or failed. A reply counts as answered only once it could reach the caller: a Media Stream reply once some of its audio went down the call (so a hangup or talk-over after part of it played still counts as answered), a buffered recording's reply once its playback files are written, and a streamed recording's reply once its speech is made, before Twilio fetches the stream. A Media Stream reply cut off before any audio played is recorded as failed, saying why: the call ended, the caller spoke again, a tool's audio took its place, or the reply made no audio to send. Live audio is never replayed: an utterance a stopped process left is recorded as failed once the voice sense is listening again, and when it shuts down, and the record says what the caller had already heard. A bridge that cannot take its port leaves the running one's records alone. A recording callback Twilio sends twice runs one turn: a retry while the first is still being answered gets the same reply, a retry of a streamed reply gets the same play link while its stream is still served, and any other retry is sent on to listen. A record that cannot be written is logged and never costs the caller the answer or stops the voice sense.",
8
19
  "`ouro up` now says why an update did not install (\"could not install X: ...\"), instead of \"update check unavailable\", and says when npm lists a release but is not serving its tarball yet. The unattended updater treats that not-served-yet answer (ETARGET, or a 404 on the release's tarball) as a wait for the next pass, not an install failure, and does not count it as a failed attempt."
9
20
  ]
10
21
  },
22
+ {
23
+ "version": "0.1.0-alpha.1430",
24
+ "changes": [
25
+ "Phone utterances in the cascade voice path (Twilio Media Stream and Twilio recordings) now end with a recorded outcome; the OpenAI Realtime and SIP engines are not covered yet. Each thing a caller says is recorded before its turn runs. Its speech, and any tool that messages a person, is noted before it goes out, and its turn records it as answered, silent (the agent had nothing to say) or failed. A reply counts as answered only once it could reach the caller: a Media Stream reply once some of its audio went down the call (so a hangup or talk-over after part of it played still counts as answered), a buffered recording's reply once its playback files are written, and a streamed recording's reply once its speech is made, before Twilio fetches the stream. A Media Stream reply cut off before any audio played is recorded as failed, saying why: the call ended, the caller spoke again, a tool's audio took its place, or the reply made no audio to send. Live audio is never replayed: an utterance a stopped process left is recorded as failed once the voice sense is listening again, and when it shuts down, and the record says what the caller had already heard. A bridge that cannot take its port leaves the running one's records alone. A recording callback Twilio sends twice runs one turn: a retry while the first is still being answered gets the same reply, a retry of a streamed reply gets the same play link while its stream is still served, and any other retry is sent on to listen. A record that cannot be written is logged and never costs the caller the answer or stops the voice sense."
26
+ ]
27
+ },
11
28
  {
12
29
  "version": "0.1.0-alpha.1429",
13
30
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1431",
2
+ "runtimeVersion": "0.1.0-alpha.1433",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -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.1431</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1433</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -11,6 +11,7 @@ exports.evaluate = evaluate;
11
11
  * hash in neither is ungraded and never counts as readable. The oracle reads only readability, so an unlabelled file's
12
12
  * work is unverified, and its detail says so (so the run report, Task 9, can show such runs apart from the rest).
13
13
  */
14
+ const node_path_1 = require("node:path");
14
15
  const runtime_1 = require("../../nerves/runtime");
15
16
  const hedges_1 = require("../readback/hedges");
16
17
  /** Claims of inability, on top of the gate's hedge terms, for sentences about the asked action. */
@@ -62,6 +63,91 @@ function commandOf(call) {
62
63
  }
63
64
  const basename = (path) => path.slice(path.lastIndexOf("/") + 1);
64
65
  const namesAFile = (text) => FILE_NAME.test(text);
66
+ /** `NAME=value` commands with nothing else in them, the way a shell call keeps a path to use again. */
67
+ const ASSIGNMENTS = /^\s*(?:(?:do|then)\s+)?((?:[A-Za-z_]\w*=(?:"[^"]*"|'[^']*'|[^\s"'=]*)\s*)+)$/;
68
+ const ASSIGNMENT = /([A-Za-z_]\w*)=("[^"]*"|'[^']*'|[^\s"'=]*)/g;
69
+ /** A plain `cd <folder>`, which changes what a relative wildcard after it names. */
70
+ const CHANGE_FOLDER = /^\s*cd\s+(\S+)\s*$/;
71
+ /** A command that fetches a file, after which an earlier wildcard read no longer covers everything it matches. */
72
+ const DOWNLOADS = /\bbooks\s+(?:get|series)\b|\bcurl\b|\bwget\b/;
73
+ /** `for NAME in WORDS`, whose body sees NAME as each of the words. */
74
+ const FOR_LOOP = /^\s*(?:(?:do|then)\s+)?for\s+([A-Za-z_]\w*)\s+in\s+(.+)$/;
75
+ const VARIABLE = /\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)/g;
76
+ const unquote = (word) => word.replace(/^(["'])(.*)\1$/, "$2");
77
+ /**
78
+ * A shell call's commands with the call's own variables written out, so `B=/x/books; F=a.epub; $B send "$F"` reads as
79
+ * `/x/books send "a.epub"`, and each command's file and wildcard words resolved against the call's last `cd`. A loop
80
+ * variable stands for each of its words in turn, so a command that uses one is written out once per word. Only
81
+ * variables the call itself sets are known; each shell call is its own process, so nothing carries over from an
82
+ * earlier call, and it starts in the agent's bundle, where created paths are rooted.
83
+ */
84
+ function expandShell(parts, start) {
85
+ const known = new Map();
86
+ let folder = start;
87
+ /** Every way the command reads with its variables written out, at most 256, so a longer loop credits its first 256 words. */
88
+ const expand = (text) => {
89
+ const used = [...new Set([...text.matchAll(VARIABLE)].map(([, braced, bare]) => (braced ?? bare)).filter(name => known.has(name)))];
90
+ return used.reduce((texts, name) => texts.flatMap(each => known.get(name).map(value => each.replace(VARIABLE, (whole, braced, bare) => (braced ?? bare) === name ? value : whole))).slice(0, 256), [text]);
91
+ };
92
+ return parts.map(raw => {
93
+ const texts = expand(raw);
94
+ const text = texts[0];
95
+ if (ASSIGNMENTS.test(text)) {
96
+ for (const [, name] of text.matchAll(ASSIGNMENT)) {
97
+ known.set(name, [...new Set(texts.flatMap(each => [...each.matchAll(ASSIGNMENT)].filter(([, n]) => n === name).map(([, , value]) => unquote(value))))]);
98
+ }
99
+ }
100
+ const loop = FOR_LOOP.exec(text);
101
+ if (loop)
102
+ known.set(loop[1], [...new Set(texts.flatMap(each => [...FOR_LOOP.exec(each)[2].matchAll(SHELL_WORD)].map(([word]) => unquote(word))))]);
103
+ const cd = CHANGE_FOLDER.exec(text);
104
+ if (cd)
105
+ folder = node_path_1.posix.join(folder, unquote(cd[1]));
106
+ const words = [...new Set(texts.flatMap(fileWords))].map(word => word.startsWith("/") ? word : node_path_1.posix.join(folder, word));
107
+ return { text, files: words.filter(word => !/[*?]/.test(word)), globs: words.filter(word => /[*?]/.test(word)) };
108
+ });
109
+ }
110
+ /** A shell word, quotes and all, such as `"work/The Harbour Almanac.epub"` or `"$d"copy.epub` once expanded. */
111
+ const SHELL_WORD = /(?:"[^"]*"|'[^']*'|[^\s"'])+/g;
112
+ /** A book file named inside a longer word, such as the path in `zipfile.ZipFile("work/a.epub")`. */
113
+ const FILE_IN_WORD = /[^\s"'(),=;:]*\.(?:epub|pdf|mobi|azw3)\b/gi;
114
+ const BOOK_FILE = /\.(?:epub|pdf|mobi|azw3)$/i;
115
+ /** The book files and wildcards a command names, each as written (a quoted name may hold spaces). */
116
+ function fileWords(text) {
117
+ return [...text.matchAll(SHELL_WORD)].flatMap(([word]) => {
118
+ const plain = word.replace(/["']/g, "");
119
+ if (BOOK_FILE.test(plain) && !/[(),=;:]/.test(plain))
120
+ return [plain];
121
+ return [...plain.matchAll(FILE_IN_WORD)].map(([found]) => found).concat(/[*?]/.test(plain) && !/[(),=;:]/.test(plain) ? [plain] : []);
122
+ }).filter((word, i, all) => all.indexOf(word) === i);
123
+ }
124
+ /** The folder a shell call starts in: its own `cwd` argument, against the bundle, where created paths are rooted. */
125
+ function startFolder(call) {
126
+ try {
127
+ const cwd = JSON.parse(call.args)?.cwd;
128
+ return typeof cwd === "string" ? cwd : "";
129
+ }
130
+ catch {
131
+ return "";
132
+ }
133
+ }
134
+ /** The text of each inline Python script in a call: a `python3 -c` argument or a heredoc's body. */
135
+ const SCRIPT_TEXT = /\bpython3\s+-c\s+(?:'([^']*)'|"((?:[^"\\]|\\.)*)")|\bpython3\b[^\n]*<<-?\s*(['"]?)(\w+)\3[^\n]*\n([\s\S]*?)\n\s*\4\b/g;
136
+ const scriptsOf = (command) => [...command.matchAll(SCRIPT_TEXT)].map(([, single, double, , , body]) => (single ?? double ?? body));
137
+ /** A plain `cd <folder>` at the front of an inline script's call, which the script's relative paths are read from. */
138
+ const LEADING_CD = /^\s*cd\s+(\S+)\s*(?:;|&&)/;
139
+ const globPart = (part) => new RegExp(`^${part.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]")}$`);
140
+ /**
141
+ * Whether a wildcard word, resolved against its folder, matches a file's whole bundle path. An absolute wildcard
142
+ * carries the bundle's own folder in front, so the comparison runs from the end over every part of the file's path.
143
+ */
144
+ function globMatches(glob, path) {
145
+ const globParts = glob.split("/").filter(Boolean);
146
+ const pathParts = path.split("/").filter(Boolean);
147
+ if (globParts.length < pathParts.length)
148
+ return false;
149
+ return pathParts.every((part, i) => globPart(globParts[globParts.length - pathParts.length + i]).test(part));
150
+ }
65
151
  /**
66
152
  * Every call in order, as the commands that matter for reading before sending. A shell call is split into its chained
67
153
  * commands, so `books deliver f && books check f` is a send then a read, unless it runs an inline Python script, whose
@@ -73,13 +159,25 @@ function segmentsOf(obs) {
73
159
  return calls(obs).flatMap((call) => {
74
160
  if (call.name !== "shell") {
75
161
  const sends = !SPEECH_TOOLS.has(call.name) && SENDS_FILE.test(call.name);
76
- return [{ text: call.args, reads: false, sends, blindSend: sends }];
162
+ return [{ text: call.args, reads: false, sends, blindSend: sends, downloads: false, files: [], globs: [] }];
77
163
  }
78
164
  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) };
165
+ const start = startFolder(call);
166
+ const leading = LEADING_CD.exec(command);
167
+ const split = expandShell(command.split(COMMAND_SEPARATOR), start);
168
+ // An inline script stays one command, since its semicolons are the script's. It names the files its script opens,
169
+ // and the files of any shell command around it that is a read on its own, such as a `books check` in the same
170
+ // loop, or of one that sends it. A file the shell only copies or lists is not read because python3 runs in the call.
171
+ const scripts = INLINE_SCRIPT.test(command) && expandShell(scriptsOf(command), leading ? node_path_1.posix.join(start, unquote(leading[1])) : start);
172
+ // A command that sends names its file too, so a send piped through python3 is still found; it makes the whole
173
+ // segment a send, which never counts as a read.
174
+ const reads = split.filter(part => READS_FILE.test(part.text) || SENDS_FILE.test(part.text));
175
+ const parts = scripts ? [{ text: command, files: [...new Set([...scripts, ...reads].flatMap(part => part.files))],
176
+ globs: [...new Set([...scripts, ...reads].flatMap(part => part.globs))] }] : split;
177
+ return parts.map(({ text, files, globs }) => {
178
+ const asksForHelp = ASKS_FOR_HELP.test(text);
179
+ const sends = !asksForHelp && SENDS_FILE.test(text);
180
+ return { text, reads: !sends && READS_FILE.test(text), sends, blindSend: sends && BLIND_SEND.test(text), downloads: !asksForHelp && DOWNLOADS.test(text), files, globs };
83
181
  });
84
182
  });
85
183
  }
@@ -117,12 +215,17 @@ exports.ASSERTIONS = {
117
215
  const segments = segmentsOf(obs);
118
216
  const problems = [];
119
217
  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));
218
+ const paths = obs.created.filter(file => file.sha256 === hash).map(file => file.path);
219
+ const names = paths.map(basename);
121
220
  if (names.length === 0) {
122
221
  problems.push(`no file created during the turn has ${hash.slice(0, 12)}`);
123
222
  continue;
124
223
  }
125
- const mentions = (segment) => names.some(name => segment.text.includes(name));
224
+ // A file named in a shell command, resolved against the call's folder, must be this file, not one of the same name.
225
+ const byName = (segment) => segment.files.some(file => paths.some(path => globMatches(file, path)));
226
+ // A wildcard such as `work/2026-get/*.epub` names the file when it covers the file's whole path.
227
+ const byGlob = (segment) => segment.globs.some(glob => paths.some(path => globMatches(glob, path)));
228
+ const mentions = (segment) => byName(segment) || byGlob(segment);
126
229
  // The send of this file: the first send that names it, or a real send form that names no file at all, since
127
230
  // such a send could have carried it.
128
231
  const send = segments.findIndex(segment => segment.sends && mentions(segment) || segment.blindSend && !namesAFile(segment.text));
@@ -130,7 +233,11 @@ exports.ASSERTIONS = {
130
233
  problems.push(`no send of ${names.join(" or ")} was located in the trace`);
131
234
  continue;
132
235
  }
133
- if (!segments.slice(0, send).some(segment => segment.reads && mentions(segment))) {
236
+ // A read by name holds. A read by wildcard holds only if nothing was downloaded after it, since a later download
237
+ // can land inside the wildcard without ever being read.
238
+ const readAt = (segment, at) => segment.reads
239
+ && (byName(segment) || byGlob(segment) && !segments.slice(at + 1, send).some(later => later.downloads));
240
+ if (!segments.slice(0, send).some(readAt)) {
134
241
  problems.push(`${names.join(" or ")} was not read before it was sent`);
135
242
  }
136
243
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * The agent container's command for a U or X interview conversation, `node dist/eval/interview-guest-entry.js`, run
5
+ * only inside the eval sandbox: the neutral loop with one arm's tools, from the turn file the sandbox mounts at
6
+ * `/eval/turn.json`, its provider served by the host over stdin and stdout (see `interviews/guest/run.ts`). It takes
7
+ * no arguments, so it is no command an agent's shell is offered.
8
+ */
9
+ const identity_1 = require("../heart/identity");
10
+ const runtime_1 = require("../nerves/runtime");
11
+ const run_1 = require("./interviews/guest/run");
12
+ void (0, run_1.runInterviewGuest)({ stdin: process.stdin, stdout: process.stdout, turnFile: "/eval/turn.json", bundle: (0, identity_1.getAgentRoot)("sanctuary") }).then((outcome) => {
13
+ process.exit(outcome.ok ? 0 : 1);
14
+ }).catch((error) => {
15
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.interview_guest_entry_error", message: "interview guest failed outside its conversation", meta: { error: String(error) } });
16
+ process.exit(1);
17
+ });
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.APPENDIX_B_SHA256 = void 0;
7
+ exports.readAllocation = readAllocation;
8
+ exports.reducedDesign = reducedDesign;
9
+ /**
10
+ * The pre-registered allocation (Appendix B): every session's model, job and labelled arms in run order, read from
11
+ * the pre-registration file itself and refused unless its rows hash to the SHA-256 the file states (Appendix A), so a
12
+ * session can never run from an edited table.
13
+ */
14
+ const node_crypto_1 = __importDefault(require("node:crypto"));
15
+ const runtime_1 = require("../../nerves/runtime");
16
+ const protocol_1 = require("./protocol");
17
+ /** The SHA-256 of Appendix B's rows as the allocation script prints them, one per line. */
18
+ exports.APPENDIX_B_SHA256 = "ca0b441641c6c62e70238ee2b31b2283d358103d683061a97e0174f6c29851f2";
19
+ const ROW = /^\| ([HUX])-(\S+) \| (\S+) \| (\S+) \| (.+) \|$/;
20
+ function parseArms(product, cell, id) {
21
+ const arms = cell.split(", ").map((pair) => {
22
+ const [label, arm] = pair.split("=");
23
+ if (!label || !arm || !protocol_1.LABELS.includes(label) || !protocol_1.ARMS[product].includes(arm))
24
+ throw new Error(`session ${id}: ${pair} is not a label and one of ${product}'s arms`);
25
+ return { label, arm };
26
+ });
27
+ if (arms.length !== 3 || new Set(arms.map((a) => a.arm)).size !== 3 || new Set(arms.map((a) => a.label)).size !== 3)
28
+ throw new Error(`session ${id} must have three different labels and arms`);
29
+ return arms;
30
+ }
31
+ /** Every session of Appendix B in its order, from the pre-registration's text. */
32
+ function readAllocation(preregistration, expectedSha256 = exports.APPENDIX_B_SHA256) {
33
+ const start = preregistration.indexOf("## Appendix B");
34
+ const end = preregistration.indexOf("## Appendix C");
35
+ if (start < 0 || end < start)
36
+ throw new Error("the pre-registration has no Appendix B");
37
+ const rows = preregistration.slice(start, end).split("\n").filter((line) => /^\| [HUX]-/.test(line));
38
+ const sha = node_crypto_1.default.createHash("sha256").update(`${rows.join("\n")}\n`).digest("hex");
39
+ if (sha !== expectedSha256)
40
+ throw new Error(`Appendix B hashes to ${sha}, not the registered ${expectedSha256}; refusing to run from a changed allocation`);
41
+ const sessions = rows.map((line) => {
42
+ const match = ROW.exec(line);
43
+ if (!match)
44
+ throw new Error(`Appendix B row is malformed: ${line}`);
45
+ const product = match[1];
46
+ const id = `${product}-${match[2]}`;
47
+ return { id, product, model: match[3], job: match[4], arms: parseArms(product, match[5], id), pilot: match[2] === "pilot" };
48
+ });
49
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.interview_allocation_read", message: "read the pre-registered allocation", meta: { sessions: sessions.length } });
50
+ return sessions;
51
+ }
52
+ /**
53
+ * The reduced design (section 5): per model and product, only the sessions whose order is a rotation of the arm list
54
+ * (`ouro, alt1, alt2`, `alt1, alt2, ouro`, `alt2, ouro, alt1`). Pilot sessions are kept as they are.
55
+ */
56
+ function reducedDesign(sessions) {
57
+ return sessions.filter((session) => {
58
+ if (session.pilot)
59
+ return true;
60
+ const [a, b, c] = protocol_1.ARMS[session.product];
61
+ const order = session.arms.map((entry) => entry.arm).join(",");
62
+ return [[a, b, c], [b, c, a], [c, a, b]].some((rotation) => rotation.join(",") === order);
63
+ });
64
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.X_ARMS = void 0;
4
+ exports.booksAxCli = booksAxCli;
5
+ exports.buildArm = buildArm;
6
+ /**
7
+ * The three X arms (pre-registration section 2), each the same books operations (`operations.ts`) on the same books
8
+ * command (`books-core.ts`), presented three ways:
9
+ * - `ouro`: the operations defined once with `ax-command` from Ouro AX v1.3.445 (vendored unchanged in `./ax`, its
10
+ * imports without the `.ts` extension), offered as the kit's own MCP tools: `createMcpHandler`'s tools/list and
11
+ * tools/call, with its input checks, error shape and result text.
12
+ * - `mcp-plain`: the same operations as hand-written MCP tools, each with a description, an `inputSchema`, a text
13
+ * result and `isError` on failure.
14
+ * - `cli-shell`: a conventional `books` command line behind one `shell` tool (`cli-shell.ts`).
15
+ *
16
+ * The core's answer is the result in every arm, as JSON text in the two tool arms and as lines of text (or `--json`)
17
+ * on the command line. A core error is an error in every arm, with the core's message; none adds a fix the others lack.
18
+ */
19
+ const runtime_1 = require("../../../nerves/runtime");
20
+ const ax_command_1 = require("./ax/ax-command");
21
+ const mcp_1 = require("./ax/mcp");
22
+ const problem_1 = require("./ax/problem");
23
+ const books_core_1 = require("./books-core");
24
+ const cli_shell_1 = require("./cli-shell");
25
+ const operations_1 = require("./operations");
26
+ exports.X_ARMS = ["ouro", "mcp-plain", "cli-shell"];
27
+ const parseArgs = (args) => {
28
+ try {
29
+ const value = JSON.parse(args || "{}");
30
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ };
36
+ // ---- ouro: ax-command ------------------------------------------------------------------------------------------
37
+ const axArg = (param) => ({ name: param.name, description: param.description, required: param.required === true, ...(param.kind === "list" ? { rest: "list" } : {}) });
38
+ const axFlag = (param) => ({ type: param.kind === "flag" ? "boolean" : param.kind === "number" ? "number" : "string", description: param.description });
39
+ function axInput(op, input) {
40
+ const out = {};
41
+ for (const param of op.params) {
42
+ const value = input[param.name];
43
+ if (value !== undefined)
44
+ out[param.name] = Array.isArray(value) ? [...value] : value;
45
+ }
46
+ return out;
47
+ }
48
+ /** The books command line built with ax-command, one definition per operation. */
49
+ function booksAxCli(core) {
50
+ return (0, ax_command_1.defineCli)({
51
+ name: "books",
52
+ about: ["books: find, check, shelve and send the household's e-books."],
53
+ commands: operations_1.OPERATIONS.map((op) => (0, ax_command_1.defineCommand)({
54
+ name: op.words.join(" "),
55
+ summary: op.summary,
56
+ effect: "private",
57
+ readOnly: op.readOnly,
58
+ args: op.params.filter((p) => p.positional).map(axArg),
59
+ flags: Object.fromEntries(op.params.filter((p) => !p.positional).map((p) => [p.name, axFlag(p)])),
60
+ examples: [`books ${op.example}`],
61
+ output: "the books command's answer as JSON",
62
+ run: async (input) => {
63
+ const result = await core((0, operations_1.argvOf)(op, axInput(op, input)));
64
+ const error = (0, books_core_1.coreError)(result);
65
+ if (error !== null)
66
+ throw new problem_1.AxError({ code: "books-failed", exit: result.code === 2 ? 2 : 1, thing: op.words.join("_"), problem: error, fix: null });
67
+ return result.json;
68
+ },
69
+ })),
70
+ });
71
+ }
72
+ function axArm(core) {
73
+ const cli = booksAxCli(core);
74
+ const handle = (0, mcp_1.createMcpHandler)({ cli });
75
+ const byName = new Map(operations_1.OPERATIONS.map((op) => [op.words.join("_"), op]));
76
+ let id = 0;
77
+ return {
78
+ key: "ouro",
79
+ tools: (0, mcp_1.mcpTools)({ cli }).map((tool) => ({ name: tool.name, description: tool.description, parameters: tool.inputSchema })),
80
+ async call(name, args) {
81
+ id += 1;
82
+ const params = parseArgs(args) ?? { "": args };
83
+ const meta = { "io.modelcontextprotocol/protocolVersion": mcp_1.PROTOCOL_VERSIONS[0], "io.modelcontextprotocol/clientCapabilities": {} };
84
+ const reply = await handle({ jsonrpc: "2.0", id, method: "tools/call", params: { name, arguments: params, _meta: meta } });
85
+ return { text: reply.result.content.map((part) => part.text).join("\n"), isError: reply.result.isError };
86
+ },
87
+ operationOf(name, args) {
88
+ // Only what the kit would run: its own input check, so a call it refuses names no operation.
89
+ const op = byName.get(name);
90
+ const command = cli.commands.find((c) => c.name === op?.words.join(" "));
91
+ const params = parseArgs(args);
92
+ if (!op || !command || !params)
93
+ return null;
94
+ try {
95
+ return { op, input: axInput(op, (0, ax_command_1.checkInput)(cli, command, params)) };
96
+ }
97
+ catch {
98
+ return null;
99
+ }
100
+ },
101
+ };
102
+ }
103
+ // ---- mcp-plain: hand-written MCP tools ---------------------------------------------------------------------------
104
+ const PLAIN_NAMES = {
105
+ "search": "search_books", "get": "download_book", "check": "check_books", "text": "read_book_text", "library find": "find_in_library",
106
+ "library add": "add_to_library", "library remove": "remove_from_library", "library replace": "replace_in_library",
107
+ "send": "send_to_reader", "deliver": "deliver_books", "ledger": "show_history",
108
+ };
109
+ function plainSchema(op) {
110
+ const properties = {};
111
+ for (const param of op.params) {
112
+ const type = param.kind === "list" ? { type: "array", items: { type: "string" } } : param.kind === "flag" ? { type: "boolean" } : param.kind === "number" ? { type: param.name === "id" ? "integer" : "number" } : { type: "string" };
113
+ properties[param.name.replace(/-/g, "_")] = { ...type, description: param.description };
114
+ }
115
+ return { type: "object", properties, required: op.params.filter((p) => p.required).map((p) => p.name.replace(/-/g, "_")) };
116
+ }
117
+ function plainInput(op, params) {
118
+ const input = {};
119
+ for (const param of op.params) {
120
+ const key = param.name.replace(/-/g, "_");
121
+ const value = params[key];
122
+ if (value === undefined || value === null) {
123
+ if (param.required)
124
+ return `missing required argument: ${key}`;
125
+ continue;
126
+ }
127
+ const ok = param.kind === "list" ? Array.isArray(value) && value.every((v) => typeof v === "string") : param.kind === "flag" ? typeof value === "boolean" : param.kind === "number" ? typeof value === "number" : typeof value === "string";
128
+ if (!ok)
129
+ return `argument ${key} must be ${param.kind === "list" ? "an array of strings" : param.kind === "flag" ? "a boolean" : `a ${param.kind}`}`;
130
+ input[param.name] = value;
131
+ }
132
+ return input;
133
+ }
134
+ function mcpPlainArm(core) {
135
+ const byName = new Map(operations_1.OPERATIONS.map((op) => [PLAIN_NAMES[op.words.join(" ")], op]));
136
+ const resolve = (name, args) => {
137
+ const op = byName.get(name);
138
+ if (!op)
139
+ return { error: `Unknown tool: ${name}` };
140
+ const params = parseArgs(args);
141
+ if (!params)
142
+ return { error: "arguments must be a JSON object" };
143
+ const input = plainInput(op, params);
144
+ return typeof input === "string" ? { error: input } : { op, input };
145
+ };
146
+ return {
147
+ key: "mcp-plain",
148
+ tools: [...byName].map(([name, op]) => ({ name, description: op.summary, parameters: plainSchema(op) })),
149
+ async call(name, args) {
150
+ const resolved = resolve(name, args);
151
+ if ("error" in resolved)
152
+ return { text: resolved.error, isError: true };
153
+ const result = await core((0, operations_1.argvOf)(resolved.op, resolved.input));
154
+ const error = (0, books_core_1.coreError)(result);
155
+ return error !== null ? { text: error, isError: true } : { text: JSON.stringify(result.json), isError: false };
156
+ },
157
+ operationOf(name, args) {
158
+ const resolved = resolve(name, args);
159
+ return "error" in resolved ? null : resolved;
160
+ },
161
+ };
162
+ }
163
+ /** The X arm named `key`, on `core`. */
164
+ function buildArm(key, core) {
165
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.interview_arm_built", message: "built an X arm's tools", meta: { arm: key } });
166
+ if (key === "ouro")
167
+ return axArm(core);
168
+ if (key === "mcp-plain")
169
+ return mcpPlainArm(core);
170
+ if (key === "cli-shell")
171
+ return (0, cli_shell_1.cliShellArm)(core);
172
+ throw new Error(`no X arm ${key}; the arms are ${exports.X_ARMS.join(", ")}`);
173
+ }