@ouro.bot/cli 0.1.0-alpha.1504 → 0.1.0-alpha.1506
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/eval/interviews/guest/h/fidelity.js +19 -1
- package/dist/eval/interviews/guest/h/openhands.js +176 -0
- package/dist/eval/interviews/guest/h/run.js +2 -1
- package/dist/eval/interviews/guest/h/wire.js +80 -2
- package/dist/eval/sandbox/slugger-projection.js +95 -7
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
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.1506",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The H interview guest has an `openhands` arm: the OpenHands Software Agent SDK at the commit pre-registration v2 pins, with its terminal and file-editor tools, running its own agent loop in a Python supervisor on the H wire. The wire now also answers chat completions without streaming, which is how the SDK calls its model. The Butler's persona and the label line are the agent context's system message suffix, the bundle's skills are installed as user skills, and the SDK's retries are off. The job and each follow-up are messages in one conversation, and OpenHands' `finish` call is a turn's reply. `deploy/eval/build-openhands.sh` installs the SDK with its own lock file in a throwaway container, and `deploy/eval/openhands.Dockerfile` adds it and tmux to the eval's agent image."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1505",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Slugger's eval projection replaces each household name, handle or email it finds in a kept file with a fixed placeholder (\"Member A\", \"member-a@example.invalid\") instead of refusing the run, and reports only how many it replaced. Leak patterns now match whole words only (a name next to digits still matches), in the redaction and the leak lint alike; a file that isn't UTF-8 text is never rewritten, and is refused if it holds a pattern."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1504",
|
|
6
18
|
"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.1506</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* config against these notes by key name.
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.H_CODEX_FIDELITY = exports.H_OURO_FIDELITY = void 0;
|
|
8
|
+
exports.H_OPENHANDS_FIDELITY = exports.H_CODEX_FIDELITY = exports.H_OURO_FIDELITY = void 0;
|
|
9
9
|
/** Departures every H arm shares, and where the `ouro` arm still differs from the others. */
|
|
10
10
|
exports.H_OURO_FIDELITY = [
|
|
11
11
|
"no provider retries, as in every arm: each error from the host's runtime is marked not retryable, so a retry is never a second metered call",
|
|
@@ -32,3 +32,21 @@ exports.H_CODEX_FIDELITY = [
|
|
|
32
32
|
"codex is killed at 540 seconds, inside the host's 600-second guest deadline, and the turn reports that it exited 137; commands it started stop when the host removes the container at the guest's end",
|
|
33
33
|
"built from source at the pinned commit for x86_64 gnu (on the x86_64 sandbox host, which runs every session), not codex's released musl build, without the release's version stamp",
|
|
34
34
|
];
|
|
35
|
+
exports.H_OPENHANDS_FIDELITY = [
|
|
36
|
+
"num_retries = 0: LiteLLM's retries are off, since a retry would be a second metered call",
|
|
37
|
+
"the agent's tools are the terminal and the file editor, as pre-registration v2 names, plus the SDK's own finish tool and, when a skill is installed, its invoke_skill tool; the SDK's default preset also gives the task tracker and the browser, and the browser couldn't reach anything in the sandbox",
|
|
38
|
+
"no condenser: the default preset summarises a long history with extra model calls; these conversations are short",
|
|
39
|
+
"load_user_skills = True: the bundle's skills are installed as user skills and listed in the prompt's skills block, as codex lists them; the default preset loads none",
|
|
40
|
+
"the model is called through chat completions without streaming (api_mode chat, stream False), since the H wire answers chat only whole",
|
|
41
|
+
"the request's own settings (max_completion_tokens, prompt_cache_key) are not passed on: the host's runtime sets the model's settings, as it does for the ouro arm",
|
|
42
|
+
"the SDK doesn't know the model's name (openai/model), so it uses its defaults for an unknown model; LITELLM_LOCAL_MODEL_COST_MAP = True makes LiteLLM read the cost map it ships with instead of fetching one",
|
|
43
|
+
"the Butler's persona and the label line are the system message's suffix, after the SDK's own system prompt",
|
|
44
|
+
"the system prompt is the default preset's (system_prompt_kwargs cli_mode False), so its security-risk wording is the preset's, not the command line's",
|
|
45
|
+
"the brand words in the SDK's system prompt and tool descriptions are replaced before the call reaches the model",
|
|
46
|
+
"the shell can still show the brand: the tmux socket and session names in TMUX, the ~/.openhands folder, and the LITELLM_LOCAL_MODEL_COST_MAP variable; none is in the prompt. AI_AGENT is set to a neutral name, where the SDK would set its own",
|
|
47
|
+
"the SDK runs on the uv-managed Python 3.13 and uv 0.13.7 its own agent-server image uses, with bytecode compiled at build time because the image is read-only when the arm runs",
|
|
48
|
+
"runs from a neutral home under /tmp (the agent container is read-only elsewhere), with the bundle linked at /tmp/agent/AgentBundles/sanctuary.agent",
|
|
49
|
+
"the supervisor process is killed at 540 seconds, inside the host's 600-second guest deadline; the terminal's tmux and anything it started stop when the host removes the container at the guest's end",
|
|
50
|
+
"SHELL is /bin/bash: tmux runs its session through SHELL, and the image's user has no login shell to fall back on",
|
|
51
|
+
"the supervisor's stdout carries only its status lines; anything the SDK or LiteLLM prints goes to stderr",
|
|
52
|
+
];
|
|
@@ -0,0 +1,176 @@
|
|
|
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.openhandsArm = openhandsArm;
|
|
7
|
+
/**
|
|
8
|
+
* H's `openhands` arm (pre-registration v2 product H): the OpenHands Software Agent SDK at `ecea9a91d8d0` with its
|
|
9
|
+
* terminal and file-editor tools, its own agent loop unchanged, on the H wire's chat-completions route as its only
|
|
10
|
+
* provider. Every call goes through the wire to the host's runtime, so the host still rewrites, scans, gates and
|
|
11
|
+
* meters it.
|
|
12
|
+
*
|
|
13
|
+
* What stays the same as in every arm: the Butler's persona and the label line (here the agent context's system
|
|
14
|
+
* message suffix, after the SDK's own system prompt), the case's conversation (put before the job by the wire), the
|
|
15
|
+
* bundle's skills (installed as user skills, which the SDK loads), the books command line and the household.
|
|
16
|
+
*
|
|
17
|
+
* One conversation runs in a Python supervisor (`deploy/eval/openhands/supervise.py`), given one message at a time:
|
|
18
|
+
* the job, then each follow-up as the owner's next message. OpenHands ends a turn with its `finish` tool, whose
|
|
19
|
+
* message is the turn's reply, so the trace shows it as one. The SDK's retries are off, since a retried call would
|
|
20
|
+
* be metered twice. It runs in the same neutral home and workdir as the codex arm.
|
|
21
|
+
*/
|
|
22
|
+
const node_child_process_1 = require("node:child_process");
|
|
23
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
24
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
25
|
+
const runtime_1 = require("../../../../nerves/runtime");
|
|
26
|
+
const loop_1 = require("../loop");
|
|
27
|
+
const run_1 = require("../run");
|
|
28
|
+
const codex_1 = require("./codex");
|
|
29
|
+
const wire_1 = require("./wire");
|
|
30
|
+
/** Where the arm's image installs the SDK and the supervisor, under a path with no brand word. */
|
|
31
|
+
const SDK_DIR = "/opt/agent-sdk";
|
|
32
|
+
/* v8 ignore start -- process wiring: what the arm does with the supervisor's lines and exit is tested with an injected supervisor @preserve */
|
|
33
|
+
const startPython = (specFile, options) => {
|
|
34
|
+
const child = (0, node_child_process_1.spawn)(node_path_1.default.join(SDK_DIR, "venv/bin/python"), [node_path_1.default.join(SDK_DIR, "supervise.py"), specFile], { cwd: options.cwd, env: options.env, stdio: ["pipe", "pipe", "pipe"] });
|
|
35
|
+
let stderr = "";
|
|
36
|
+
let buffered = "";
|
|
37
|
+
const lines = [];
|
|
38
|
+
let waiting = null;
|
|
39
|
+
let ended = false;
|
|
40
|
+
const exited = new Promise((resolve) => {
|
|
41
|
+
child.on("error", (error) => { stderr += `${error.message}\n`; resolve(127); });
|
|
42
|
+
child.on("close", (code) => resolve(code ?? 137));
|
|
43
|
+
});
|
|
44
|
+
child.stderr.on("data", (chunk) => { stderr += chunk.toString("utf8"); });
|
|
45
|
+
// A supervisor that died between turns breaks the pipe; its exit says why, so the write's error is not thrown.
|
|
46
|
+
child.stdin.on("error", () => undefined);
|
|
47
|
+
child.stdout.on("data", (chunk) => {
|
|
48
|
+
buffered += chunk.toString("utf8");
|
|
49
|
+
let at;
|
|
50
|
+
while ((at = buffered.indexOf("\n")) >= 0) {
|
|
51
|
+
const line = buffered.slice(0, at);
|
|
52
|
+
buffered = buffered.slice(at + 1);
|
|
53
|
+
if (waiting) {
|
|
54
|
+
const take = waiting;
|
|
55
|
+
waiting = null;
|
|
56
|
+
take(line);
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
lines.push(line);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
void exited.then(() => { ended = true; if (waiting) {
|
|
63
|
+
const take = waiting;
|
|
64
|
+
waiting = null;
|
|
65
|
+
take(null);
|
|
66
|
+
} });
|
|
67
|
+
const next = () => lines.length > 0 ? Promise.resolve(lines.shift()) : ended ? Promise.resolve(null) : new Promise((resolve) => { waiting = resolve; });
|
|
68
|
+
// Inside the host's 600-second guest deadline, so a stuck supervisor ends as this arm's failure, not the guest's.
|
|
69
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), 540_000);
|
|
70
|
+
return {
|
|
71
|
+
send: async (message) => {
|
|
72
|
+
if (!ended)
|
|
73
|
+
child.stdin.write(`${JSON.stringify(message)}\n`);
|
|
74
|
+
const line = await next();
|
|
75
|
+
if (line === null)
|
|
76
|
+
return null;
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(line);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { error: `the supervisor printed ${line.slice(0, 200)}` };
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
close: async () => {
|
|
85
|
+
child.stdin.end();
|
|
86
|
+
const code = await exited;
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
return { code, stderr };
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/* v8 ignore stop */
|
|
93
|
+
const lastLine = (text) => text.trim().split("\n").at(-1).trim();
|
|
94
|
+
/** The message of a `finish` call: its `message` argument, or its arguments as they are. */
|
|
95
|
+
function finishMessage(args) {
|
|
96
|
+
try {
|
|
97
|
+
const message = JSON.parse(args).message;
|
|
98
|
+
if (typeof message === "string")
|
|
99
|
+
return message;
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Not JSON: the arguments are the message.
|
|
103
|
+
}
|
|
104
|
+
return args;
|
|
105
|
+
}
|
|
106
|
+
function openhandsArm(options = {}) {
|
|
107
|
+
const start = options.start ?? startPython;
|
|
108
|
+
const home = options.home ?? codex_1.CODEX_HOME_DIR;
|
|
109
|
+
const workdir = options.workdir ?? node_path_1.default.join(home, "AgentBundles", "sanctuary.agent");
|
|
110
|
+
return async ({ turn, bundle, providerRuntime }) => {
|
|
111
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(workdir), { recursive: true });
|
|
112
|
+
if (!node_fs_1.default.existsSync(workdir))
|
|
113
|
+
node_fs_1.default.symlinkSync(bundle, workdir);
|
|
114
|
+
(0, codex_1.installSkills)(bundle, home);
|
|
115
|
+
const wire = (0, wire_1.createWire)({ runtime: providerRuntime, prefix: turn.prefix });
|
|
116
|
+
const served = await (0, wire_1.serveWire)(wire);
|
|
117
|
+
try {
|
|
118
|
+
const specFile = node_path_1.default.join(home, ".arm-spec.json");
|
|
119
|
+
node_fs_1.default.writeFileSync(specFile, JSON.stringify({ baseUrl: served.url, workdir, systemSuffix: `${(0, run_1.personaPrompt)(bundle)}\n\n${turn.labelLine}` }));
|
|
120
|
+
// The SDK reads the model cost map it ships with rather than fetching one; the container has no route out.
|
|
121
|
+
// The terminal's tmux keeps the neutral workdir as given; PWD keeps it too if the SDK falls back to a plain shell.
|
|
122
|
+
// AI_AGENT is set to a neutral name, since the SDK otherwise puts its own brand there for the shell. SHELL is
|
|
123
|
+
// bash because tmux runs its session through SHELL, and the image's user has no login shell to fall back on.
|
|
124
|
+
const supervisor = start(specFile, { cwd: workdir, env: { HOME: home, PWD: workdir, PATH: process.env.PATH, SHELL: "/bin/bash", LITELLM_LOCAL_MODEL_COST_MAP: "True", AI_AGENT: "agent" } });
|
|
125
|
+
// OpenHands' `finish` call is the turn's reply.
|
|
126
|
+
const traced = () => wire.timeline().map((entry) => entry.kind === "call" && entry.name === "finish"
|
|
127
|
+
? { kind: "reply", text: (0, loop_1.withoutThinking)(finishMessage(entry.args)) }
|
|
128
|
+
: entry.kind === "reply" ? { kind: "reply", text: (0, loop_1.withoutThinking)(entry.text) } : entry);
|
|
129
|
+
const turns = [];
|
|
130
|
+
let closed = null;
|
|
131
|
+
// The supervisor is closed however the turns end, so Python never outlives the arm.
|
|
132
|
+
try {
|
|
133
|
+
for (const [index, text] of [turn.userText, ...turn.followUps].entries()) {
|
|
134
|
+
const record = { start: traced().length, finalReply: "", outcome: "settled", calls: 0 };
|
|
135
|
+
turns.push(record);
|
|
136
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.h_openhands_turn_start", message: "openhands is taking a turn", meta: { index } });
|
|
137
|
+
const callsBefore = wire.calls();
|
|
138
|
+
const line = await supervisor.send(text);
|
|
139
|
+
record.calls = wire.calls() - callsBefore;
|
|
140
|
+
const reply = traced().slice(record.start).filter((entry) => entry.kind === "reply").at(-1);
|
|
141
|
+
if (reply)
|
|
142
|
+
record.finalReply = reply.text;
|
|
143
|
+
// A failed call ends the conversation, so any failure the wire remembers is this turn's.
|
|
144
|
+
const failure = wire.error();
|
|
145
|
+
if (failure !== null) {
|
|
146
|
+
record.outcome = `provider-error: ${failure}`;
|
|
147
|
+
}
|
|
148
|
+
else if (line === null) {
|
|
149
|
+
closed = await supervisor.close();
|
|
150
|
+
record.outcome = `harness-error: openhands exited ${closed.code}${closed.stderr.trim() ? `: ${lastLine(closed.stderr)}` : ""}`;
|
|
151
|
+
}
|
|
152
|
+
else if (line.error !== undefined) {
|
|
153
|
+
record.outcome = `harness-error: openhands failed: ${line.error}`;
|
|
154
|
+
}
|
|
155
|
+
else if (line.status !== "finished") {
|
|
156
|
+
record.outcome = `harness-error: openhands stopped the turn ${line.status}`;
|
|
157
|
+
}
|
|
158
|
+
else if (!reply) {
|
|
159
|
+
record.outcome = "harness-error: openhands ended the turn with no reply";
|
|
160
|
+
}
|
|
161
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.h_openhands_turn_end", message: "openhands ended a turn", meta: { index, outcome: record.outcome, calls: record.calls } });
|
|
162
|
+
if (record.outcome !== "settled")
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
if (!closed)
|
|
168
|
+
await supervisor.close();
|
|
169
|
+
}
|
|
170
|
+
return { timeline: traced(), finalReply: turns[0].finalReply, outcome: turns[0].outcome, steps: wire.calls(), turns };
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await served.close();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
@@ -21,6 +21,7 @@ const runtime_1 = require("../../../../nerves/runtime");
|
|
|
21
21
|
const provider_proxy_1 = require("../../../transport/provider-proxy");
|
|
22
22
|
const telegram_turn_1 = require("../../../transport/telegram-turn");
|
|
23
23
|
const codex_1 = require("./codex");
|
|
24
|
+
const openhands_1 = require("./openhands");
|
|
24
25
|
/** The ouro arm: the harness's own turn, unchanged but for the label line and the later message. */
|
|
25
26
|
function ouroArm(runTurn = telegram_turn_1.runTelegramTurn) {
|
|
26
27
|
return ({ turn, bundle, providerRuntime }) => runTurn({
|
|
@@ -28,7 +29,7 @@ function ouroArm(runTurn = telegram_turn_1.runTelegramTurn) {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
/** The H arms this guest runs. */
|
|
31
|
-
exports.H_ARMS = { ouro: ouroArm(), codex: (0, codex_1.codexArm)() };
|
|
32
|
+
exports.H_ARMS = { ouro: ouroArm(), codex: (0, codex_1.codexArm)(), openhands: (0, openhands_1.openhandsArm)() };
|
|
32
33
|
function readTurnFile(file) {
|
|
33
34
|
const value = JSON.parse(node_fs_1.default.readFileSync(file, "utf8"));
|
|
34
35
|
if (value.product !== "H" || typeof value.arm !== "string" || typeof value.labelLine !== "string" || !Array.isArray(value.prefix)
|
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkToolFields = checkToolFields;
|
|
7
7
|
exports.responsesRequest = responsesRequest;
|
|
8
|
+
exports.chatRequest = chatRequest;
|
|
9
|
+
exports.chatAnswer = chatAnswer;
|
|
8
10
|
exports.responsesEvents = responsesEvents;
|
|
9
11
|
exports.sse = sse;
|
|
10
12
|
exports.createWire = createWire;
|
|
@@ -180,6 +182,79 @@ function responsesRequest(body, prefix) {
|
|
|
180
182
|
const activeTools = wireTools(tools);
|
|
181
183
|
return { messages: [...(leading.length > 0 ? [{ role: "system", content: leading.join("\n\n") }] : []), ...rest], activeTools };
|
|
182
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* A chat-completions body as the harness's request: its messages as they are, with text-only content made plain, a
|
|
187
|
+
* developer message as a system message, and the case's conversation before the first user message. Streaming is
|
|
188
|
+
* refused: the clients the wire serves this way (openhands) ask for one whole answer.
|
|
189
|
+
*/
|
|
190
|
+
const CHAT_FIELDS = new Set(["model", "messages", "tools", "stream", "max_completion_tokens", "prompt_cache_key"]);
|
|
191
|
+
function chatRequest(body, prefix) {
|
|
192
|
+
if (!isRecord(body) || !Array.isArray(body.messages))
|
|
193
|
+
throw new Error("a chat body needs a messages list");
|
|
194
|
+
if (body.stream === true)
|
|
195
|
+
throw new Error("the H wire answers chat completions only without streaming");
|
|
196
|
+
// The request settings the arm may send, which the host's runtime sets instead (a fidelity note); any other field
|
|
197
|
+
// is refused by name, never dropped unseen.
|
|
198
|
+
for (const key of Object.keys(body))
|
|
199
|
+
if (!CHAT_FIELDS.has(key))
|
|
200
|
+
throw new Error(`the H wire can't carry a chat request's ${key}`);
|
|
201
|
+
const messages = [];
|
|
202
|
+
let prefixed = false;
|
|
203
|
+
for (const item of body.messages) {
|
|
204
|
+
const value = isRecord(item) ? item : {};
|
|
205
|
+
const role = String(value.role);
|
|
206
|
+
if (role === "system" || role === "developer") {
|
|
207
|
+
messages.push({ role: "system", content: textOf(value.content) });
|
|
208
|
+
}
|
|
209
|
+
else if (role === "user") {
|
|
210
|
+
if (!prefixed)
|
|
211
|
+
messages.push(...prefix);
|
|
212
|
+
prefixed = true;
|
|
213
|
+
messages.push({ role: "user", content: textOf(value.content) });
|
|
214
|
+
}
|
|
215
|
+
else if (role === "assistant") {
|
|
216
|
+
const calls = Array.isArray(value.tool_calls) ? value.tool_calls : [];
|
|
217
|
+
messages.push({
|
|
218
|
+
role: "assistant", content: value.content === null || value.content === undefined ? null : textOf(value.content),
|
|
219
|
+
...(calls.length > 0 ? { tool_calls: calls.map((call) => ({ id: String(call.id), type: "function", function: { name: String(call.function.name), arguments: String(call.function.arguments) } })) } : {}),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else if (role === "tool") {
|
|
223
|
+
messages.push({ role: "tool", tool_call_id: String(value.tool_call_id), content: textOf(value.content) });
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw new Error(`the H wire can't carry a message from ${role}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const tools = Array.isArray(body.tools) ? body.tools : [];
|
|
230
|
+
// A chat tool nests the same fields under `function`; they pass through as the Responses shape's do.
|
|
231
|
+
for (const tool of tools) {
|
|
232
|
+
if (typeOf(tool) !== "function")
|
|
233
|
+
throw new Error(`the H wire can't carry a tool of type ${typeOf(tool)}`);
|
|
234
|
+
const { function: fields, ...outer } = tool;
|
|
235
|
+
if (!isRecord(fields))
|
|
236
|
+
throw new Error("a chat tool needs its function");
|
|
237
|
+
checkToolFields({ ...outer, ...fields });
|
|
238
|
+
}
|
|
239
|
+
const activeTools = wireTools(tools.map((tool) => tool.function));
|
|
240
|
+
return { messages, activeTools };
|
|
241
|
+
}
|
|
242
|
+
/** One chat completion for an answer: the reply, its calls, why it stopped and the usage. */
|
|
243
|
+
function chatAnswer(result, id) {
|
|
244
|
+
const usage = result.usage;
|
|
245
|
+
const message = {
|
|
246
|
+
role: "assistant", content: result.content,
|
|
247
|
+
...(result.toolCalls.length > 0 ? { tool_calls: result.toolCalls.map((call) => ({ id: call.id, type: "function", function: { name: call.name, arguments: call.arguments } })) } : {}),
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
id, object: "chat.completion", created: 0, model: "model",
|
|
251
|
+
choices: [{ index: 0, finish_reason: result.toolCalls.length > 0 ? "tool_calls" : "stop", message }],
|
|
252
|
+
usage: {
|
|
253
|
+
prompt_tokens: usage?.input_tokens ?? 0, completion_tokens: usage?.output_tokens ?? 0, total_tokens: usage?.total_tokens ?? 0,
|
|
254
|
+
prompt_tokens_details: { cached_tokens: usage?.cached_input_tokens ?? 0 }, completion_tokens_details: { reasoning_tokens: usage?.reasoning_tokens ?? 0 },
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
183
258
|
/** The events a Responses client reads for one answer: created, each output item done, then completed with usage. */
|
|
184
259
|
function responsesEvents(result, id) {
|
|
185
260
|
const usage = result.usage;
|
|
@@ -214,11 +289,12 @@ function createWire(input) {
|
|
|
214
289
|
calls: () => calls,
|
|
215
290
|
error: () => failure,
|
|
216
291
|
async handle(route, body) {
|
|
217
|
-
|
|
292
|
+
const chat = route === "/v1/chat/completions" || route === "/chat/completions";
|
|
293
|
+
if (!chat && route !== "/v1/responses" && route !== "/responses")
|
|
218
294
|
return errorAnswer(404, `no route ${route}`);
|
|
219
295
|
let request;
|
|
220
296
|
try {
|
|
221
|
-
request = responsesRequest(body, input.prefix);
|
|
297
|
+
request = chat ? chatRequest(body, input.prefix) : responsesRequest(body, input.prefix);
|
|
222
298
|
}
|
|
223
299
|
catch (error) {
|
|
224
300
|
failure = (0, loop_1.messageOf)(error);
|
|
@@ -256,6 +332,8 @@ function createWire(input) {
|
|
|
256
332
|
if (result.toolCalls.length === 0)
|
|
257
333
|
timeline.push({ kind: "reply", text: result.content });
|
|
258
334
|
responses += 1;
|
|
335
|
+
if (chat)
|
|
336
|
+
return { status: 200, contentType: "application/json", body: JSON.stringify(chatAnswer(result, `chat_${responses}`)) };
|
|
259
337
|
return { status: 200, contentType: "text/event-stream", body: sse(responsesEvents(result, `resp_${responses}`)) };
|
|
260
338
|
},
|
|
261
339
|
};
|
|
@@ -8,6 +8,8 @@ exports.archiveBundle = archiveBundle;
|
|
|
8
8
|
exports.removeArchive = removeArchive;
|
|
9
9
|
exports.projectAgentConfig = projectAgentConfig;
|
|
10
10
|
exports.readLeakPatterns = readLeakPatterns;
|
|
11
|
+
exports.placeholder = placeholder;
|
|
12
|
+
exports.redact = redact;
|
|
11
13
|
exports.leakLint = leakLint;
|
|
12
14
|
exports.projectSlugger = projectSlugger;
|
|
13
15
|
exports.sluggerProfile = sluggerProfile;
|
|
@@ -25,11 +27,17 @@ exports.sluggerProfile = sluggerProfile;
|
|
|
25
27
|
* dot-file and dot-folder (`.git`, `.backup/`, ...) and every symbolic link.
|
|
26
28
|
* - **Created empty:** every path Slugger's profile may write, so `books/` too, where the sandbox writes the books
|
|
27
29
|
* CLI's synthetic settings.
|
|
28
|
-
* - **Leak
|
|
30
|
+
* - **Leak patterns.** The household's names, handles, emails and addresses are kept in his private bundle at
|
|
29
31
|
* `eval/leak-patterns.json` (`{ "literals": [...] }`) and never committed to the harness. They are read from the
|
|
30
|
-
* same commit as the rest, so an older commit is checked against the list it had then.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
32
|
+
* same commit as the rest, so an older commit is checked against the list it had then. A pattern matches in any case
|
|
33
|
+
* and as a whole word only: not inside a longer run of letters (digits don't count, so `name99` matches). One with a
|
|
34
|
+
* letter outside basic Latin matches anywhere (see `wordPattern`).
|
|
35
|
+
* - **Redaction.** Every match in a copied file's contents is replaced with a placeholder fixed by the pattern's place
|
|
36
|
+
* in the list, the same in every file: "Member A", "Member B", ..., or "member-a@example.invalid" for a pattern
|
|
37
|
+
* holding `@`, or "@member-a" for a handle starting with it. Longer patterns are replaced first. A gap gives only how many strings and files were replaced.
|
|
38
|
+
* - **Leak lint.** After redaction the patterns are matched again against every projected file's and folder's name,
|
|
39
|
+
* every file's contents and every gap, before any model call. A match, or no pattern file, stops the projection and
|
|
40
|
+
* removes it; the error gives counts only, never a match.
|
|
33
41
|
* `git archive` follows the bundle repository's `export-ignore` and `export-subst` attributes; a top-level entry left
|
|
34
42
|
* out that way fails the archive's completeness check.
|
|
35
43
|
* What differs from the live bundle comes back as `gaps`, which every report lists.
|
|
@@ -204,10 +212,85 @@ function readLeakPatterns(archiveDir) {
|
|
|
204
212
|
}
|
|
205
213
|
return literals.map((literal) => literal.trim().toLowerCase());
|
|
206
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* A pattern in any case, as a whole word: not next to another letter, so a name inside a longer word is no match, but
|
|
217
|
+
* a handle next to digits (`name99`) is. Words in a pattern match across any run of spaces or line breaks. A pattern
|
|
218
|
+
* with a letter outside basic Latin matches anywhere, since scripts such as Japanese don't separate words and Hebrew
|
|
219
|
+
* joins prefixes to names.
|
|
220
|
+
*/
|
|
221
|
+
function wordPattern(pattern) {
|
|
222
|
+
const body = pattern.split(/\s+/).map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("\\s+");
|
|
223
|
+
if (/[^\p{ASCII}]/u.test(pattern))
|
|
224
|
+
return new RegExp(body, "giu");
|
|
225
|
+
return new RegExp(`(?<![\\p{L}\\p{M}])${body}(?![\\p{L}\\p{M}])`, "giu");
|
|
226
|
+
}
|
|
227
|
+
const holdsAny = (text, patterns) => patterns.some((pattern) => wordPattern(pattern).test(text));
|
|
228
|
+
/**
|
|
229
|
+
* The placeholder for the pattern at `index`: "Member A" to "Member Z", then "Member AA"; an email's is an address
|
|
230
|
+
* and a handle's (`@name`) a handle. A pattern such as `member` or `example` would match its own placeholder, which the
|
|
231
|
+
* second lint then refuses.
|
|
232
|
+
*/
|
|
233
|
+
function placeholder(index, pattern) {
|
|
234
|
+
let letters = "";
|
|
235
|
+
for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26))
|
|
236
|
+
letters = String.fromCharCode(65 + ((n - 1) % 26)) + letters;
|
|
237
|
+
if (pattern.startsWith("@"))
|
|
238
|
+
return `@member-${letters.toLowerCase()}`;
|
|
239
|
+
return pattern.includes("@") ? `member-${letters.toLowerCase()}@example.invalid` : `Member ${letters}`;
|
|
240
|
+
}
|
|
241
|
+
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
242
|
+
function filesUnder(root) {
|
|
243
|
+
const found = [];
|
|
244
|
+
const walk = (relative) => {
|
|
245
|
+
const full = node_path_1.default.join(root, relative);
|
|
246
|
+
if (node_fs_1.default.lstatSync(full).isDirectory())
|
|
247
|
+
for (const name of node_fs_1.default.readdirSync(full).sort())
|
|
248
|
+
walk(relative ? node_path_1.default.posix.join(relative, name) : name);
|
|
249
|
+
else
|
|
250
|
+
found.push(relative);
|
|
251
|
+
};
|
|
252
|
+
walk("");
|
|
253
|
+
return found;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Replaces every match in the contents of each file under `root` with its pattern's placeholder. A file that isn't
|
|
257
|
+
* UTF-8 text is left as it is, so the lint after this refuses it if it holds a pattern.
|
|
258
|
+
*/
|
|
259
|
+
function redact(root, patterns) {
|
|
260
|
+
const order = patterns.map((pattern, index) => ({ pattern, index })).sort((a, b) => b.pattern.length - a.pattern.length || a.index - b.index);
|
|
261
|
+
let strings = 0;
|
|
262
|
+
let files = 0;
|
|
263
|
+
for (const relative of filesUnder(root)) {
|
|
264
|
+
const full = node_path_1.default.join(root, relative);
|
|
265
|
+
let text;
|
|
266
|
+
try {
|
|
267
|
+
text = utf8.decode(node_fs_1.default.readFileSync(full));
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
let here = 0;
|
|
273
|
+
for (const { pattern, index } of order) {
|
|
274
|
+
text = text.replace(wordPattern(pattern), () => { here += 1; return placeholder(index, pattern); });
|
|
275
|
+
}
|
|
276
|
+
if (here > 0) {
|
|
277
|
+
// A failed write's error names the file, whose path the lint hasn't checked yet.
|
|
278
|
+
try {
|
|
279
|
+
node_fs_1.default.writeFileSync(full, text);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
refuse("a projected file couldn't be rewritten with placeholders");
|
|
283
|
+
}
|
|
284
|
+
strings += here;
|
|
285
|
+
files += 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return { strings, files };
|
|
289
|
+
}
|
|
207
290
|
/** Every file or folder under `root` whose path, or a file's contents, holds a pattern, by its path relative to `root`. */
|
|
208
291
|
function leakLint(root, patterns) {
|
|
209
292
|
const flagged = [];
|
|
210
|
-
const holds = (text) =>
|
|
293
|
+
const holds = (text) => holdsAny(text, patterns);
|
|
211
294
|
const walk = (relative) => {
|
|
212
295
|
const full = node_path_1.default.join(root, relative);
|
|
213
296
|
if (node_fs_1.default.lstatSync(full).isDirectory()) {
|
|
@@ -237,6 +320,7 @@ function projectSlugger(input) {
|
|
|
237
320
|
const patterns = readLeakPatterns(input.archive);
|
|
238
321
|
node_fs_1.default.mkdirSync(input.out, { recursive: true, mode: 0o755 });
|
|
239
322
|
const gaps = [];
|
|
323
|
+
let redactedStrings = 0;
|
|
240
324
|
try {
|
|
241
325
|
for (const include of input.include.filter((each) => each !== "agent.json")) {
|
|
242
326
|
const parts = include.split("/");
|
|
@@ -267,8 +351,12 @@ function projectSlugger(input) {
|
|
|
267
351
|
node_fs_1.default.mkdirSync(node_path_1.default.join(input.out, dir), { recursive: true });
|
|
268
352
|
node_fs_1.default.writeFileSync(node_path_1.default.join(input.out, "books/ledger.ndjson"), "");
|
|
269
353
|
gaps.push("psyche/TACIT.md and psyche/memory: left out", "friends, state, arc, desk and books: start empty", "browser: left out");
|
|
354
|
+
const redacted = redact(input.out, patterns);
|
|
355
|
+
redactedStrings = redacted.strings;
|
|
356
|
+
if (redacted.strings > 0)
|
|
357
|
+
gaps.push(`${redacted.strings} private strings replaced with placeholders in ${redacted.files} ${redacted.files === 1 ? "file" : "files"}`);
|
|
270
358
|
// Gaps go into every report, so they are checked like the files are.
|
|
271
|
-
const flagged = leakLint(input.out, patterns).length + gaps.filter((gap) =>
|
|
359
|
+
const flagged = leakLint(input.out, patterns).length + gaps.filter((gap) => holdsAny(gap, patterns)).length;
|
|
272
360
|
if (flagged > 0)
|
|
273
361
|
refuse(`${flagged} projected path(s) or gap(s) hold a leak pattern; nothing was run`);
|
|
274
362
|
}
|
|
@@ -276,7 +364,7 @@ function projectSlugger(input) {
|
|
|
276
364
|
node_fs_1.default.rmSync(input.out, { recursive: true, force: true });
|
|
277
365
|
throw error;
|
|
278
366
|
}
|
|
279
|
-
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.slugger_projection", message: "projected Slugger's bundle", meta: { gaps: gaps.length } });
|
|
367
|
+
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.slugger_projection", message: "projected Slugger's bundle", meta: { gaps: gaps.length, redacted: redactedStrings } });
|
|
280
368
|
return { gaps };
|
|
281
369
|
}
|
|
282
370
|
/** Slugger's profile for a run on an archive `archiveBundle` made; the caller removes the archive afterwards. */
|
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.1506",
|
|
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.1506",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1506",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|