@ouro.bot/cli 0.1.0-alpha.1501 → 0.1.0-alpha.1502
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 +6 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/mailroom-copy-proof.js +158 -0
- package/dist/heart/daemon/state-retention.js +13 -1
- package/dist/mailroom/blob-store.js +17 -0
- package/dist/mailroom/core.js +8 -0
- package/dist/mailroom/reader.js +17 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
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.1502",
|
|
6
|
+
"changes": [
|
|
7
|
+
"State retention now deletes a gzipped local mail copy once Blob is proven to hold the same mail: under the same key, Blob's message records the same raw size and SHA-256, and its raw object exists. A copy whose upload it can't confirm stays, and the daemon logs counts only (`daemon.state_retention_mailroom_proven_copies`)."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1501",
|
|
6
12
|
"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.1502</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,158 @@
|
|
|
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.pruneProvenMailroomCopies = pruneProvenMailroomCopies;
|
|
37
|
+
const crypto_1 = require("crypto");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const zlib = __importStar(require("zlib"));
|
|
41
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
42
|
+
const core_1 = require("../../mailroom/core");
|
|
43
|
+
const DEFAULT_MAX_PER_PASS = 5000;
|
|
44
|
+
function emptyResult() {
|
|
45
|
+
return { checked: 0, deleted: 0, bytesFreed: 0, notInBlob: 0, mismatched: 0, unconfirmed: 0, localInvalid: 0, changed: 0, deferred: 0 };
|
|
46
|
+
}
|
|
47
|
+
function text(value) {
|
|
48
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
49
|
+
}
|
|
50
|
+
/** Reads a gzipped local copy and checks its raw file matches its own record; null when it doesn't. */
|
|
51
|
+
function readLocalCopy(root, messagePath) {
|
|
52
|
+
try {
|
|
53
|
+
const messageStat = fs.statSync(messagePath);
|
|
54
|
+
const record = JSON.parse(zlib.gunzipSync(fs.readFileSync(messagePath)).toString("utf-8"));
|
|
55
|
+
const id = text(record.id);
|
|
56
|
+
const rawObject = text(record.rawObject);
|
|
57
|
+
const rawSha256 = text(record.rawSha256);
|
|
58
|
+
if (!id || !rawObject || !rawSha256 || typeof record.rawSize !== "number")
|
|
59
|
+
return null;
|
|
60
|
+
const rawPath = path.resolve(root, `${rawObject}.gz`);
|
|
61
|
+
if (!rawPath.startsWith(path.join(path.resolve(root), "raw") + path.sep))
|
|
62
|
+
return null;
|
|
63
|
+
const rawStat = fs.statSync(rawPath);
|
|
64
|
+
const raw = zlib.gunzipSync(fs.readFileSync(rawPath));
|
|
65
|
+
if (raw.byteLength !== record.rawSize || (0, crypto_1.createHash)("sha256").update(raw).digest("hex") !== rawSha256)
|
|
66
|
+
return null;
|
|
67
|
+
const keys = [id];
|
|
68
|
+
const agentId = text(record.agentId);
|
|
69
|
+
const mailboxId = text(record.mailboxId);
|
|
70
|
+
const address = text(record.recipient);
|
|
71
|
+
if (agentId && mailboxId && address && record.envelope && typeof record.envelope === "object") {
|
|
72
|
+
keys.unshift((0, core_1.hostedMessageStorageId)(record.envelope, raw, { agentId, mailboxId, address }));
|
|
73
|
+
}
|
|
74
|
+
return { messagePath, rawPath, keys: [...new Set(keys)], rawSha256, rawSize: raw.byteLength, messageStat, rawStat };
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function verdictFor(copy, hosted) {
|
|
81
|
+
let mismatched = false;
|
|
82
|
+
for (const key of copy.keys) {
|
|
83
|
+
const record = await hosted.readMessage(key);
|
|
84
|
+
if (!record)
|
|
85
|
+
continue;
|
|
86
|
+
if (record.rawSha256 !== copy.rawSha256 || record.rawSize !== copy.rawSize) {
|
|
87
|
+
mismatched = true;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const rawObject = text(record.rawObject);
|
|
91
|
+
const size = rawObject ? await hosted.rawObjectSize(rawObject) : null;
|
|
92
|
+
if (size !== null && size > 0)
|
|
93
|
+
return "proven";
|
|
94
|
+
}
|
|
95
|
+
return mismatched ? "mismatched" : "not-in-blob";
|
|
96
|
+
}
|
|
97
|
+
function unchanged(before, file) {
|
|
98
|
+
try {
|
|
99
|
+
const after = fs.statSync(file);
|
|
100
|
+
return after.size === before.size && after.mtimeMs === before.mtimeMs;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function pruneProvenMailroomCopies(input) {
|
|
107
|
+
const result = emptyResult();
|
|
108
|
+
const messagesDir = path.join(input.mailroomRoot, "messages");
|
|
109
|
+
let names;
|
|
110
|
+
try {
|
|
111
|
+
names = fs.readdirSync(messagesDir).filter((name) => name.endsWith(".json.gz")).sort();
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
const limit = input.maxPerPass ?? DEFAULT_MAX_PER_PASS;
|
|
117
|
+
result.deferred = Math.max(0, names.length - limit);
|
|
118
|
+
for (const name of names.slice(0, limit)) {
|
|
119
|
+
result.checked += 1;
|
|
120
|
+
const copy = readLocalCopy(input.mailroomRoot, path.join(messagesDir, name));
|
|
121
|
+
if (!copy) {
|
|
122
|
+
result.localInvalid += 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
let verdict;
|
|
126
|
+
try {
|
|
127
|
+
verdict = await verdictFor(copy, input.hosted);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
result.unconfirmed += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (verdict === "not-in-blob") {
|
|
134
|
+
result.notInBlob += 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (verdict === "mismatched") {
|
|
138
|
+
result.mismatched += 1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (!unchanged(copy.rawStat, copy.rawPath) || !unchanged(copy.messageStat, copy.messagePath)) {
|
|
142
|
+
result.changed += 1;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// The raw file first: a message record without its raw file is caught as localInvalid next pass and kept.
|
|
146
|
+
fs.unlinkSync(copy.rawPath);
|
|
147
|
+
fs.unlinkSync(copy.messagePath);
|
|
148
|
+
result.deleted += 1;
|
|
149
|
+
result.bytesFreed += copy.rawStat.size + copy.messageStat.size;
|
|
150
|
+
}
|
|
151
|
+
(0, runtime_1.emitNervesEvent)({
|
|
152
|
+
component: "daemon",
|
|
153
|
+
event: "daemon.state_retention_mailroom_proven_copies",
|
|
154
|
+
message: "deleted gzipped local mail copies that Blob is proven to hold",
|
|
155
|
+
meta: { ...(input.agent ? { agent: input.agent } : {}), ...result },
|
|
156
|
+
});
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
@@ -179,6 +179,10 @@ function mailroomStoreFromRuntimeConfig(runtime) {
|
|
|
179
179
|
const account = mailroom && typeof mailroom === "object" ? mailroom.azureAccountUrl : undefined;
|
|
180
180
|
return typeof account === "string" && account.trim().length > 0 ? "hosted" : "local";
|
|
181
181
|
}
|
|
182
|
+
// Loaded only for an agent whose mail is hosted, so the daemon's startup doesn't load the mail store.
|
|
183
|
+
async function defaultHostedMailCopies(agent) {
|
|
184
|
+
return (await Promise.resolve().then(() => __importStar(require("../../mailroom/reader")))).openHostedMailCopies(agent);
|
|
185
|
+
}
|
|
182
186
|
/** Runs retention for each agent in turn; one agent's failure doesn't stop the rest. Telemetry is counts only. */
|
|
183
187
|
async function runAgentStateRetention(input) {
|
|
184
188
|
const compactSessions = input.compactSessions ?? compactLegacySessionArchives;
|
|
@@ -205,7 +209,15 @@ async function runAgentStateRetention(input) {
|
|
|
205
209
|
message: "gzipped the local mail file store once the agent's mail is hosted",
|
|
206
210
|
meta: { agent, ...mailroom },
|
|
207
211
|
});
|
|
208
|
-
|
|
212
|
+
const hosted = store === "hosted" ? await (input.hostedMailCopies ?? defaultHostedMailCopies)(agent) : null;
|
|
213
|
+
const mailroomCopies = hosted
|
|
214
|
+
? await (await Promise.resolve().then(() => __importStar(require("./mailroom-copy-proof")))).pruneProvenMailroomCopies({
|
|
215
|
+
mailroomRoot: path.join(input.bundlesRoot, `${agent}.ouro`, "state", "mailroom"),
|
|
216
|
+
hosted,
|
|
217
|
+
agent,
|
|
218
|
+
})
|
|
219
|
+
: null;
|
|
220
|
+
results.push({ agent, sessionArchives, mailroom, mailroomCopies });
|
|
209
221
|
}
|
|
210
222
|
catch (error) {
|
|
211
223
|
(0, runtime_1.emitNervesEvent)({
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AzureBlobMailroomStore = void 0;
|
|
4
4
|
exports.canonicalMailIndexRecordSnapshot = canonicalMailIndexRecordSnapshot;
|
|
5
5
|
exports.decryptBlobMessages = decryptBlobMessages;
|
|
6
|
+
exports.blobHostedMailCopies = blobHostedMailCopies;
|
|
6
7
|
const node_crypto_1 = require("node:crypto");
|
|
7
8
|
const runtime_1 = require("../nerves/runtime");
|
|
8
9
|
const core_1 = require("./core");
|
|
@@ -972,3 +973,19 @@ exports.AzureBlobMailroomStore = AzureBlobMailroomStore;
|
|
|
972
973
|
function decryptBlobMessages(messages, privateKeys) {
|
|
973
974
|
return messages.map((message) => (0, core_1.readDecryptedMailMessage)(message, privateKeys));
|
|
974
975
|
}
|
|
976
|
+
function blobHostedMailCopies(container, timeoutMs = DEFAULT_BLOB_OPERATION_TIMEOUT_MS) {
|
|
977
|
+
return {
|
|
978
|
+
readMessage: (id) => downloadJson(container.getBlockBlobClient(`messages/${id}.json`), timeoutMs),
|
|
979
|
+
rawObjectSize: async (name) => {
|
|
980
|
+
try {
|
|
981
|
+
const properties = await withBlobOperationTimeout(timeoutMs, (abortSignal) => container.getBlockBlobClient(name).getProperties({ abortSignal }));
|
|
982
|
+
return typeof properties.contentLength === "number" ? properties.contentLength : null;
|
|
983
|
+
}
|
|
984
|
+
catch (error) {
|
|
985
|
+
if (isBlobNotFoundError(error))
|
|
986
|
+
return null;
|
|
987
|
+
throw error;
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
};
|
|
991
|
+
}
|
package/dist/mailroom/core.js
CHANGED
|
@@ -47,6 +47,7 @@ exports.encryptJsonForMailKey = encryptJsonForMailKey;
|
|
|
47
47
|
exports.decryptMailJson = decryptMailJson;
|
|
48
48
|
exports.resolveMailAddress = resolveMailAddress;
|
|
49
49
|
exports.describeMailProvenance = describeMailProvenance;
|
|
50
|
+
exports.hostedMessageStorageId = hostedMessageStorageId;
|
|
50
51
|
exports.htmlMailBodyToText = htmlMailBodyToText;
|
|
51
52
|
exports.privateMailEnvelopeReadableText = privateMailEnvelopeReadableText;
|
|
52
53
|
exports.buildStoredMailMessageMetadata = buildStoredMailMessageMetadata;
|
|
@@ -394,6 +395,13 @@ function messageStorageId(envelope, raw, destination) {
|
|
|
394
395
|
const value = digest.digest("hex");
|
|
395
396
|
return `mail_${value.slice(0, 32)}`;
|
|
396
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* The id the hosted (Blob) store gives a message: the local file store's id plus its destination. Retention uses it to
|
|
400
|
+
* find a local copy's hosted counterpart before deleting the local copy.
|
|
401
|
+
*/
|
|
402
|
+
function hostedMessageStorageId(envelope, raw, destination) {
|
|
403
|
+
return messageStorageId(envelope, raw, destination);
|
|
404
|
+
}
|
|
397
405
|
function candidateSender(input) {
|
|
398
406
|
const parsed = input.parsedFrom[0];
|
|
399
407
|
if (parsed)
|
package/dist/mailroom/reader.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.parseMailroomConfig = parseMailroomConfig;
|
|
|
37
37
|
exports.readMailroomRegistry = readMailroomRegistry;
|
|
38
38
|
exports.writeMailroomRegistry = writeMailroomRegistry;
|
|
39
39
|
exports.resolveMailroomReader = resolveMailroomReader;
|
|
40
|
+
exports.openHostedMailCopies = openHostedMailCopies;
|
|
40
41
|
exports.resolveHostedMailAuthority = resolveHostedMailAuthority;
|
|
41
42
|
exports.resolveMailroomReaderWithRefresh = resolveMailroomReaderWithRefresh;
|
|
42
43
|
const fs = __importStar(require("node:fs"));
|
|
@@ -223,6 +224,22 @@ function resolveMailroomReader(agentName = (0, identity_1.getAgentName)()) {
|
|
|
223
224
|
});
|
|
224
225
|
return result;
|
|
225
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Read-only lookups in the agent's hosted mail container, for retention to prove a local copy was uploaded before it
|
|
229
|
+
* deletes it. Null when the agent's mail isn't hosted or its runtime config can't be read.
|
|
230
|
+
*/
|
|
231
|
+
function openHostedMailCopies(agentName) {
|
|
232
|
+
const runtime = (0, runtime_credentials_1.readRuntimeCredentialConfig)(agentName);
|
|
233
|
+
if (!runtime.ok)
|
|
234
|
+
return null;
|
|
235
|
+
const mailroom = isRecord(runtime.config.mailroom) ? runtime.config.mailroom : null;
|
|
236
|
+
const azureAccountUrl = mailroom ? textField(mailroom, "azureAccountUrl") : undefined;
|
|
237
|
+
if (!mailroom || !azureAccountUrl)
|
|
238
|
+
return null;
|
|
239
|
+
const container = createBlobServiceClient(azureAccountUrl, textField(mailroom, "azureManagedIdentityClientId"))
|
|
240
|
+
.getContainerClient(textField(mailroom, "azureContainer") ?? "mailroom");
|
|
241
|
+
return (0, blob_store_1.blobHostedMailCopies)(container);
|
|
242
|
+
}
|
|
226
243
|
function resolveHostedMailAuthority(agentName = (0, identity_1.getAgentName)()) {
|
|
227
244
|
const runtime = (0, runtime_credentials_1.readRuntimeCredentialConfig)(agentName);
|
|
228
245
|
if (!runtime.ok) {
|
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.1502",
|
|
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.1502",
|
|
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.1502",
|
|
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": {
|