@ouro.bot/cli 0.1.0-alpha.1286 → 0.1.0-alpha.1288

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 CHANGED
@@ -1,6 +1,18 @@
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.1288",
6
+ "changes": [
7
+ "The replay eval can run one owner Telegram turn in-process through the real Telegram sense, shared turn runner, Sanctuary answer checks and tool dispatch, with an injected provider that is never retried and a fake Telegram transport, and read back the tool calls, the whole reply as the person reads it, the outcome and the model-call count."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1287",
12
+ "changes": [
13
+ "Update the Ouro UI files to Ouro UI v1.3.414."
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1286",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1286",
2
+ "runtimeVersion": "0.1.0-alpha.1288",
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.1286</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1288</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,208 @@
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.recordModelTraffic = recordModelTraffic;
7
+ exports.runTelegramTurn = runTelegramTurn;
8
+ /**
9
+ * Runs one owner Telegram turn through the production path, in-process, with an injected provider: the real
10
+ * Telegram sense (`createTelegramSenseApp`), the shared turn runner and `handleInboundTurn`, the production owner
11
+ * relationship (`createProductionTelegramRelationshipComposition`, which reads `tool-profiles.json`), the Sanctuary
12
+ * answer checks at settle, real tool dispatch, and a fake Telegram transport that records what the Butler sent.
13
+ *
14
+ * Run it only inside the eval sandbox. The owner profile offers `shell`, `fetch_url`, `web_search`, `bundle_push`
15
+ * and `send_message`, and in the process that runs the turn those tools are real.
16
+ *
17
+ * What the pipeline needed, found by running it (slice 2's spike):
18
+ * - The bundle must sit where the turn itself looks for it, `$HOME/AgentBundles/sanctuary.ouro`: the Telegram sense
19
+ * takes a root, but the shared turn runner re-derives it from `HOME`, so a bundle anywhere else splits the session
20
+ * in two. The container sets `HOME=/home/ouro`; the test points `HOME` at a temporary folder.
21
+ * - One owner Friend with the `sanctuary-owner` profile, bound to the fake bot and private chat, and the case prefix
22
+ * saved as that owner's Telegram session. Both are written here. The Telegram identity key is created in the
23
+ * bundle's state on first use, as on a fresh host.
24
+ * - `skipKeptNotes`, so the kept-notes judge does not ask for a provider of its own, and `providerRuntimeOverride`,
25
+ * which also empties the fallback chain. Both reach `runAgent` through the turn's `prepareRunAgentOptions` hook,
26
+ * after the relationship authorization is attached.
27
+ * - No retry of a provider error. Core retries an error unless it says `retryable: false`, and each retry refreshes
28
+ * the agent's credentials and rebuilds its runtime from `agent.json`, dropping the override. Every error from the
29
+ * injected runtime is marked not retryable, so a turn makes one call per step and never reaches a real provider.
30
+ * - Nothing from the live host. The Sanctuary service context (Unraid, SABnzbd, Jellyfin) is left out, so those tools
31
+ * are not offered; the local interactive-control socket is not opened.
32
+ *
33
+ * What the turn writes in the bundle: `friends/eval-owner.json`, the session under `state/sessions/`, the identity
34
+ * key and other runtime state under `state/`, and the flight recorder under `arc/`. A bundle runs one turn: the
35
+ * message ids are fixed, so a second run on the same bundle fails. Bundle sync is on in `agent.json` and does
36
+ * nothing only because the bundle is not a Git repository; a projection must not carry `.git`.
37
+ *
38
+ * Fidelity gaps:
39
+ * - The message goes straight to the sense's message handler, skipping the long poll's update parsing, its user and
40
+ * chat filter and the inbox. Friend resolution and relationship authorization still run.
41
+ * - A question about whether a title is on the shelf brings in the media-catalog contract, which requires
42
+ * `media_search`; with no Jellyfin context that tool is not offered and the turn fails. The books cases do not ask
43
+ * one.
44
+ * - The owner's prompt does not list `skills/`: the relationship prompt has no skills section and `load_skill` is not
45
+ * in the `sanctuary-owner` profile, so a skill file reaches the model only when the agent reads it with a tool.
46
+ * - Replies are read back as text: Telegram's HTML is decoded, and a message with buttons is not part of the answer.
47
+ * Files sent with `send_file` appear only as the tool call.
48
+ */
49
+ const node_fs_1 = __importDefault(require("node:fs"));
50
+ const node_path_1 = __importDefault(require("node:path"));
51
+ const friends_1 = require("@ouro.bot/friends");
52
+ const identity_1 = require("../../heart/identity");
53
+ const context_1 = require("../../mind/context");
54
+ const runtime_1 = require("../../nerves/runtime");
55
+ const sanctuary_runtime_1 = require("../../senses/sanctuary-runtime");
56
+ const shared_turn_1 = require("../../senses/shared-turn");
57
+ const telegram_1 = require("../../senses/telegram");
58
+ const telegram_identity_key_1 = require("../../senses/telegram-identity-key");
59
+ const AGENT = "sanctuary";
60
+ const BOT_ID = "7001";
61
+ const OWNER_USER = "4242";
62
+ const OWNER_FRIEND_ID = "eval-owner";
63
+ async function writeOwner(agentRoot) {
64
+ const now = new Date().toISOString();
65
+ await new friends_1.FileFriendStore(node_path_1.default.join(agentRoot, "friends")).put(OWNER_FRIEND_ID, {
66
+ id: OWNER_FRIEND_ID, name: "Ari", trustLevel: "family", admissionState: "active", initiativePolicy: "proactive",
67
+ capabilityProfileId: "sanctuary-owner",
68
+ externalIds: [{ provider: "telegram-user", externalId: OWNER_USER, tenantId: BOT_ID, linkedAt: now }],
69
+ tenantMemberships: [], toolPreferences: {}, notes: {}, totalTokens: 0, createdAt: now, updatedAt: now, schemaVersion: 1,
70
+ });
71
+ }
72
+ /**
73
+ * Wraps a runtime to record the turn's tool calls in the order the model made them, each filled with the result the
74
+ * turn handed back, and to count model calls. A Proxy, so a class-based runtime keeps its prototype methods.
75
+ */
76
+ function recordModelTraffic(inner, timeline) {
77
+ const calls = new Map();
78
+ let steps = 0;
79
+ const streamTurn = async (request) => {
80
+ steps += 1;
81
+ let result;
82
+ try {
83
+ result = await inner.streamTurn(request);
84
+ }
85
+ catch (error) {
86
+ // Never retried: a retry is another billed call, and core's retry rebuilds the runtime from the agent's own
87
+ // credentials, which would drop this override.
88
+ throw Object.assign(error instanceof Error ? error : new Error(String(error)), { retryable: false });
89
+ }
90
+ for (const call of result.toolCalls) {
91
+ const entry = { kind: "call", name: call.name, args: call.arguments, result: "" };
92
+ calls.set(call.id, entry);
93
+ timeline.push(entry);
94
+ }
95
+ return result;
96
+ };
97
+ const appendToolOutput = (callId, output) => {
98
+ Object.assign(calls.get(callId) ?? {}, { result: output });
99
+ inner.appendToolOutput(callId, output);
100
+ };
101
+ const runtime = new Proxy(inner, {
102
+ get(target, property) {
103
+ if (property === "streamTurn")
104
+ return streamTurn;
105
+ if (property === "appendToolOutput")
106
+ return appendToolOutput;
107
+ const value = Reflect.get(target, property);
108
+ return typeof value === "function" ? value.bind(target) : value;
109
+ },
110
+ });
111
+ return { runtime, steps: () => steps };
112
+ }
113
+ const idle = async () => undefined;
114
+ const ENTITIES = { amp: "&", lt: "<", gt: ">", quot: "\"", "#39": "'" };
115
+ /** Telegram HTML as sent, back to the text the person reads. */
116
+ function visibleText(html) {
117
+ return html.replace(/<[^>]+>/g, "").replace(/&(amp|lt|gt|quot|#39);/g, (_match, name) => ENTITIES[name]);
118
+ }
119
+ async function runTelegramTurn(input) {
120
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.telegram_turn_start", message: "running one eval Telegram turn", meta: { steps: input.prefix.length } });
121
+ try {
122
+ const agentRoot = node_path_1.default.resolve(input.agentRoot);
123
+ if (agentRoot !== (0, identity_1.getAgentRoot)(AGENT))
124
+ throw new Error(`agentRoot must be the sanctuary bundle at ${(0, identity_1.getAgentRoot)(AGENT)}, where the turn reads it`);
125
+ (0, identity_1.setAgentName)(AGENT);
126
+ await writeOwner(agentRoot);
127
+ const identityKey = (0, telegram_identity_key_1.readOrCreateTelegramIdentityKey)(agentRoot);
128
+ const sessionKey = `telegram:${(0, telegram_1.opaqueTelegramSubject)(identityKey, BOT_ID, OWNER_USER, OWNER_USER)}`;
129
+ const sessionPath = (0, shared_turn_1.getSenseSessionPath)(AGENT, OWNER_FRIEND_ID, "telegram", sessionKey, agentRoot);
130
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(sessionPath), { recursive: true });
131
+ (0, context_1.saveSession)(sessionPath, [{ role: "system", content: "" }, ...input.prefix]);
132
+ const timeline = [];
133
+ const recorded = recordModelTraffic(input.providerRuntime, timeline);
134
+ const withButtons = new Map();
135
+ let messageId = 1;
136
+ const api = {
137
+ request: async (method, body) => {
138
+ if (method === "sendMessage") {
139
+ const entry = { kind: "reply", text: visibleText(String(body.text)) };
140
+ timeline.push(entry);
141
+ // A message with buttons (an approval card) is not part of the answer.
142
+ withButtons.set(entry, Boolean(body.reply_markup));
143
+ }
144
+ return { message_id: messageId++ };
145
+ },
146
+ stop: () => undefined,
147
+ };
148
+ const credentials = { botToken: `${BOT_ID}:eval-token`, authorizedUserId: OWNER_USER, authorizedChatId: OWNER_USER };
149
+ let turn;
150
+ let turnError;
151
+ let onMessage;
152
+ const app = (0, telegram_1.createTelegramSenseApp)({
153
+ agentName: AGENT,
154
+ credentials,
155
+ identityKey,
156
+ _agentRoot: agentRoot,
157
+ _toolContext: { agentRoot, answerGates: sanctuary_runtime_1.SANCTUARY_ANSWER_GATES },
158
+ api,
159
+ createLongPoll: (options) => {
160
+ onMessage = options.onMessage;
161
+ return { pollOnce: idle, run: idle, stop: idle };
162
+ },
163
+ _createInteractiveControl: (() => ({ socketPath: "unused", start: idle, stop: idle })),
164
+ migrateIdentity: idle,
165
+ ...(await (0, telegram_1.createProductionTelegramRelationshipComposition)(AGENT, credentials, agentRoot)),
166
+ _runTurn: async (options) => {
167
+ try {
168
+ turn = await (0, shared_turn_1.runSenseTurn)({
169
+ ...options,
170
+ prepareRunAgentOptions: async (prepare) => ({
171
+ ...await options.prepareRunAgentOptions(prepare),
172
+ providerRuntimeOverride: recorded.runtime,
173
+ skipKeptNotes: true,
174
+ }),
175
+ });
176
+ return turn;
177
+ }
178
+ catch (error) {
179
+ // The sense reports a failed turn to the person and carries on; the eval needs the failure itself.
180
+ turnError = error;
181
+ throw error;
182
+ }
183
+ },
184
+ });
185
+ try {
186
+ await onMessage({ updateId: 1, messageId: "1", userId: OWNER_USER, chatId: OWNER_USER, text: input.userText });
187
+ }
188
+ finally {
189
+ await app.stop();
190
+ }
191
+ if (turnError)
192
+ throw turnError;
193
+ // The answer is every message sent after the model's last tool call: Telegram splits a long one into several.
194
+ const lastCall = timeline.findLastIndex((entry) => entry.kind === "call");
195
+ const result = {
196
+ timeline,
197
+ finalReply: timeline.slice(lastCall + 1).filter((entry) => !withButtons.get(entry)).map((entry) => entry.text).join("\n"),
198
+ outcome: String(turn.turnOutcome),
199
+ steps: recorded.steps(),
200
+ };
201
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.telegram_turn_end", message: "eval Telegram turn finished", meta: { outcome: result.outcome, steps: result.steps } });
202
+ return result;
203
+ }
204
+ catch (error) {
205
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.telegram_turn_error", message: "eval Telegram turn failed", meta: { error: error.message } });
206
+ throw error;
207
+ }
208
+ }