@ouro.bot/cli 0.1.0-alpha.1124 → 0.1.0-alpha.1125
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/senses/app-sessions/client.js +15 -0
- package/dist/senses/app-sessions/sense.js +1 -1
- package/dist/senses/app-sessions/wake-runner.js +30 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1125",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Wake runners hold a wake while the last one sent to the same session has not reached it, so the app's own queue never fills with hours-old wakes that arrive one per turn; the command offers the news again on its next run."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1124",
|
|
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.1125</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -42,6 +42,7 @@ exports.assertSessionId = assertSessionId;
|
|
|
42
42
|
exports.eventLogPath = eventLogPath;
|
|
43
43
|
exports.readEventLog = readEventLog;
|
|
44
44
|
exports.parseEventLines = parseEventLines;
|
|
45
|
+
exports.messageDelivered = messageDelivered;
|
|
45
46
|
exports.describePermission = describePermission;
|
|
46
47
|
exports.tailFacts = tailFacts;
|
|
47
48
|
exports.classify = classify;
|
|
@@ -195,6 +196,20 @@ function parseEventLines(text) {
|
|
|
195
196
|
function tailEvents(stateDir, id, bytes) {
|
|
196
197
|
return parseEventLines(readEventLog(id, { stateDir, maxBytes: bytes }).text);
|
|
197
198
|
}
|
|
199
|
+
const DELIVERY_TAIL_BYTES = 4 * 1024 * 1024;
|
|
200
|
+
const DELIVERY_CLOCK_SLACK_MS = 60_000;
|
|
201
|
+
const squash = (text) => text.replace(/\s+/g, " ").trim();
|
|
202
|
+
/**
|
|
203
|
+
* Whether a message sent at `sinceMs` has reached the session: its log holds a user message that starts with the same
|
|
204
|
+
* text. A message the app accepted but still holds in its own queue is not in the log yet.
|
|
205
|
+
*/
|
|
206
|
+
function messageDelivered(id, text, sinceMs, options = {}) {
|
|
207
|
+
const probe = squash(text).slice(0, 160);
|
|
208
|
+
return parseEventLines(readEventLog(id, { ...options, maxBytes: DELIVERY_TAIL_BYTES }).text).some(event => {
|
|
209
|
+
const data = isRecord(event.data) ? event.data : {};
|
|
210
|
+
return event.type === "user.message" && Date.parse(str(event.timestamp) ?? "") >= sinceMs - DELIVERY_CLOCK_SLACK_MS && squash(str(data.content) ?? "").includes(probe);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
198
213
|
const PERMISSION_WHAT = {
|
|
199
214
|
shell: "run a shell command",
|
|
200
215
|
write: "change a file",
|
|
@@ -200,7 +200,7 @@ function startAppSessionsSense(options) {
|
|
|
200
200
|
const runnerTick = () => {
|
|
201
201
|
if (stopped)
|
|
202
202
|
return;
|
|
203
|
-
runnerPoll = checkWakeRunners(options.agentName, agentRoot, { run: options.runCommand ?? wake_runner_1.runCommand, send: options.sendWake ?? (0, wake_runner_1.sendWake)(client), now: now() }, due).then(ms => {
|
|
203
|
+
runnerPoll = checkWakeRunners(options.agentName, agentRoot, { run: options.runCommand ?? wake_runner_1.runCommand, send: options.sendWake ?? (0, wake_runner_1.sendWake)(client), delivered: options.wasDelivered ?? (0, wake_runner_1.wasDelivered)(client), now: now() }, due).then(ms => {
|
|
204
204
|
if (!stopped)
|
|
205
205
|
cancelRunners = schedule(runnerTick, ms);
|
|
206
206
|
});
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.sendWake = exports.runCommand = exports.WAKE_RUNNER_TIMEOUT_MS = exports.WAKE_RUNNER_DEFAULT_SECONDS = void 0;
|
|
36
|
+
exports.sendWake = exports.wasDelivered = exports.runCommand = exports.WAKE_HOLD_MS = exports.WAKE_RUNNER_TIMEOUT_MS = exports.WAKE_RUNNER_DEFAULT_SECONDS = void 0;
|
|
37
37
|
exports.parseWakeOutput = parseWakeOutput;
|
|
38
38
|
exports.runWakeRunner = runWakeRunner;
|
|
39
39
|
exports.runWakeRunners = runWakeRunners;
|
|
@@ -56,9 +56,15 @@ const wake_runner_state_1 = require("./wake-runner-state");
|
|
|
56
56
|
* A wake is delivered "immediate" by default: the app admits it at the session's next turn boundary. A session that works for
|
|
57
57
|
* hours in one run never goes idle, so a message queued behind that run ("enqueue") waits until the run ends, however old the
|
|
58
58
|
* news in it. A runner can ask for "enqueue" when a wake should never interrupt.
|
|
59
|
+
*
|
|
60
|
+
* The app holds an accepted message in its own queue until the session reaches a turn boundary, and it cannot be taken back.
|
|
61
|
+
* So a session gets one wake at a time: while the last wake sent to it has not shown up in its log, the next wake is held
|
|
62
|
+
* and reported undelivered, and the command, which re-derives its state every run, offers it again. A wake still missing
|
|
63
|
+
* after `WAKE_HOLD_MS` is taken as lost. Held wakes never pile up in the app as hours-old news.
|
|
59
64
|
*/
|
|
60
65
|
exports.WAKE_RUNNER_DEFAULT_SECONDS = 300;
|
|
61
66
|
exports.WAKE_RUNNER_TIMEOUT_MS = 2 * 60_000;
|
|
67
|
+
exports.WAKE_HOLD_MS = 30 * 60_000;
|
|
62
68
|
const MAX_STATUS_LINES = 20;
|
|
63
69
|
const MAX_LINE = 300;
|
|
64
70
|
const MAX_OUTPUT = 10 * 1024 * 1024;
|
|
@@ -100,14 +106,19 @@ const runCommand = (argv, timeoutMs) => new Promise(resolve => {
|
|
|
100
106
|
});
|
|
101
107
|
});
|
|
102
108
|
exports.runCommand = runCommand;
|
|
109
|
+
const wasDelivered = (client) => (session, message, sinceMs) => (0, client_1.messageDelivered)(session, message, sinceMs, client);
|
|
110
|
+
exports.wasDelivered = wasDelivered;
|
|
103
111
|
const sendWake = (client) => async (session, message, delivery) => {
|
|
104
112
|
const result = await (0, client_1.sendToAppSession)(session, message, { ...client, delivery });
|
|
105
113
|
return { ok: result.ok, error: result.error };
|
|
106
114
|
};
|
|
107
115
|
exports.sendWake = sendWake;
|
|
108
116
|
/** Run one runner's command, deliver its wakes and report each one back. Returns the runner's new state. */
|
|
109
|
-
async function runWakeRunner(runner, deps) {
|
|
117
|
+
async function runWakeRunner(runner, deps, previous = {}) {
|
|
110
118
|
const state = { lastRunAt: new Date(deps.now).toISOString() };
|
|
119
|
+
const open = openWakes(previous, deps);
|
|
120
|
+
if (Object.keys(open).length)
|
|
121
|
+
state.open = open;
|
|
111
122
|
const ran = await deps.run(runner.command, exports.WAKE_RUNNER_TIMEOUT_MS);
|
|
112
123
|
if (!ran.ok)
|
|
113
124
|
return fail(runner, state, ran.error ?? "the command failed");
|
|
@@ -124,9 +135,14 @@ async function runWakeRunner(runner, deps) {
|
|
|
124
135
|
const problems = [];
|
|
125
136
|
for (const wake of output.wakes) {
|
|
126
137
|
const session = wake.session ?? runner.session;
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
const holding = session ? state.open?.[session] : undefined;
|
|
139
|
+
const sent = !session
|
|
140
|
+
? { ok: false, error: "the wake names no session and the runner has none" }
|
|
141
|
+
: holding
|
|
142
|
+
? { ok: false, error: `held: the wake sent ${ageLabel(deps.now - Date.parse(holding.at))} ago has not reached the session yet` }
|
|
143
|
+
: await deps.send(session, wake.message, runner.delivery ?? "immediate").catch((error) => ({ ok: false, error: error.message }));
|
|
144
|
+
if (session && sent.ok)
|
|
145
|
+
(state.open ??= {})[session] = { at: new Date(deps.now).toISOString(), message: wake.message };
|
|
130
146
|
const reason = sent.ok ? null : sent.error ?? "the app refused the message";
|
|
131
147
|
if (!reason)
|
|
132
148
|
state.lastDelivered += 1;
|
|
@@ -143,6 +159,14 @@ async function runWakeRunner(runner, deps) {
|
|
|
143
159
|
(0, runtime_1.emitNervesEvent)({ level: problems.length ? "warn" : "info", component: "senses", event: "senses.wake_runner_run", message: "ran a wake runner and delivered its wakes", meta: { runner: runner.name, wakes: state.lastWakes, delivered: state.lastDelivered, problems: problems.length } });
|
|
144
160
|
return state;
|
|
145
161
|
}
|
|
162
|
+
const ageLabel = (ms) => `${Math.max(1, Math.round(ms / 60_000))} min`;
|
|
163
|
+
/** The wakes sent earlier that are still in the app's queue, by session: the ones the session's log does not show and that are younger than the hold. */
|
|
164
|
+
function openWakes(previous, deps) {
|
|
165
|
+
return Object.fromEntries(Object.entries(previous.open ?? {}).filter(([session, wake]) => {
|
|
166
|
+
const sentAt = Date.parse(wake.at);
|
|
167
|
+
return deps.now - sentAt < exports.WAKE_HOLD_MS && !deps.delivered(session, wake.message, sentAt);
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
146
170
|
function fail(runner, state, reason) {
|
|
147
171
|
state.lastError = reason;
|
|
148
172
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "senses", event: "senses.wake_runner_error", message: "a wake runner's command did not give wakes; nothing was delivered", meta: { runner: runner.name, error: reason } });
|
|
@@ -154,6 +178,6 @@ async function runWakeRunners(agentRoot, runners, deps, only) {
|
|
|
154
178
|
const states = Object.fromEntries(runners.map(runner => [runner.name, stored[runner.name] ?? {}]));
|
|
155
179
|
for (const runner of runners)
|
|
156
180
|
if (!only || only.has(runner.name))
|
|
157
|
-
states[runner.name] = await runWakeRunner(runner, deps);
|
|
181
|
+
states[runner.name] = await runWakeRunner(runner, deps, stored[runner.name]);
|
|
158
182
|
(0, store_1.writeJson)((0, wake_runner_state_1.wakeRunnerStateFile)(agentRoot), states);
|
|
159
183
|
}
|
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.1125",
|
|
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.1125",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|