@ouro.bot/cli 0.1.0-alpha.1129 → 0.1.0-alpha.1130
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,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.1130",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Wake runners take back older wakes a newer one replaces: a wake can name a message prefix, and the session's own app queue is cleared of the user-side messages with that prefix before it is sent, so stale wakes no longer sit in the queue and arrive one per turn."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
4
10
|
{
|
|
5
11
|
"version": "0.1.0-alpha.1129",
|
|
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.1130</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -55,6 +55,8 @@ exports.messagesIn = messagesIn;
|
|
|
55
55
|
exports.eventLogSize = eventLogSize;
|
|
56
56
|
exports.exchange = exchange;
|
|
57
57
|
exports.sendToAppSession = sendToAppSession;
|
|
58
|
+
exports.listSessionQueue = listSessionQueue;
|
|
59
|
+
exports.withdrawQueuedMessages = withdrawQueuedMessages;
|
|
58
60
|
exports.resumePrompt = resumePrompt;
|
|
59
61
|
exports.resumeAppSession = resumeAppSession;
|
|
60
62
|
exports.openAppChat = openAppChat;
|
|
@@ -599,6 +601,31 @@ async function sendToAppSession(id, text, options = {}) {
|
|
|
599
601
|
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_sent", message: "sent a message into a Copilot app session", meta: { session: id, chars: text.length, ok, reply: result.reply } });
|
|
600
602
|
return result;
|
|
601
603
|
}
|
|
604
|
+
/** The session's queued messages, oldest first. An empty list when the session has none or the app cannot say. */
|
|
605
|
+
async function listSessionQueue(id, options = {}) {
|
|
606
|
+
assertSessionId(id);
|
|
607
|
+
const requestId = (0, node_crypto_1.randomUUID)();
|
|
608
|
+
const got = await exchange([{ type: "get_session_queue", session_id: id, request_id: requestId }], { keep: (frame) => frame.request_id === requestId || frame.type === "socket_error", done: (frame) => frame.request_id === requestId || frame.type === "socket_error", waitMs: options.sendWaitMs ?? exports.SEND_WAIT_MS }, options);
|
|
609
|
+
const data = isRecord(got.at(-1)?.data) ? got.at(-1).data : {};
|
|
610
|
+
const items = Array.isArray(data.items) ? data.items : [];
|
|
611
|
+
return items.filter(isRecord).flatMap(item => (str(item.id) && item.kind === "message" ? [{ id: str(item.id), source: str(item.source) ?? "", text: str(item.display_text) ?? "" }] : []));
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Take back the messages of `source: "user"` (what the app's own box and Ouroboros send) that a session still holds in its
|
|
615
|
+
* queue and that start with `prefix`. Only those: another session's or an agent's messages stay. Returns how many it removed.
|
|
616
|
+
*/
|
|
617
|
+
async function withdrawQueuedMessages(id, prefix, options = {}) {
|
|
618
|
+
const mine = (await listSessionQueue(id, options)).filter(item => item.source === "user" && item.text.startsWith(prefix));
|
|
619
|
+
let removed = 0;
|
|
620
|
+
for (const item of mine) {
|
|
621
|
+
const requestId = (0, node_crypto_1.randomUUID)();
|
|
622
|
+
const got = await exchange([{ type: "remove_session_queue_item", session_id: id, id: item.id, request_id: requestId }], { keep: (frame) => frame.request_id === requestId || frame.type === "socket_error", done: (frame) => frame.request_id === requestId || frame.type === "socket_error", waitMs: options.sendWaitMs ?? exports.SEND_WAIT_MS }, options);
|
|
623
|
+
if (got.at(-1)?.request_id === requestId && !got.at(-1)?.error)
|
|
624
|
+
removed += 1;
|
|
625
|
+
}
|
|
626
|
+
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_queue_withdrawn", message: "took back queued messages a newer one replaces", meta: { session: id, found: mine.length, removed } });
|
|
627
|
+
return removed;
|
|
628
|
+
}
|
|
602
629
|
/** The nudge the desk's keeper sends a session that stopped mid-work. */
|
|
603
630
|
function resumePrompt(state, note) {
|
|
604
631
|
return [
|
|
@@ -61,6 +61,10 @@ const wake_runner_state_1 = require("./wake-runner-state");
|
|
|
61
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
62
|
* and reported undelivered, and the command, which re-derives its state every run, offers it again. A wake still missing
|
|
63
63
|
* after `WAKE_HOLD_MS` is taken as lost. Held wakes never pile up in the app as hours-old news.
|
|
64
|
+
*
|
|
65
|
+
* A wake may name `replaces`, a message prefix. Before it is sent, the messages the session still holds in the app's queue
|
|
66
|
+
* that start with it (and come from the user side, never another session's or an agent's) are taken back, so a newer wake
|
|
67
|
+
* replaces older undelivered ones instead of queueing behind them.
|
|
64
68
|
*/
|
|
65
69
|
exports.WAKE_RUNNER_DEFAULT_SECONDS = 300;
|
|
66
70
|
exports.WAKE_RUNNER_TIMEOUT_MS = 2 * 60_000;
|
|
@@ -88,7 +92,9 @@ function parseWakeOutput(stdout) {
|
|
|
88
92
|
throw new Error(`wakes[${index}].session is not a session id`);
|
|
89
93
|
if (wake.done !== undefined && (!Array.isArray(wake.done) || wake.done.length === 0 || wake.done.some(part => typeof part !== "string")))
|
|
90
94
|
throw new Error(`wakes[${index}].done is not an argv`);
|
|
91
|
-
|
|
95
|
+
if (wake.replaces !== undefined && (typeof wake.replaces !== "string" || !wake.replaces.trim()))
|
|
96
|
+
throw new Error(`wakes[${index}].replaces is not a message prefix`);
|
|
97
|
+
return { message: wake.message, ...(wake.session !== undefined ? { session: wake.session } : {}), ...(wake.done !== undefined ? { done: wake.done } : {}), ...(wake.replaces !== undefined ? { replaces: wake.replaces } : {}) };
|
|
92
98
|
});
|
|
93
99
|
// eslint-disable-next-line no-control-regex
|
|
94
100
|
const clean = (line) => line.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").trim().slice(0, MAX_LINE);
|
|
@@ -108,7 +114,10 @@ const runCommand = (argv, timeoutMs) => new Promise(resolve => {
|
|
|
108
114
|
exports.runCommand = runCommand;
|
|
109
115
|
const wasDelivered = (client) => (session, message, sinceMs) => (0, client_1.messageDelivered)(session, message, sinceMs, client);
|
|
110
116
|
exports.wasDelivered = wasDelivered;
|
|
111
|
-
const sendWake = (client) => async (session, message, delivery) => {
|
|
117
|
+
const sendWake = (client) => async (session, message, delivery, replaces) => {
|
|
118
|
+
// The command re-derives its whole state each run, so a wake still queued in the session is stale news: take it back first.
|
|
119
|
+
if (replaces)
|
|
120
|
+
await (0, client_1.withdrawQueuedMessages)(session, replaces, client).catch(() => 0);
|
|
112
121
|
const result = await (0, client_1.sendToAppSession)(session, message, { ...client, delivery });
|
|
113
122
|
return { ok: result.ok, error: result.error };
|
|
114
123
|
};
|
|
@@ -135,12 +144,13 @@ async function runWakeRunner(runner, deps, previous = {}) {
|
|
|
135
144
|
const problems = [];
|
|
136
145
|
for (const wake of output.wakes) {
|
|
137
146
|
const session = wake.session ?? runner.session;
|
|
138
|
-
|
|
147
|
+
// A wake that replaces older ones takes them back from the app's queue and goes out; only a wake that cannot is held behind the last one.
|
|
148
|
+
const holding = session && !wake.replaces ? state.open?.[session] : undefined;
|
|
139
149
|
const sent = !session
|
|
140
150
|
? { ok: false, error: "the wake names no session and the runner has none" }
|
|
141
151
|
: holding
|
|
142
152
|
? { 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 }));
|
|
153
|
+
: await deps.send(session, wake.message, runner.delivery ?? "immediate", wake.replaces).catch((error) => ({ ok: false, error: error.message }));
|
|
144
154
|
if (session && sent.ok)
|
|
145
155
|
(state.open ??= {})[session] = { at: new Date(deps.now).toISOString(), message: wake.message };
|
|
146
156
|
const reason = sent.ok ? null : sent.error ?? "the app refused the message";
|
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.1130",
|
|
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.1130",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|