@ouro.bot/cli 0.1.0-alpha.1472 → 0.1.0-alpha.1474
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,13 @@
|
|
|
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.1474",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The daemon now gzips session archives (`*.archive.ndjson`) that nothing has written for a week, 10 minutes after it starts and then once a day. Nothing has read these files since May 2026. Each gzip is checked to give back the same bytes before the original is removed, and the daemon logs counts only (`daemon.state_retention_session_archives`).",
|
|
8
|
+
"Once an agent's mail is hosted (`mailroom.azureAccountUrl`), the daemon gzips the leftover local mail file store (`state/mailroom/messages` and `raw`), for messages older than 30 days. It never touches the file store while it holds the agent's mail, or when the daemon can't tell where the mail lives. It keeps `registry.json`, checks every gzip before removing the original, and logs counts only (`daemon.state_retention_mailroom`)."
|
|
9
|
+
]
|
|
10
|
+
},
|
|
4
11
|
{
|
|
5
12
|
"version": "0.1.0-alpha.1472",
|
|
6
13
|
"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.1474</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -51,6 +51,7 @@ const os = __importStar(require("os"));
|
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const node_crypto_1 = require("node:crypto");
|
|
53
53
|
const identity_1 = require("../identity");
|
|
54
|
+
const state_retention_1 = require("./state-retention");
|
|
54
55
|
const agent_discovery_1 = require("./agent-discovery");
|
|
55
56
|
const runtime_1 = require("../../nerves/runtime");
|
|
56
57
|
const runtime_metadata_1 = require("./runtime-metadata");
|
|
@@ -613,6 +614,8 @@ function defaultSelfUpdateLauncher() {
|
|
|
613
614
|
return async () => (await Promise.resolve().then(() => __importStar(require("../versioning/self-update-defaults")))).launchUnattendedSelfUpdate();
|
|
614
615
|
}
|
|
615
616
|
/* v8 ignore stop */
|
|
617
|
+
const STATE_RETENTION_FIRST_DELAY_MS = 10 * 60_000;
|
|
618
|
+
const STATE_RETENTION_INTERVAL_MS = 24 * 60 * 60_000;
|
|
616
619
|
class OuroDaemon {
|
|
617
620
|
socketPath;
|
|
618
621
|
processManager;
|
|
@@ -627,6 +630,8 @@ class OuroDaemon {
|
|
|
627
630
|
socketIdentity = null;
|
|
628
631
|
senseAutostartTimer = null;
|
|
629
632
|
externalEventReconcileTimer = null;
|
|
633
|
+
stateRetentionTimer = null;
|
|
634
|
+
stateRetention;
|
|
630
635
|
externalEventReconcileRunning = false;
|
|
631
636
|
constructedAtMs = Date.now();
|
|
632
637
|
frontendSocketPath;
|
|
@@ -682,6 +687,11 @@ class OuroDaemon {
|
|
|
682
687
|
this.schedulerFireVerifier = options.schedulerFireVerifier;
|
|
683
688
|
this.schedulerFireConsumer = options.schedulerFireConsumer;
|
|
684
689
|
this.orphanStartupDrain = options.orphanStartupDrain ?? drainOrphanProcessesBeforeStartup;
|
|
690
|
+
this.stateRetention = options.stateRetention ?? (() => (0, state_retention_1.runAgentStateRetention)({
|
|
691
|
+
bundlesRoot: this.bundlesRoot,
|
|
692
|
+
// Only agents homed here: another machine's daemon looks after its own agents' state.
|
|
693
|
+
agents: (0, agent_discovery_1.listHomeBundleAgents)({ bundlesRoot: this.bundlesRoot }),
|
|
694
|
+
}));
|
|
685
695
|
this.socketAnswering = options.socketAnswering ?? socket_client_1.checkDaemonSocketAlive;
|
|
686
696
|
this.selfUpdateLauncher = options.selfUpdateLauncher !== undefined ? options.selfUpdateLauncher : defaultSelfUpdateLauncher();
|
|
687
697
|
this.externalEventSourceReadiness = options.externalEventSourceReadiness ?? (async (agent, source) => {
|
|
@@ -850,6 +860,7 @@ class OuroDaemon {
|
|
|
850
860
|
void this.reconcileExternalEvents();
|
|
851
861
|
}, 1_000);
|
|
852
862
|
this.externalEventReconcileTimer.unref?.();
|
|
863
|
+
this.scheduleStateRetention(STATE_RETENTION_FIRST_DELAY_MS);
|
|
853
864
|
// Write all managed PIDs to disk so the next daemon can clean up
|
|
854
865
|
/* v8 ignore start -- pidfile write: collects PIDs from process managers @preserve */
|
|
855
866
|
const agentPids = this.processManager.listAgentSnapshots().map((s) => s.pid).filter((p) => p !== null);
|
|
@@ -876,6 +887,16 @@ class OuroDaemon {
|
|
|
876
887
|
});
|
|
877
888
|
}
|
|
878
889
|
}
|
|
890
|
+
// Waits after start so a restart isn't slowed by it; a failed pass is logged by retention and tried again tomorrow.
|
|
891
|
+
scheduleStateRetention(delayMs) {
|
|
892
|
+
this.stateRetentionTimer = setTimeout(() => {
|
|
893
|
+
void this.stateRetention().catch(() => undefined).finally(() => {
|
|
894
|
+
if (this.stateRetentionTimer)
|
|
895
|
+
this.scheduleStateRetention(STATE_RETENTION_INTERVAL_MS);
|
|
896
|
+
});
|
|
897
|
+
}, delayMs);
|
|
898
|
+
this.stateRetentionTimer.unref?.();
|
|
899
|
+
}
|
|
879
900
|
triggerAutoStartAgents() {
|
|
880
901
|
if (this.processManager.triggerAutoStartAgents) {
|
|
881
902
|
this.processManager.triggerAutoStartAgents();
|
|
@@ -1161,6 +1182,10 @@ class OuroDaemon {
|
|
|
1161
1182
|
clearInterval(this.externalEventReconcileTimer);
|
|
1162
1183
|
this.externalEventReconcileTimer = null;
|
|
1163
1184
|
}
|
|
1185
|
+
if (this.stateRetentionTimer) {
|
|
1186
|
+
clearTimeout(this.stateRetentionTimer);
|
|
1187
|
+
this.stateRetentionTimer = null;
|
|
1188
|
+
}
|
|
1164
1189
|
const workerStopTasks = [
|
|
1165
1190
|
Promise.resolve().then(() => this.processManager.stopAll()),
|
|
1166
1191
|
Promise.resolve().then(() => (0, mcp_manager_1.shutdownSharedMcpManager)()),
|
|
@@ -0,0 +1,222 @@
|
|
|
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.compactLegacySessionArchives = compactLegacySessionArchives;
|
|
37
|
+
exports.compactUnusedMailroomFileStore = compactUnusedMailroomFileStore;
|
|
38
|
+
exports.mailroomStoreFromRuntimeConfig = mailroomStoreFromRuntimeConfig;
|
|
39
|
+
exports.runAgentStateRetention = runAgentStateRetention;
|
|
40
|
+
const crypto_1 = require("crypto");
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const stream_1 = require("stream");
|
|
44
|
+
const promises_1 = require("stream/promises");
|
|
45
|
+
const zlib = __importStar(require("zlib"));
|
|
46
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
47
|
+
const runtime_credentials_1 = require("../runtime-credentials");
|
|
48
|
+
const ARCHIVE_SUFFIX = ".archive.ndjson";
|
|
49
|
+
const DEFAULT_MIN_IDLE_MS = 7 * 24 * 60 * 60_000;
|
|
50
|
+
const MAILROOM_MIN_IDLE_MS = 30 * 24 * 60 * 60_000;
|
|
51
|
+
const MAILROOM_FILE_STORE_DIRS = ["messages", "raw"];
|
|
52
|
+
function emptyResult() {
|
|
53
|
+
return { compacted: 0, skippedRecent: 0, failed: 0, bytesBefore: 0, bytesAfter: 0 };
|
|
54
|
+
}
|
|
55
|
+
function findArchives(root) {
|
|
56
|
+
const found = [];
|
|
57
|
+
const walk = (dir) => {
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
const full = path.join(dir, entry.name);
|
|
67
|
+
if (entry.isDirectory())
|
|
68
|
+
walk(full);
|
|
69
|
+
else if (entry.isFile() && entry.name.endsWith(ARCHIVE_SUFFIX))
|
|
70
|
+
found.push(full);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
walk(root);
|
|
74
|
+
return found.sort();
|
|
75
|
+
}
|
|
76
|
+
function hashingStream(hash) {
|
|
77
|
+
return new stream_1.Transform({
|
|
78
|
+
transform(chunk, _encoding, callback) {
|
|
79
|
+
hash.update(chunk);
|
|
80
|
+
callback(null, chunk);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async function sha256OfFile(file) {
|
|
85
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
86
|
+
await (0, promises_1.pipeline)(fs.createReadStream(file), hashingStream(hash), new stream_1.PassThrough().resume());
|
|
87
|
+
return hash.digest("hex");
|
|
88
|
+
}
|
|
89
|
+
async function sha256OfGunzip(file) {
|
|
90
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
91
|
+
await (0, promises_1.pipeline)(fs.createReadStream(file), zlib.createGunzip(), hashingStream(hash), new stream_1.PassThrough().resume());
|
|
92
|
+
return hash.digest("hex");
|
|
93
|
+
}
|
|
94
|
+
function unchanged(before, file) {
|
|
95
|
+
const after = fs.statSync(file);
|
|
96
|
+
return after.size === before.size && after.mtimeMs === before.mtimeMs;
|
|
97
|
+
}
|
|
98
|
+
/** Gzips one archive in place. Returns the gzip's size, or null when the archive was kept as it is. */
|
|
99
|
+
async function compactArchive(file, before, beforeCommit) {
|
|
100
|
+
const gz = `${file}.gz`;
|
|
101
|
+
if (fs.existsSync(gz)) {
|
|
102
|
+
// An earlier pass wrote the gzip and stopped before removing the archive; finish only if they match.
|
|
103
|
+
const [original, packed] = await Promise.all([sha256OfFile(file), sha256OfGunzip(gz).catch(() => null)]);
|
|
104
|
+
if (original !== packed || !unchanged(before, file))
|
|
105
|
+
return null;
|
|
106
|
+
fs.unlinkSync(file);
|
|
107
|
+
return fs.statSync(gz).size;
|
|
108
|
+
}
|
|
109
|
+
const tmp = `${gz}.tmp-${process.pid}`;
|
|
110
|
+
try {
|
|
111
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
112
|
+
await (0, promises_1.pipeline)(fs.createReadStream(file), hashingStream(hash), zlib.createGzip({ level: 6 }), fs.createWriteStream(tmp));
|
|
113
|
+
const original = hash.digest("hex");
|
|
114
|
+
const packed = await sha256OfGunzip(tmp);
|
|
115
|
+
beforeCommit?.(file);
|
|
116
|
+
if (original !== packed || !unchanged(before, file)) {
|
|
117
|
+
fs.rmSync(tmp, { force: true });
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
fs.renameSync(tmp, gz);
|
|
121
|
+
fs.unlinkSync(file);
|
|
122
|
+
return fs.statSync(gz).size;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
fs.rmSync(tmp, { force: true });
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function compactFiles(files, now, minIdleMs, beforeCommit) {
|
|
130
|
+
const result = emptyResult();
|
|
131
|
+
for (const file of files) {
|
|
132
|
+
const before = fs.statSync(file);
|
|
133
|
+
if (now - before.mtimeMs < minIdleMs) {
|
|
134
|
+
result.skippedRecent += 1;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const packedSize = await compactArchive(file, before, beforeCommit).catch(() => null);
|
|
138
|
+
if (packedSize === null) {
|
|
139
|
+
result.failed += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
result.compacted += 1;
|
|
143
|
+
result.bytesBefore += before.size;
|
|
144
|
+
result.bytesAfter += packedSize;
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
async function compactLegacySessionArchives(input) {
|
|
149
|
+
return compactFiles(findArchives(input.sessionsRoot), (input.now ?? Date.now)(), input.minIdleMs ?? DEFAULT_MIN_IDLE_MS, input.beforeCommit);
|
|
150
|
+
}
|
|
151
|
+
function findMailroomFiles(root) {
|
|
152
|
+
return MAILROOM_FILE_STORE_DIRS.flatMap((dir) => {
|
|
153
|
+
const full = path.join(root, dir);
|
|
154
|
+
let entries;
|
|
155
|
+
try {
|
|
156
|
+
entries = fs.readdirSync(full, { withFileTypes: true });
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
return entries
|
|
162
|
+
.filter((entry) => entry.isFile() && !entry.name.endsWith(".gz") && !entry.name.includes(".gz.tmp-"))
|
|
163
|
+
.map((entry) => path.join(full, entry.name))
|
|
164
|
+
.sort();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/** Gzips the local mailroom file store's messages, only once the agent's mail is hosted somewhere else. */
|
|
168
|
+
async function compactUnusedMailroomFileStore(input) {
|
|
169
|
+
if (input.store !== "hosted")
|
|
170
|
+
return { store: input.store, ...emptyResult() };
|
|
171
|
+
const result = await compactFiles(findMailroomFiles(input.mailroomRoot), (input.now ?? Date.now)(), input.minIdleMs ?? MAILROOM_MIN_IDLE_MS);
|
|
172
|
+
return { store: input.store, ...result };
|
|
173
|
+
}
|
|
174
|
+
/** Where the agent's mail lives, by the same rule as `mailroom/reader.ts`: hosted when it names an Azure account. */
|
|
175
|
+
function mailroomStoreFromRuntimeConfig(runtime) {
|
|
176
|
+
if (!runtime.ok)
|
|
177
|
+
return "unknown";
|
|
178
|
+
const mailroom = runtime.config?.mailroom;
|
|
179
|
+
const account = mailroom && typeof mailroom === "object" ? mailroom.azureAccountUrl : undefined;
|
|
180
|
+
return typeof account === "string" && account.trim().length > 0 ? "hosted" : "local";
|
|
181
|
+
}
|
|
182
|
+
/** Runs retention for each agent in turn; one agent's failure doesn't stop the rest. Telemetry is counts only. */
|
|
183
|
+
async function runAgentStateRetention(input) {
|
|
184
|
+
const compactSessions = input.compactSessions ?? compactLegacySessionArchives;
|
|
185
|
+
const results = [];
|
|
186
|
+
for (const agent of input.agents) {
|
|
187
|
+
try {
|
|
188
|
+
const sessionsRoot = path.join(input.bundlesRoot, `${agent}.ouro`, "state", "sessions");
|
|
189
|
+
const sessionArchives = await compactSessions({ sessionsRoot, now: input.now });
|
|
190
|
+
(0, runtime_1.emitNervesEvent)({
|
|
191
|
+
component: "daemon",
|
|
192
|
+
event: "daemon.state_retention_session_archives",
|
|
193
|
+
message: "gzipped session archives nothing reads any more",
|
|
194
|
+
meta: { agent, ...sessionArchives },
|
|
195
|
+
});
|
|
196
|
+
const store = (input.mailroomStore ?? ((name) => mailroomStoreFromRuntimeConfig((0, runtime_credentials_1.readRuntimeCredentialConfig)(name))))(agent);
|
|
197
|
+
const mailroom = await compactUnusedMailroomFileStore({
|
|
198
|
+
mailroomRoot: path.join(input.bundlesRoot, `${agent}.ouro`, "state", "mailroom"),
|
|
199
|
+
store,
|
|
200
|
+
now: input.now,
|
|
201
|
+
});
|
|
202
|
+
(0, runtime_1.emitNervesEvent)({
|
|
203
|
+
component: "daemon",
|
|
204
|
+
event: "daemon.state_retention_mailroom",
|
|
205
|
+
message: "gzipped the local mail file store once the agent's mail is hosted",
|
|
206
|
+
meta: { agent, ...mailroom },
|
|
207
|
+
});
|
|
208
|
+
results.push({ agent, sessionArchives, mailroom });
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
(0, runtime_1.emitNervesEvent)({
|
|
212
|
+
level: "warn",
|
|
213
|
+
component: "daemon",
|
|
214
|
+
event: "daemon.state_retention_error",
|
|
215
|
+
message: "state retention failed for one agent",
|
|
216
|
+
// A code, never a message: messages carry paths.
|
|
217
|
+
meta: { agent, errorCode: error?.code ?? "unknown" },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return results;
|
|
222
|
+
}
|
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.1474",
|
|
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.1474",
|
|
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.1474",
|
|
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": {
|