@ouro.bot/cli 0.1.0-alpha.1645 → 0.1.0-alpha.1646
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 +13 -4
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/daemon.js +36 -0
- package/dist/heart/letters/expired-note.js +72 -0
- package/dist/heart/letters/filed-note.js +6 -19
- package/dist/heart/letters/letter-index.js +2 -1
- package/dist/heart/letters/tell-agent.js +27 -0
- package/dist/heart/letters/writer.js +48 -2
- package/dist/heart/private-runtime/policy.js +8 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -2,12 +2,21 @@
|
|
|
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
4
|
{
|
|
5
|
-
"version": "0.1.0-alpha.
|
|
5
|
+
"version": "0.1.0-alpha.1646",
|
|
6
6
|
"changes": [
|
|
7
|
-
"`ouro doctor` now says how far each agent's BlueBubbles address can be trusted with the server password, which every request carries. A server on the same Mac, behind https, or at a tailnet address passes. Plain http to anything else warns, as does an address that isn't an http or https URL; each says the mailbox won't read letter answers from it and names the fix. A MagicDNS name counts only over https.",
|
|
8
|
-
"`ouro doctor` also says whether a shell beside the daemon could send iMessages as the agent's person. It compares the uid that owns the daemon's socket with the uid of the declared host account (`senses.bluebubbles.hostUsername`), the one signed in to the agent's own Apple ID, so it holds when `ouro doctor` runs as the person and the daemon doesn't. It passes when they match. A socket no daemon answers on counts as no daemon. Otherwise it warns that each letter answer is marked `shared-apple-id` until a human runs the daemon under that account.",
|
|
9
7
|
"A person can now answer a letter by texting its code and an option number, such as `L7 2`, in the iMessage chat the letter went to. When a one-to-one message in answer form arrives, the BlueBubbles sense hands the daemon only its GUID, and the daemon decides from the server's own copy. A recorded answer is not a chat turn. A message that already answered is handled the same when it is replayed. Anything else stays an ordinary chat turn, and so does a message the daemon doesn't answer for within 30 seconds: the daemon records nothing after 27 seconds, so a message is never both.",
|
|
10
|
-
"Once an answer is recorded, the person gets a one-line receipt in the same chat, naming the letter as its heading does, such as `Recorded L7 · Slugger asks: Which name? → 2 Ouro`, so a misread answer shows at once. The agent is told in its private runtime and woken; the private-runtime policy allows that wake only when it names the letter and comes from the daemon's answer command. A receipt or wake that fails is logged and never undoes the answer."
|
|
8
|
+
"Once an answer is recorded, the person gets a one-line receipt in the same chat, naming the letter as its heading does, such as `Recorded L7 · Slugger asks: Which name? → 2 Ouro`, so a misread answer shows at once. The agent is told in its private runtime and woken; the private-runtime policy allows that wake only when it names the letter and comes from the daemon's answer command. A receipt or wake that fails is logged and never undoes the answer.",
|
|
9
|
+
"A letter now closes as expired once its `expiresAt` has passed with no answer. The daemon checks every minute and waits ten minutes past the expiry before closing a letter, so an answer the person sent in time still counts when it is read late. It then releases anyone waiting on the letter and wakes the agent that owns it with a note in its private runtime: \"letter L7 expired at … with no answer from my person\". An expired letter can't be answered or delivered. A new private-runtime policy rule allows that wake only when it names the letter and comes from the expiry pass.",
|
|
10
|
+
"A `now` letter whose sender sets no `expiresAt` now expires 24 hours after it is filed. Other letters still never expire unless their sender says so. Refiling a letter with the same `dedupeKey` doesn't extend its expiry, and once a letter is past its expiry the same `dedupeKey` files a new letter.",
|
|
11
|
+
"`mailbox_send` refuses an `expiresAt` that has already passed.",
|
|
12
|
+
"A daemon with no letters loads none of the mailbox's code for the expiry pass."
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"version": "0.1.0-alpha.1644",
|
|
17
|
+
"changes": [
|
|
18
|
+
"`ouro doctor` now says how far each agent's BlueBubbles address can be trusted with the server password, which every request carries. A server on the same Mac, behind https, or at a tailnet address passes. Plain http to anything else warns, as does an address that isn't an http or https URL; each says the mailbox won't read letter answers from it and names the fix. A MagicDNS name counts only over https.",
|
|
19
|
+
"`ouro doctor` also says whether a shell beside the daemon could send iMessages as the agent's person. It compares the uid that owns the daemon's socket with the uid of the declared host account (`senses.bluebubbles.hostUsername`), the one signed in to the agent's own Apple ID, so it holds when `ouro doctor` runs as the person and the daemon doesn't. It passes when they match. A socket no daemon answers on counts as no daemon. Otherwise it warns that each letter answer is marked `shared-apple-id` until a human runs the daemon under that account."
|
|
11
20
|
]
|
|
12
21
|
},
|
|
13
22
|
{
|
|
@@ -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.1646</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -626,6 +626,10 @@ function defaultUpdaterAgentWatch() {
|
|
|
626
626
|
}
|
|
627
627
|
/* v8 ignore stop */
|
|
628
628
|
const STATE_RETENTION_FIRST_DELAY_MS = 10 * 60_000;
|
|
629
|
+
/** How often the daemon closes letters past their expiresAt. */
|
|
630
|
+
const LETTER_EXPIRY_TICK_MS = 60_000;
|
|
631
|
+
/** Matches EXPIRY_GRACE_MS in the letters writer, which daemon.ts doesn't load at start. */
|
|
632
|
+
const LETTER_EXPIRY_GRACE_MS = 10 * 60_000;
|
|
629
633
|
const STATE_RETENTION_INTERVAL_MS = 24 * 60 * 60_000;
|
|
630
634
|
const UPDATER_AGENT_WATCH_FIRST_DELAY_MS = 5 * 60_000;
|
|
631
635
|
const UPDATER_AGENT_WATCH_INTERVAL_MS = 60 * 60_000;
|
|
@@ -661,6 +665,7 @@ class OuroDaemon {
|
|
|
661
665
|
socketIdentity = null;
|
|
662
666
|
senseAutostartTimer = null;
|
|
663
667
|
externalEventReconcileTimer = null;
|
|
668
|
+
letterExpiryTimer = null;
|
|
664
669
|
stateRetentionTimer = null;
|
|
665
670
|
stateRetention;
|
|
666
671
|
updaterAgentWatchTimer = null;
|
|
@@ -894,6 +899,14 @@ class OuroDaemon {
|
|
|
894
899
|
void this.reconcileExternalEvents();
|
|
895
900
|
}, 1_000);
|
|
896
901
|
this.externalEventReconcileTimer.unref?.();
|
|
902
|
+
// The first pass waits out the grace after start, so the senses' catch-up over messages missed while the daemon
|
|
903
|
+
// was down records any answer sent before a letter expired, before the sweep can close that letter.
|
|
904
|
+
const expiryFrom = Date.now() + LETTER_EXPIRY_GRACE_MS;
|
|
905
|
+
this.letterExpiryTimer = setInterval(() => {
|
|
906
|
+
if (Date.now() >= expiryFrom)
|
|
907
|
+
void this.expireLetters();
|
|
908
|
+
}, LETTER_EXPIRY_TICK_MS);
|
|
909
|
+
this.letterExpiryTimer.unref?.();
|
|
897
910
|
this.scheduleStateRetention(STATE_RETENTION_FIRST_DELAY_MS);
|
|
898
911
|
this.scheduleUpdaterAgentWatch(UPDATER_AGENT_WATCH_FIRST_DELAY_MS);
|
|
899
912
|
// Write all managed PIDs to disk so the next daemon can clean up
|
|
@@ -1218,6 +1231,23 @@ class OuroDaemon {
|
|
|
1218
1231
|
}
|
|
1219
1232
|
}
|
|
1220
1233
|
}
|
|
1234
|
+
/**
|
|
1235
|
+
* One expiry pass. It reads no letters code until some bundle has letters, so a daemon without them loads nothing.
|
|
1236
|
+
* Answers how many letters it closed.
|
|
1237
|
+
*/
|
|
1238
|
+
async expireLetters() {
|
|
1239
|
+
try {
|
|
1240
|
+
const any = !!this.lettersWriter || fs.readdirSync(this.bundlesRoot).some((name) => fs.existsSync(path.join(this.bundlesRoot, name, "state", "letters")));
|
|
1241
|
+
return any ? await (await this.letters()).expireDue() : 0;
|
|
1242
|
+
}
|
|
1243
|
+
catch (error) {
|
|
1244
|
+
// No bundles folder yet means no letters, not a failure worth a warning every minute.
|
|
1245
|
+
if (error.code === "ENOENT")
|
|
1246
|
+
return 0;
|
|
1247
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "daemon.letter_expiry_error", message: "the letter expiry pass failed", meta: { error: error.message } });
|
|
1248
|
+
return 0;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1221
1251
|
async stop() {
|
|
1222
1252
|
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
1223
1253
|
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts.
|
|
@@ -1241,6 +1271,10 @@ class OuroDaemon {
|
|
|
1241
1271
|
clearTimeout(this.senseAutostartTimer);
|
|
1242
1272
|
this.senseAutostartTimer = null;
|
|
1243
1273
|
}
|
|
1274
|
+
if (this.letterExpiryTimer) {
|
|
1275
|
+
clearInterval(this.letterExpiryTimer);
|
|
1276
|
+
this.letterExpiryTimer = null;
|
|
1277
|
+
}
|
|
1244
1278
|
if (this.externalEventReconcileTimer) {
|
|
1245
1279
|
clearInterval(this.externalEventReconcileTimer);
|
|
1246
1280
|
this.externalEventReconcileTimer = null;
|
|
@@ -1386,6 +1420,8 @@ class OuroDaemon {
|
|
|
1386
1420
|
deliverChat: (await Promise.resolve().then(() => __importStar(require("../../senses/bluebubbles/agent-client")))).letterChatSender(this.bundlesRoot),
|
|
1387
1421
|
// Filing tells the agent, in its own private runtime, so it decides when its person sees the letter.
|
|
1388
1422
|
onFiled: (await Promise.resolve().then(() => __importStar(require("../letters/filed-note")))).letterFiledTeller(this.bundlesRoot, (wake) => this.handlePrivateRuntimeWake(wake)),
|
|
1423
|
+
// So does a letter that expires with no answer.
|
|
1424
|
+
onExpired: (await Promise.resolve().then(() => __importStar(require("../letters/expired-note")))).letterExpiredTeller(this.bundlesRoot, (wake) => this.handlePrivateRuntimeWake(wake)),
|
|
1389
1425
|
// A recorded answer sends the person a receipt in the same chat and tells the agent.
|
|
1390
1426
|
onAnswered: (await Promise.resolve().then(() => __importStar(require("../letters/answered-note")))).letterAnsweredTeller(this.bundlesRoot, (await Promise.resolve().then(() => __importStar(require("../../senses/bluebubbles/agent-client")))).letterChatSender(this.bundlesRoot), (wake) => this.handlePrivateRuntimeWake(wake)),
|
|
1391
1427
|
}))();
|
|
@@ -0,0 +1,72 @@
|
|
|
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.letterExpiredNote = letterExpiredNote;
|
|
37
|
+
exports.letterExpiredWake = letterExpiredWake;
|
|
38
|
+
exports.letterExpiredTeller = letterExpiredTeller;
|
|
39
|
+
// A letter that reaches its expiresAt with no answer closes as expired, and the agent that owns it is woken with
|
|
40
|
+
// "expired, no answer" (design §3.4, "Expiry"), so it can decide what its lane does without the person's answer.
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
43
|
+
const tell_agent_1 = require("./tell-agent");
|
|
44
|
+
/** The note in the agent's own words; the subject is the sender's, quoted as theirs. */
|
|
45
|
+
function letterExpiredNote(letter) {
|
|
46
|
+
return `letter ${letter.code} expired at ${letter.expiresAt} with no answer from my person; its sender gave it the subject ${JSON.stringify(letter.subject)}. it is closed, so it can't be answered or delivered now; mailbox_read shows it.`;
|
|
47
|
+
}
|
|
48
|
+
/** The private-runtime wake for one expired letter; its idempotency key makes a repeat a duplicate. */
|
|
49
|
+
function letterExpiredWake(agent, letter) {
|
|
50
|
+
return {
|
|
51
|
+
kind: "private.wake",
|
|
52
|
+
agent,
|
|
53
|
+
reason: `letter ${letter.code} expired`,
|
|
54
|
+
triggerSource: "letter-expired",
|
|
55
|
+
budgetClass: "interactive",
|
|
56
|
+
idempotencyKey: `letter-expired:${agent}:${letter.id}`,
|
|
57
|
+
originRefs: [{ kind: "letter", id: letter.id }, { kind: "scheduler", id: "letters-expiry" }],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** The daemon's onExpired: the note is dated by the expiry, so telling twice is one note. */
|
|
61
|
+
function letterExpiredTeller(bundlesRoot, wake) {
|
|
62
|
+
return async (agent, letter) => {
|
|
63
|
+
const note = { content: letterExpiredNote(letter), timestamp: Date.parse(letter.expiresAt), packetId: `letter-expired:${letter.id}` };
|
|
64
|
+
const problem = await (0, tell_agent_1.queueNoteAndWake)(agent, path.join(bundlesRoot, `${agent}.ouro`), note, () => wake(letterExpiredWake(agent, letter)));
|
|
65
|
+
if (problem === null) {
|
|
66
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.expired_told", message: "the agent was told a letter expired", meta: { code: letter.code } });
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.expired_wake_failed", message: "an expired letter's note waits for the agent's next private turn", meta: { code: letter.code, error: problem } });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -41,8 +41,8 @@ exports.letterFiledTeller = letterFiledTeller;
|
|
|
41
41
|
// decide whether and when its person sees the letter. The note goes to the agent's own private runtime, the way a
|
|
42
42
|
// habit that can't run tells it, and a wake has the agent read it now. It is the harness speaking, never the person.
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
|
-
const pending_1 = require("../../mind/pending");
|
|
45
44
|
const runtime_1 = require("../../nerves/runtime");
|
|
45
|
+
const tell_agent_1 = require("./tell-agent");
|
|
46
46
|
/** The note in the agent's own words, the way its private runtime notes read. */
|
|
47
47
|
function letterFiledNote(letter) {
|
|
48
48
|
// The lane and subject are the sender's words, quoted as theirs, so they can't read as the agent's own thought.
|
|
@@ -71,26 +71,13 @@ function letterFiledWake(agent, letter) {
|
|
|
71
71
|
*/
|
|
72
72
|
async function tellAgentLetterFiled(agent, agentRoot, letter, wake) {
|
|
73
73
|
// The queue names a note by its timestamp and packet id, so the letter's own filing time makes a repeat one note.
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
channel: "inner",
|
|
78
|
-
key: "dialog",
|
|
79
|
-
content: letterFiledNote(letter),
|
|
80
|
-
timestamp: Date.parse(letter.createdAt),
|
|
81
|
-
packetId: `letter-filed:${letter.id}`,
|
|
82
|
-
});
|
|
83
|
-
try {
|
|
84
|
-
const answer = await wake(letterFiledWake(agent, letter));
|
|
85
|
-
if (!answer.ok)
|
|
86
|
-
throw new Error(answer.error ?? "the wake was refused");
|
|
87
|
-
// A wake policy denies still answers ok; only an executable decision woke the agent.
|
|
88
|
-
if (answer.data?.decision?.executable === false)
|
|
89
|
-
throw new Error(answer.message ?? "the wake was denied");
|
|
74
|
+
const note = { content: letterFiledNote(letter), timestamp: Date.parse(letter.createdAt), packetId: `letter-filed:${letter.id}` };
|
|
75
|
+
const problem = await (0, tell_agent_1.queueNoteAndWake)(agent, agentRoot, note, () => wake(letterFiledWake(agent, letter)));
|
|
76
|
+
if (problem === null) {
|
|
90
77
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.filed_told", message: "the agent was told a letter was filed", meta: { code: letter.code } });
|
|
91
78
|
}
|
|
92
|
-
|
|
93
|
-
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.filed_wake_failed", message: "a filed letter's note waits for the agent's next private turn", meta: { code: letter.code, error:
|
|
79
|
+
else {
|
|
80
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.filed_wake_failed", message: "a filed letter's note waits for the agent's next private turn", meta: { code: letter.code, error: problem } });
|
|
94
81
|
}
|
|
95
82
|
}
|
|
96
83
|
/** The daemon's onFiled: each agent hears through its own bundle's private runtime. */
|
|
@@ -69,7 +69,8 @@ class LetterIndex {
|
|
|
69
69
|
for (const entry of this.byId.values()) {
|
|
70
70
|
if (dedupeScope(entry.letter) !== scope)
|
|
71
71
|
continue;
|
|
72
|
-
|
|
72
|
+
// A letter past its expiry is as good as expired, though the sweep hasn't closed it yet, so a new one is filed.
|
|
73
|
+
if (entry.state === "waiting" && !(entry.letter.expiresAt && Date.parse(entry.letter.expiresAt) <= now))
|
|
73
74
|
return { entry, why: "open" };
|
|
74
75
|
const answer = entry.events.find((event) => event.t === "answered");
|
|
75
76
|
if (answer && now - Date.parse(answer.at) <= exports.ANSWERED_DEDUPE_MS)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queueNoteAndWake = queueNoteAndWake;
|
|
4
|
+
// How the mailbox tells the agent that owns it about a letter: a note in its own private runtime, then a wake so it
|
|
5
|
+
// reads the note now. A wake that fails leaves the note queued for the agent's next private turn, so it is never lost.
|
|
6
|
+
const pending_1 = require("../../mind/pending");
|
|
7
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
8
|
+
/** Queues the note and wakes the agent: null once it is woken, or why the wake failed. A failed queue throws. */
|
|
9
|
+
async function queueNoteAndWake(agent, agentRoot, note, wake) {
|
|
10
|
+
(0, pending_1.queuePendingMessageOnce)((0, pending_1.getPrivateRuntimePendingDir)(agent, agentRoot), {
|
|
11
|
+
from: agent, friendId: "self", channel: "inner", key: "dialog", content: note.content, timestamp: note.timestamp, packetId: note.packetId,
|
|
12
|
+
});
|
|
13
|
+
let problem = null;
|
|
14
|
+
try {
|
|
15
|
+
const answer = await wake();
|
|
16
|
+
// A wake policy denies still answers ok; only an executable decision woke the agent.
|
|
17
|
+
if (!answer.ok)
|
|
18
|
+
problem = answer.error ?? "the wake was refused";
|
|
19
|
+
else if (answer.data?.decision?.executable === false)
|
|
20
|
+
problem = answer.message ?? "the wake was denied";
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
problem = error.message;
|
|
24
|
+
}
|
|
25
|
+
(0, runtime_1.emitNervesEvent)({ level: "debug", component: "daemon", event: "letters.agent_note_queued", message: "a mailbox note was queued for the agent", meta: { packetId: note.packetId, woken: problem === null } });
|
|
26
|
+
return problem;
|
|
27
|
+
}
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.LettersWriter = exports.ROLL_AFTER_MS = exports.DELIVER_DEADLINE_MS = exports.LetterRefusal = exports.ownerFriendIds = void 0;
|
|
36
|
+
exports.LettersWriter = exports.ROLL_AFTER_MS = exports.DELIVER_DEADLINE_MS = exports.EXPIRY_GRACE_MS = exports.NOW_LETTER_EXPIRY_MS = exports.LetterRefusal = exports.ownerFriendIds = void 0;
|
|
37
37
|
exports.answerLettersCommand = answerLettersCommand;
|
|
38
38
|
// The letters' single writer (design §3.2): the daemon holds one of these, and every door (CLI, MCP, in-turn tools)
|
|
39
39
|
// reaches it over the daemon's socket with a `letters.action` command. Each agent's letters live in its own bundle,
|
|
@@ -59,6 +59,14 @@ class LetterRefusal extends Error {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.LetterRefusal = LetterRefusal;
|
|
62
|
+
/** How long a `now` letter waits when its sender sets no expiresAt (design §3.4, "Expiry"); other letters never expire. */
|
|
63
|
+
exports.NOW_LETTER_EXPIRY_MS = 24 * 60 * 60_000;
|
|
64
|
+
/**
|
|
65
|
+
* How long past its expiresAt a letter stays open before the sweep closes it. An answer the person sent before the
|
|
66
|
+
* expiry still counts when it is read late (by a webhook that lags, or a catch-up pass after a restart), and that
|
|
67
|
+
* needs the letter still waiting when it is read.
|
|
68
|
+
*/
|
|
69
|
+
exports.EXPIRY_GRACE_MS = 10 * 60_000;
|
|
62
70
|
/** Under the door's own timeout for a deliver (doors.ts), so the daemon always answers before the door gives up. */
|
|
63
71
|
exports.DELIVER_DEADLINE_MS = 25_000;
|
|
64
72
|
/** Closed letters move to closed/YYYY-MM/ this long after they close (design §3.2); they are never deleted. */
|
|
@@ -128,6 +136,39 @@ class LettersWriter {
|
|
|
128
136
|
default: return Promise.reject(new LetterRefusal("unknown-door", `The mailbox has no action ${action}.`));
|
|
129
137
|
}
|
|
130
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Closes every waiting letter more than EXPIRY_GRACE_MS past its expiresAt, in each agent's bundle that has letters,
|
|
141
|
+
* and tells its agent.
|
|
142
|
+
* The daemon runs it on a timer; it answers how many letters it closed.
|
|
143
|
+
*/
|
|
144
|
+
async expireDue() {
|
|
145
|
+
let closed = 0;
|
|
146
|
+
for (const name of fs.readdirSync(this.deps.bundlesRoot)) {
|
|
147
|
+
const agent = name.endsWith(".ouro") ? name.slice(0, -".ouro".length) : "";
|
|
148
|
+
if (!AGENT_NAME.test(agent) || !fs.existsSync(path.join(this.deps.bundlesRoot, name, "state", "letters")))
|
|
149
|
+
continue;
|
|
150
|
+
try {
|
|
151
|
+
const letters = this.open(agent, false);
|
|
152
|
+
closed += await this.serial(letters, async () => {
|
|
153
|
+
const now = this.now();
|
|
154
|
+
const due = letters.index.list({}).filter((entry) => entry.letter.expiresAt && Date.parse(entry.letter.expiresAt) + exports.EXPIRY_GRACE_MS <= now.getTime());
|
|
155
|
+
for (const entry of due) {
|
|
156
|
+
this.addEvent(letters, entry.letter.id, { t: "expired", at: now.toISOString() });
|
|
157
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "letters.letter_expired", message: "a letter expired with no answer", meta: { code: entry.letter.code } });
|
|
158
|
+
this.deps.onExpired?.(agent, entry.letter).catch((error) => {
|
|
159
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.expired_tell_failed", message: "the agent could not be told a letter expired", meta: { code: entry.letter.code, reason: error.message } });
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return due.length;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
// One agent's letters that don't read leave the others' expiry alone.
|
|
167
|
+
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "daemon", event: "letters.expiry_failed", message: "an agent's letters could not be checked for expiry", meta: { agent, reason: error.message } });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return closed;
|
|
171
|
+
}
|
|
131
172
|
/** The agent's letters, read from its bundle the first time; letters closed long enough are rolled then, unless that first call is a dry run, which writes nothing. */
|
|
132
173
|
open(agent, dryRun) {
|
|
133
174
|
const bundle = path.join(this.deps.bundlesRoot, `${agent}.ouro`);
|
|
@@ -195,6 +236,9 @@ class LettersWriter {
|
|
|
195
236
|
const { lane, ...draft } = checked.letter;
|
|
196
237
|
const from = { agent: letters.agent, ...(lane ? { lane } : {}) };
|
|
197
238
|
const now = this.now();
|
|
239
|
+
if (draft.expiresAt && Date.parse(draft.expiresAt) <= now.getTime()) {
|
|
240
|
+
throw new LetterRefusal("invalid-letter", `expiresAt ${draft.expiresAt} has already passed. Fix: give a time in the future, or leave it out.`);
|
|
241
|
+
}
|
|
198
242
|
const duplicate = letters.index.findDuplicate({ from, dedupeKey: draft.dedupeKey }, now.getTime());
|
|
199
243
|
if (duplicate) {
|
|
200
244
|
const { letter } = duplicate.entry;
|
|
@@ -216,8 +260,10 @@ class LettersWriter {
|
|
|
216
260
|
letters.index.reserve(number + 1);
|
|
217
261
|
// The person's answering handle is frozen into the letter now, so a later change leaves this letter alone.
|
|
218
262
|
const answeringHandle = (0, answering_1.readAnsweringHandles)(letters.store.dir)[to];
|
|
263
|
+
const expiresAt = draft.expiresAt ?? (draft.urgency === "now" ? new Date(now.getTime() + exports.NOW_LETTER_EXPIRY_MS).toISOString() : undefined);
|
|
219
264
|
const letter = {
|
|
220
|
-
v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, ...(answeringHandle ? { answeringHandle } : {}), to, from, ...draft,
|
|
265
|
+
v: 1, id: (this.deps.newId ?? letter_1.newLetterId)(now.getTime()), code: `L${number}`, ...(answeringHandle ? { answeringHandle } : {}), to, from, ...draft,
|
|
266
|
+
...(expiresAt ? { expiresAt } : {}), createdAt: now.toISOString(),
|
|
221
267
|
};
|
|
222
268
|
try {
|
|
223
269
|
letters.store.create(letter);
|
|
@@ -201,6 +201,14 @@ async function evaluatePolicy(request, context, deps) {
|
|
|
201
201
|
reason: "a letter was filed for the agent's person",
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
|
+
if (request.triggerSource === "letter-expired"
|
|
205
|
+
&& hasNonEmptyOriginRef(originRefs, "letter")
|
|
206
|
+
&& hasOriginRef(originRefs, "scheduler", "letters-expiry")) {
|
|
207
|
+
return {
|
|
208
|
+
result: "allow",
|
|
209
|
+
reason: "a letter expired with no answer",
|
|
210
|
+
};
|
|
211
|
+
}
|
|
204
212
|
if (request.triggerSource === "letter-answered"
|
|
205
213
|
&& hasNonEmptyOriginRef(originRefs, "letter")
|
|
206
214
|
&& hasOriginRef(originRefs, "daemon-command", "letters.answer")) {
|
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.1646",
|
|
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.1646",
|
|
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.1646",
|
|
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": {
|