@ouro.bot/cli 0.1.0-alpha.1517 → 0.1.0-alpha.1519
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/actions/generated/mailbox/actions.json +558 -7
- package/dist/actions/generated/mailbox/commands.json +168 -2
- package/dist/actions/generated/mailbox/mcp.json +413 -5
- package/dist/actions/generated/mailbox-tools/tools.json +487 -6
- package/dist/heart/daemon/cli-exec.js +19 -3
- package/dist/heart/daemon/cli-parse.js +21 -9
- package/dist/heart/daemon/daemon.js +9 -0
- package/dist/heart/letters/doors-tools.js +33 -1
- package/dist/heart/letters/doors.js +229 -19
- package/dist/heart/letters/letter-index.js +89 -0
- package/dist/heart/letters/letter.js +247 -0
- package/dist/heart/letters/store.js +210 -0
- package/dist/heart/letters/writer.js +298 -0
- package/dist/heart/mcp/mcp-server.js +37 -8
- package/dist/repertoire/in-turn-tools-door.js +1 -0
- package/dist/repertoire/tools.js +9 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LettersWriter = exports.ROLL_AFTER_MS = exports.LetterRefusal = void 0;
|
|
37
|
+
exports.ownerFriendIds = ownerFriendIds;
|
|
38
|
+
exports.answerLettersCommand = answerLettersCommand;
|
|
39
|
+
// The letters' single writer (design §3.2): the daemon holds one of these, and every door (CLI, MCP, in-turn tools)
|
|
40
|
+
// reaches it over the daemon's socket with a `letters.action` command. Each agent's letters live in its own bundle,
|
|
41
|
+
// under state/letters, and every write to them goes through that agent's one queue, so two sends never race.
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const friends_1 = require("@ouro.bot/friends");
|
|
45
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
46
|
+
const letter_1 = require("./letter");
|
|
47
|
+
const letter_index_1 = require("./letter-index");
|
|
48
|
+
const store_1 = require("./store");
|
|
49
|
+
/** A refusal the door answers with its card's code. */
|
|
50
|
+
class LetterRefusal extends Error {
|
|
51
|
+
code;
|
|
52
|
+
constructor(code, message) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.name = "LetterRefusal";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.LetterRefusal = LetterRefusal;
|
|
59
|
+
/** Closed letters move to closed/YYYY-MM/ this long after they close (design §3.2); they are never deleted. */
|
|
60
|
+
exports.ROLL_AFTER_MS = 90 * 24 * 60 * 60 * 1000;
|
|
61
|
+
const AGENT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
62
|
+
const WAIT_DEFAULT_S = 60;
|
|
63
|
+
const WAIT_MAX_S = 300;
|
|
64
|
+
/** The family records in a bundle's friends folder that name this machine's owner, the rule `ouro friend link-code` uses. */
|
|
65
|
+
async function ownerFriendIds(bundleRoot, owner, list) {
|
|
66
|
+
const friends = await (list ?? ((root) => new friends_1.FileFriendStore(path.join(root, "friends")).listAll()))(bundleRoot);
|
|
67
|
+
return friends
|
|
68
|
+
.filter((record) => record.trustLevel === "family" && record.externalIds.some((id) => (0, friends_1.isLocalMachineOwnerIdentity)(id.provider, id.externalId, owner)))
|
|
69
|
+
.map((record) => record.id);
|
|
70
|
+
}
|
|
71
|
+
function ageOf(createdAt, now) {
|
|
72
|
+
const minutes = Math.max(0, Math.floor((now - Date.parse(createdAt)) / 60000));
|
|
73
|
+
if (minutes < 60)
|
|
74
|
+
return `${minutes}m`;
|
|
75
|
+
const hours = Math.floor(minutes / 60);
|
|
76
|
+
return hours < 24 ? `${hours}h` : `${Math.floor(hours / 24)}d`;
|
|
77
|
+
}
|
|
78
|
+
function optionText(letter, option) {
|
|
79
|
+
const label = letter.options.find((candidate) => candidate.id === option)?.label;
|
|
80
|
+
return label ? `${option} (${label})` : option;
|
|
81
|
+
}
|
|
82
|
+
function eventLine(letter, event) {
|
|
83
|
+
switch (event.t) {
|
|
84
|
+
case "delivered": return `${event.at} delivered to ${event.channel}`;
|
|
85
|
+
case "seen": return `${event.at} seen on ${event.via}`;
|
|
86
|
+
case "answered": return `${event.at} answered ${optionText(letter, event.option)}`;
|
|
87
|
+
case "refiled": return `${event.at} refiled by ${event.by}`;
|
|
88
|
+
case "withdrawn": return `${event.at} withdrawn: ${event.reason}`;
|
|
89
|
+
case "expired": return `${event.at} expired`;
|
|
90
|
+
case "returned": return `${event.at} returned to ${event.to}${event.ok ? "" : ", failed"}`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** When a letter closed: its first answered, withdrawn or expired event. */
|
|
94
|
+
function closedAt(entry) {
|
|
95
|
+
const closing = entry.events.find((event) => event.t === "answered" || event.t === "withdrawn" || event.t === "expired");
|
|
96
|
+
return closing ? Date.parse(closing.at) : null;
|
|
97
|
+
}
|
|
98
|
+
class LettersWriter {
|
|
99
|
+
deps;
|
|
100
|
+
agents = new Map();
|
|
101
|
+
constructor(deps) {
|
|
102
|
+
this.deps = deps;
|
|
103
|
+
}
|
|
104
|
+
now() {
|
|
105
|
+
return (this.deps.now ?? (() => new Date()))();
|
|
106
|
+
}
|
|
107
|
+
/** Runs one action for an agent; a refusal throws LetterRefusal with its card's code. */
|
|
108
|
+
async run(agent, action, input, options = {}) {
|
|
109
|
+
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
110
|
+
throw new LetterRefusal("bad-input", "The action's input must be an object.");
|
|
111
|
+
const letters = this.open(agent);
|
|
112
|
+
const result = await this.dispatch(letters, action, input, options.dryRun === true);
|
|
113
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.action_done", message: "letters action done", meta: { action, outcome: result.outcome } });
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
dispatch(letters, action, input, dryRun) {
|
|
117
|
+
switch (action) {
|
|
118
|
+
case "mailbox_send": return this.serial(letters, () => {
|
|
119
|
+
// Each send first rolls the letters closed long enough, so a daemon that runs for months still rolls them; a
|
|
120
|
+
// dry run writes nothing, so it doesn't roll.
|
|
121
|
+
if (!dryRun)
|
|
122
|
+
this.rollClosed(letters);
|
|
123
|
+
return this.send(letters, input, dryRun);
|
|
124
|
+
});
|
|
125
|
+
case "mailbox_list": return Promise.resolve(this.list(letters, input));
|
|
126
|
+
case "mailbox_read": return Promise.resolve(this.read(letters, input));
|
|
127
|
+
case "mailbox_wait": return this.wait(letters, input);
|
|
128
|
+
case "mailbox_withdraw": return this.serial(letters, () => this.withdraw(letters, input, dryRun));
|
|
129
|
+
case "mailbox_deliver": return Promise.resolve(this.deliver(letters, input));
|
|
130
|
+
default: return Promise.reject(new LetterRefusal("unknown-door", `The mailbox has no action ${action}.`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** The agent's letters, read from its bundle the first time; letters closed long enough are rolled then. */
|
|
134
|
+
open(agent) {
|
|
135
|
+
const bundle = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
|
|
136
|
+
if (!AGENT_NAME.test(agent) || !fs.existsSync(bundle))
|
|
137
|
+
throw new LetterRefusal("no-agent", `No agent bundle ${agent}.ouro is on this machine.`);
|
|
138
|
+
const known = this.agents.get(agent);
|
|
139
|
+
if (known)
|
|
140
|
+
return known;
|
|
141
|
+
const store = new store_1.LetterStore(path.join(bundle, "state", "letters"));
|
|
142
|
+
const index = new letter_index_1.LetterIndex(store.loadAll(), store.readNextCode());
|
|
143
|
+
const letters = { agent, store, index, queue: Promise.resolve(), waiters: new Map() };
|
|
144
|
+
this.agents.set(agent, letters);
|
|
145
|
+
this.rollClosed(letters);
|
|
146
|
+
return letters;
|
|
147
|
+
}
|
|
148
|
+
rollClosed(letters) {
|
|
149
|
+
const now = this.now().getTime();
|
|
150
|
+
for (const entry of letters.index.list({ all: true })) {
|
|
151
|
+
const closed = closedAt(entry);
|
|
152
|
+
if (entry.closed || closed === null || now - closed < exports.ROLL_AFTER_MS)
|
|
153
|
+
continue;
|
|
154
|
+
// Rolling is housekeeping: a letter that can't be moved stays where it is, readable, and is tried again later.
|
|
155
|
+
try {
|
|
156
|
+
letters.store.roll(entry.letter.id, new Date(closed));
|
|
157
|
+
letters.index.markClosed(entry.letter.id);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.roll_failed", message: "a closed letter could not be rolled", meta: { reason: error.message } });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Runs a write after every write queued before it; a failed write doesn't stop the ones after it. */
|
|
165
|
+
serial(letters, work) {
|
|
166
|
+
const next = letters.queue.then(work);
|
|
167
|
+
letters.queue = next.catch(() => undefined);
|
|
168
|
+
return next;
|
|
169
|
+
}
|
|
170
|
+
addEvent(letters, id, event) {
|
|
171
|
+
letters.store.append(id, event);
|
|
172
|
+
const entry = letters.index.addEvent(id, event);
|
|
173
|
+
for (const wake of letters.waiters.get(id) ?? [])
|
|
174
|
+
wake();
|
|
175
|
+
return entry;
|
|
176
|
+
}
|
|
177
|
+
find(letters, input) {
|
|
178
|
+
const entry = typeof input.letter === "string" ? letters.index.get(input.letter) : undefined;
|
|
179
|
+
if (!entry)
|
|
180
|
+
throw new LetterRefusal("not-found", `No letter is ${String(input.letter)}.`);
|
|
181
|
+
return entry;
|
|
182
|
+
}
|
|
183
|
+
async person(agent) {
|
|
184
|
+
const bundle = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
|
|
185
|
+
const ids = await ownerFriendIds(bundle, (this.deps.ownerUsername ?? friends_1.machineOwnerUsername)(), this.deps.listFriends);
|
|
186
|
+
if (ids.length === 1)
|
|
187
|
+
return ids[0];
|
|
188
|
+
throw new LetterRefusal("no-person", ids.length === 0
|
|
189
|
+
? "No family friend record names this machine's owner, so Ouro can't tell who the letter is to."
|
|
190
|
+
: `${ids.length} family records name this machine's owner, so Ouro can't tell which one the letter is to.`);
|
|
191
|
+
}
|
|
192
|
+
async send(letters, input, dryRun) {
|
|
193
|
+
const checked = (0, letter_1.checkLetterInput)(input);
|
|
194
|
+
if (!checked.ok)
|
|
195
|
+
throw new LetterRefusal("invalid-letter", checked.problem);
|
|
196
|
+
const { lane, ...draft } = checked.letter;
|
|
197
|
+
const from = { agent: letters.agent, ...(lane ? { lane } : {}) };
|
|
198
|
+
const now = this.now();
|
|
199
|
+
const duplicate = letters.index.findDuplicate({ from, dedupeKey: draft.dedupeKey }, now.getTime());
|
|
200
|
+
if (duplicate) {
|
|
201
|
+
const { letter } = duplicate.entry;
|
|
202
|
+
if (dryRun)
|
|
203
|
+
return { outcome: "preview", id: "", code: "", state: "waiting", message: `Would return ${letter.code}, which is already ${duplicate.entry.state} with this dedupeKey.` };
|
|
204
|
+
if (duplicate.why === "answered") {
|
|
205
|
+
const answer = duplicate.entry.events.find((event) => event.t === "answered");
|
|
206
|
+
return { outcome: "done", id: letter.id, code: letter.code, state: "answered", message: `${letter.code} was answered ${optionText(letter, answer.option)} in the last day, so the answer stands.` };
|
|
207
|
+
}
|
|
208
|
+
this.addEvent(letters, letter.id, { t: "refiled", at: now.toISOString(), by: letters.agent });
|
|
209
|
+
return { outcome: "done", id: letter.id, code: letter.code, state: "waiting", message: `${letter.code} is already waiting with this dedupeKey, so it was refiled, not filed again.` };
|
|
210
|
+
}
|
|
211
|
+
const to = await this.person(letters.agent);
|
|
212
|
+
if (dryRun)
|
|
213
|
+
return { outcome: "preview", id: "", code: "", state: "waiting", message: `Would file a new letter to ${to}.` };
|
|
214
|
+
const number = letters.index.nextCode();
|
|
215
|
+
// The counter moves first, so a crash after it can skip a code but never reuse one.
|
|
216
|
+
letters.store.writeNextCode(number + 1);
|
|
217
|
+
letters.index.reserve(number + 1);
|
|
218
|
+
const letter = { v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, to, from, ...draft, createdAt: now.toISOString() };
|
|
219
|
+
letters.store.create(letter);
|
|
220
|
+
letters.index.add({ letter, events: [], closed: false });
|
|
221
|
+
return { outcome: "needs-human", id: letter.id, code: letter.code, state: "waiting", message: `Filed ${letter.code}, ${letter.subject}. It waits for the person's answer.` };
|
|
222
|
+
}
|
|
223
|
+
list(letters, input) {
|
|
224
|
+
const now = this.now().getTime();
|
|
225
|
+
const entries = letters.index.list({
|
|
226
|
+
all: input.all === true,
|
|
227
|
+
...(typeof input.kind === "string" ? { kind: input.kind } : {}),
|
|
228
|
+
...(input.mine === true ? { from: letters.agent } : {}),
|
|
229
|
+
});
|
|
230
|
+
const listing = entries.map((entry) => `${entry.letter.code} ${entry.state} ${ageOf(entry.letter.createdAt, now)} ${entry.letter.subject}`).join("\n");
|
|
231
|
+
return { outcome: "done", count: entries.length, listing };
|
|
232
|
+
}
|
|
233
|
+
read(letters, input) {
|
|
234
|
+
const entry = this.find(letters, input);
|
|
235
|
+
return { outcome: "done", state: entry.state, letter: JSON.stringify(entry.letter), events: entry.events.map((event) => eventLine(entry.letter, event)).join("\n") };
|
|
236
|
+
}
|
|
237
|
+
/** Blocks until the letter leaves waiting, or has an event past the cursor, or the timeout ends. */
|
|
238
|
+
async wait(letters, input) {
|
|
239
|
+
const entry = this.find(letters, input);
|
|
240
|
+
const cursor = Number.isInteger(input.cursor) && input.cursor >= 0 ? input.cursor : null;
|
|
241
|
+
const seconds = Number.isInteger(input.timeout) ? Math.min(WAIT_MAX_S, Math.max(1, input.timeout)) : WAIT_DEFAULT_S;
|
|
242
|
+
const ready = () => entry.state !== "waiting" || (cursor !== null && entry.events.length > cursor);
|
|
243
|
+
if (!ready()) {
|
|
244
|
+
const id = entry.letter.id;
|
|
245
|
+
await new Promise((resolve) => {
|
|
246
|
+
const waiters = letters.waiters.get(id) ?? new Set();
|
|
247
|
+
letters.waiters.set(id, waiters);
|
|
248
|
+
const done = () => {
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
waiters.delete(wake);
|
|
251
|
+
if (waiters.size === 0)
|
|
252
|
+
letters.waiters.delete(id);
|
|
253
|
+
resolve();
|
|
254
|
+
};
|
|
255
|
+
const wake = () => {
|
|
256
|
+
if (ready())
|
|
257
|
+
done();
|
|
258
|
+
};
|
|
259
|
+
const timer = setTimeout(done, seconds * (this.deps.waitUnitMs ?? 1000));
|
|
260
|
+
waiters.add(wake);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return { outcome: ready() ? "done" : "timeout", state: entry.state, cursor: entry.events.length };
|
|
264
|
+
}
|
|
265
|
+
async withdraw(letters, input, dryRun) {
|
|
266
|
+
const entry = this.find(letters, input);
|
|
267
|
+
if (entry.letter.from.agent !== letters.agent)
|
|
268
|
+
throw new LetterRefusal("not-sender", `${entry.letter.code} was filed by ${entry.letter.from.agent}, and only the agent that filed a letter may withdraw it.`);
|
|
269
|
+
if (entry.state !== "waiting")
|
|
270
|
+
throw new LetterRefusal("not-waiting", `${entry.letter.code} is already ${entry.state}.`);
|
|
271
|
+
const checked = (0, letter_1.checkWithdrawReason)(input.reason);
|
|
272
|
+
if (!checked.ok)
|
|
273
|
+
throw new LetterRefusal("bad-input", `${checked.problem} Say in one line why the letter no longer needs an answer.`);
|
|
274
|
+
const reason = checked.reason.trim();
|
|
275
|
+
// A dry run checks everything a withdraw checks, then writes nothing.
|
|
276
|
+
if (dryRun)
|
|
277
|
+
return { outcome: "preview", state: entry.state };
|
|
278
|
+
const after = this.addEvent(letters, entry.letter.id, { t: "withdrawn", at: this.now().toISOString(), reason });
|
|
279
|
+
return { outcome: "done", state: after.state };
|
|
280
|
+
}
|
|
281
|
+
deliver(letters, input) {
|
|
282
|
+
const entry = this.find(letters, input);
|
|
283
|
+
throw new LetterRefusal("no-answering-handle", `The person has no answering handle yet, so ${entry.letter.code} stays waiting until chat delivery is ready.`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
exports.LettersWriter = LettersWriter;
|
|
287
|
+
/** The daemon's answer to a `letters.action` command: the result, or the refusal's code and text. */
|
|
288
|
+
async function answerLettersCommand(writer, command) {
|
|
289
|
+
try {
|
|
290
|
+
return { ok: true, data: await writer.run(command.agent, command.action, command.input, { dryRun: command.dryRun === true }) };
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (error instanceof LetterRefusal)
|
|
294
|
+
return { ok: false, error: error.message, data: { code: error.code, message: error.message } };
|
|
295
|
+
(0, runtime_1.emitNervesEvent)({ level: "error", component: "daemon", event: "letters.action_failed", message: "letters action failed", meta: { action: command.action } });
|
|
296
|
+
return { ok: false, error: error.message };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.serverErrors = exports._senseTurnCommandTimeoutMs = exports._senseTurnRetryDelays = exports.SENSE_TURN_COMMAND_TIMEOUT_MS = exports.SENSE_TURN_RETRY_DELAYS_MS = exports.SENSE_TURN_MAX_RETRIES = void 0;
|
|
36
|
+
exports.serverErrors = exports._senseTurnCommandTimeoutMs = exports._senseTurnRetryDelays = exports.SENSE_TURN_COMMAND_TIMEOUT_MS = exports.SENSE_TURN_RETRY_DELAYS_MS = exports.SENSE_TURN_MAX_RETRIES = exports.MAILBOX_REFUSAL_CODES = void 0;
|
|
37
37
|
exports._setSenseTurnRetryDelays = _setSenseTurnRetryDelays;
|
|
38
38
|
exports._setSenseTurnCommandTimeoutMs = _setSenseTurnCommandTimeoutMs;
|
|
39
39
|
exports.mcpAnnotationsOf = mcpAnnotationsOf;
|
|
@@ -53,6 +53,11 @@ const feedback_source_1 = require("../../senses/shepherd/feedback-source");
|
|
|
53
53
|
const redact_1 = require("../../senses/shepherd/redact");
|
|
54
54
|
const tool_candidates_1 = require("../../repertoire/tool-candidates");
|
|
55
55
|
const doors_1 = require("../letters/doors");
|
|
56
|
+
/** The codes the mailbox doors answer a refusal with: the doors' own checks and the daemon's letters writer. */
|
|
57
|
+
exports.MAILBOX_REFUSAL_CODES = new Set([
|
|
58
|
+
"daemon-down", "unknown-input", "bad-input", "no-agent", "not-found",
|
|
59
|
+
"invalid-letter", "no-person", "not-sender", "not-waiting", "no-answering-handle",
|
|
60
|
+
]);
|
|
56
61
|
exports.SENSE_TURN_MAX_RETRIES = 3;
|
|
57
62
|
exports.SENSE_TURN_RETRY_DELAYS_MS = [1000, 2000, 4000];
|
|
58
63
|
exports.SENSE_TURN_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;
|
|
@@ -391,6 +396,13 @@ function createMcpServer(options) {
|
|
|
391
396
|
* An `isError` result in the tool's own card's words: `[code] means`, the detail when there is one, then `Fix: fix`.
|
|
392
397
|
* Every code a call path raises is on that tool's card; the census checks each card code is raised in this file.
|
|
393
398
|
*/
|
|
399
|
+
/**
|
|
400
|
+
* Whether a mailbox refusal's code is one this server answers as a refusal: one the mailbox doors raise (the daemon's
|
|
401
|
+
* writer or the doors' own checks), and on the tool's card. Any other code is answered as a failure.
|
|
402
|
+
*/
|
|
403
|
+
function mailboxRefusalCarded(toolName, code) {
|
|
404
|
+
return exports.MAILBOX_REFUSAL_CODES.has(code) && getToolSchemas().find((schema) => schema.name === toolName).ax.errors.some((error) => error.code === code);
|
|
405
|
+
}
|
|
394
406
|
function writeToolError(request, toolName, code, detail) {
|
|
395
407
|
const card = getToolSchemas().find((schema) => schema.name === toolName).ax.errors.find((error) => error.code === code);
|
|
396
408
|
const text = [`[${code}] ${card.means}`, ...(detail ? [detail] : []), `Fix: ${card.fix}`].join("\n");
|
|
@@ -474,6 +486,13 @@ function createMcpServer(options) {
|
|
|
474
486
|
const toolName = params.name;
|
|
475
487
|
const toolArgs = (params.arguments ?? {});
|
|
476
488
|
/* v8 ignore stop */
|
|
489
|
+
// A person-only action is no tool, but a call to it gets the person-only refusal ouro-actions generated for it.
|
|
490
|
+
const { refusals } = (0, doors_1.readMailboxDoors)();
|
|
491
|
+
const personOnly = typeof toolName === "string" && Object.hasOwn(refusals, toolName) ? refusals[toolName] : undefined;
|
|
492
|
+
if (personOnly) {
|
|
493
|
+
writeResponse({ jsonrpc: "2.0", id: request.id, result: { content: [{ type: "text", text: `[person-only] ${personOnly.summary}` }], structuredContent: personOnly, isError: true } });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
477
496
|
// An error in finding the tool is a protocol error, not a tool result (MCP 2025-11-25, CallToolResult.isError).
|
|
478
497
|
const names = getToolSchemas().map((schema) => schema.name);
|
|
479
498
|
if (typeof toolName !== "string" || !names.includes(toolName)) {
|
|
@@ -503,17 +522,17 @@ function createMcpServer(options) {
|
|
|
503
522
|
await runFeedbackTool(request, toolName, toolArgs);
|
|
504
523
|
return;
|
|
505
524
|
}
|
|
506
|
-
// ── Mailbox tools: generated doors
|
|
525
|
+
// ── Mailbox tools: generated doors; the daemon's single writer runs them over the socket ──
|
|
507
526
|
if ((0, doors_1.mailboxMcpSchemas)().some((schema) => schema.name === toolName)) {
|
|
508
527
|
try {
|
|
509
|
-
const result = (0, doors_1.runMailboxAction)(toolName, toolArgs);
|
|
528
|
+
const result = await (0, doors_1.runMailboxAction)(toolName, toolArgs, { agent, socketPath });
|
|
510
529
|
writeResponse({ jsonrpc: "2.0", id: request.id, result: { content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result, isError: false } });
|
|
511
530
|
}
|
|
512
531
|
catch (error) {
|
|
513
|
-
// A
|
|
514
|
-
//
|
|
515
|
-
if (error instanceof doors_1.MailboxDoorError)
|
|
516
|
-
writeToolError(request, toolName,
|
|
532
|
+
// A refusal answers with its card's code. Anything else is a failure, not bad input: it is answered as a
|
|
533
|
+
// JSON-RPC internal error, since nothing above handleRequest catches a throw.
|
|
534
|
+
if (error instanceof doors_1.MailboxDoorError && mailboxRefusalCarded(toolName, error.code))
|
|
535
|
+
writeToolError(request, toolName, error.code, error.message);
|
|
517
536
|
else
|
|
518
537
|
writeResponse({ jsonrpc: "2.0", id: request.id, error: { code: -32603, message: `${toolName} failed: ${error.message}` } });
|
|
519
538
|
}
|
|
@@ -682,11 +701,16 @@ function readErrors(tool, what) {
|
|
|
682
701
|
];
|
|
683
702
|
}
|
|
684
703
|
/**
|
|
685
|
-
* Returns the list of MCP tool schemas for all
|
|
704
|
+
* Returns the list of MCP tool schemas for all 23 agent tools (17 written here, the mailbox group's 6 generated), each with its Ouro AX card (`ax`).
|
|
686
705
|
* Each schema follows JSON Schema for inputSchema as required by MCP.
|
|
687
706
|
*/
|
|
688
707
|
function getToolSchemas() {
|
|
708
|
+
const mailboxSend = (0, doors_1.mailboxMcpSchema)("mailbox_send");
|
|
689
709
|
const mailboxList = (0, doors_1.mailboxMcpSchema)("mailbox_list");
|
|
710
|
+
const mailboxRead = (0, doors_1.mailboxMcpSchema)("mailbox_read");
|
|
711
|
+
const mailboxWait = (0, doors_1.mailboxMcpSchema)("mailbox_wait");
|
|
712
|
+
const mailboxWithdraw = (0, doors_1.mailboxMcpSchema)("mailbox_withdraw");
|
|
713
|
+
const mailboxDeliver = (0, doors_1.mailboxMcpSchema)("mailbox_deliver");
|
|
690
714
|
return [
|
|
691
715
|
{
|
|
692
716
|
name: "shepherd_feedback",
|
|
@@ -887,7 +911,12 @@ function getToolSchemas() {
|
|
|
887
911
|
},
|
|
888
912
|
// The mailbox group's tools, generated by ouro-actions from actions/mailbox.actions.mts. Each is named here, where
|
|
889
913
|
// the census places MCP doors; mailboxMcpSchema reads the rest from mcp.json and fails on a name it doesn't list.
|
|
914
|
+
{ ...mailboxSend, name: "mailbox_send", inputSchema: mailboxSend.inputSchema },
|
|
890
915
|
{ ...mailboxList, name: "mailbox_list", inputSchema: mailboxList.inputSchema },
|
|
916
|
+
{ ...mailboxRead, name: "mailbox_read", inputSchema: mailboxRead.inputSchema },
|
|
917
|
+
{ ...mailboxWait, name: "mailbox_wait", inputSchema: mailboxWait.inputSchema },
|
|
918
|
+
{ ...mailboxWithdraw, name: "mailbox_withdraw", inputSchema: mailboxWithdraw.inputSchema },
|
|
919
|
+
{ ...mailboxDeliver, name: "mailbox_deliver", inputSchema: mailboxDeliver.inputSchema },
|
|
891
920
|
];
|
|
892
921
|
}
|
|
893
922
|
// MCP server v0.1.0-alpha.140
|
|
@@ -20,6 +20,7 @@ exports.DISPATCH_ERRORS = [
|
|
|
20
20
|
{ code: "guardrail-blocked", means: "A guardrail refused this call; the text says which.", fix: "Do what the text says, such as reading the file before editing it." },
|
|
21
21
|
{ code: "commerce-authority-required", means: "A purchase needs a commerce authority token from the person.", fix: "Ask the person to approve the purchase, then call it with the token." },
|
|
22
22
|
{ code: "not-run", means: "This X-ray door checked the call but runs no tool.", fix: "Nothing to fix: in a real turn the tool runs." },
|
|
23
|
+
{ code: "person-only", means: "Only the person can do this, so no agent may call it; the text says why and where the person does it.", fix: "Tell the person what the text says, and leave the step to them." },
|
|
23
24
|
];
|
|
24
25
|
/** The door's sign-in: it never starts one, since no tool it answers runs. */
|
|
25
26
|
async function neverSignIn() {
|
package/dist/repertoire/tools.js
CHANGED
|
@@ -125,11 +125,12 @@ function withCheckBack(tool) {
|
|
|
125
125
|
// Re-export surface tool schema for consumers (e.g. heart/core.ts)
|
|
126
126
|
var tools_surface_2 = require("./tools-surface");
|
|
127
127
|
Object.defineProperty(exports, "surfaceToolDef", { enumerable: true, get: function () { return tools_surface_2.surfaceToolDef; } });
|
|
128
|
+
// The mailbox group, generated by ouro-actions-tools (actions/generated/mailbox-tools/tools.json): the dispatcher and the
|
|
129
|
+
// X-ray know it, and every ordinary turn offers it, so the agent can file a letter only its person can answer.
|
|
130
|
+
const mailboxDefinitions = (0, doors_tools_1.mailboxToolDefinitions)();
|
|
128
131
|
// All tool definitions in a single registry
|
|
129
132
|
const additionalDefinitions = [...tools_chat_1.chatToolDefinitions, ...tools_teams_1.teamsToolDefinitions, ...ado_semantic_1.adoSemanticToolDefinitions, ...tools_github_1.githubToolDefinitions, ...tools_bundle_1.bundleToolDefinitions, ...tools_voice_1.voiceToolDefinitions, ...tools_unraid_1.unraidToolDefinitions, tools_steward_policy_1.stewardPolicyToolDefinition, ...tools_house_care_1.houseCareToolDefinitions, tools_surface_1.surfaceToolDefinition, ...tools_shepherd_1.shepherdToolDefinitions, ...tools_app_sessions_1.appSessionsToolDefinitions, ...tools_mail_1.mailToolDefinitions,
|
|
130
|
-
|
|
131
|
-
// dispatcher and the X-ray know it, and offered in no turn until the letters store exists.
|
|
132
|
-
...(0, doors_tools_1.mailboxToolDefinitions)()];
|
|
133
|
+
...mailboxDefinitions];
|
|
133
134
|
const COMMERCE_AUTHORITY_TOOLS = new Set(["stripe_create_card", "flight_hold", "flight_book"]);
|
|
134
135
|
class ToolSelectionError extends Error {
|
|
135
136
|
}
|
|
@@ -216,6 +217,7 @@ function selectToolsForChannel(capabilities, toolPreferences, _context, provider
|
|
|
216
217
|
// The mail tools exist only for an agent that turned the mail sense on in agent.json.
|
|
217
218
|
...((0, tools_mail_1.mailToolsEnabled)(context?.agentRoot ?? safeGetAgentRoot()) ? tools_mail_1.mailToolDefinitions : []),
|
|
218
219
|
...tools_chat_1.chatToolDefinitions,
|
|
220
|
+
...mailboxDefinitions,
|
|
219
221
|
...(capabilities?.channel === "voice" ? tools_voice_1.voiceToolDefinitions : []),
|
|
220
222
|
...((0, tools_voice_local_1.localAudioToolGate)({ ...context, context: _context }).ok ? [tools_voice_local_1.voiceLocalAudioToolDefinition] : []),
|
|
221
223
|
...integrations, ...mcp,
|
|
@@ -458,6 +460,10 @@ async function preflightToolCall(name, args, ctx) {
|
|
|
458
460
|
const def = findDefinition(name, selection);
|
|
459
461
|
const schema = def?.tool ?? selection?.engine.find((tool) => tool.function.name === name);
|
|
460
462
|
if (!schema) {
|
|
463
|
+
// A person-only action is no tool, but a model that calls it gets its refusal, not an unknown tool.
|
|
464
|
+
const personOnly = (0, doors_tools_1.mailboxToolRefusal)(name);
|
|
465
|
+
if (personOnly)
|
|
466
|
+
return { kind: "rejected_before_handler", text: personOnly };
|
|
461
467
|
(0, runtime_1.emitNervesEvent)({ level: "error", event: "tool.error", component: "tools", message: "unknown or unselected tool requested", meta: { name } });
|
|
462
468
|
return { kind: "rejected_before_handler", text: (0, tools_base_1.withCode)(unknownToolText(name, selection), "unknown-tool") };
|
|
463
469
|
}
|
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.1519",
|
|
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.1519",
|
|
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.1519",
|
|
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": {
|