@ouro.bot/cli 0.1.0-alpha.1173 → 0.1.0-alpha.1175
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/agent-config-check.js +6 -0
- package/dist/heart/daemon/daemon-entry.js +42 -35
- package/dist/heart/daemon/vault-outage.js +74 -0
- package/dist/repertoire/tools-app-sessions.js +63 -27
- package/dist/senses/app-sessions/client.js +4 -68
- package/dist/senses/app-sessions/digest-push.js +2 -2
- package/dist/senses/app-sessions/shepherd-cli.js +165 -0
- package/dist/senses/app-sessions/store.js +0 -17
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/senses/app-sessions/app-interface.js +0 -364
- package/dist/senses/app-sessions/coordinator.js +0 -78
- package/dist/senses/app-sessions/handoff.js +0 -177
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REPORT_SCAN_BYTES = void 0;
|
|
4
|
-
exports.handoffSuccessors = handoffSuccessors;
|
|
5
|
-
exports.reportTargets = reportTargets;
|
|
6
|
-
exports.coordinatorOf = coordinatorOf;
|
|
7
|
-
const runtime_1 = require("../../nerves/runtime");
|
|
8
|
-
const client_1 = require("./client");
|
|
9
|
-
const handoff_1 = require("./handoff");
|
|
10
|
-
/**
|
|
11
|
-
* Who coordinates a session now. The app records a coordinator once, when the session is made, and never lets another
|
|
12
|
-
* session take that field over: when the coordinator hands off to a fresh successor and is archived, the field still
|
|
13
|
-
* names the archived one, while the lanes have long been reporting to the successor. So the field alone is not the truth.
|
|
14
|
-
* In order:
|
|
15
|
-
*
|
|
16
|
-
* - `app`: the session the app names, when it is still in the sidebar (by session id or project-session id);
|
|
17
|
-
* - `hand-off`: that session's successor, when a hand-off names one that is listed (`successorOf`, owned by `handoff.ts`);
|
|
18
|
-
* - `reports`: the listed session this lane last sent a message to with `send_session_message`, in the end of its history.
|
|
19
|
-
*
|
|
20
|
-
* `gone` means none of these finds one: only then may anyone say the lane has no coordinator.
|
|
21
|
-
*/
|
|
22
|
-
exports.REPORT_SCAN_BYTES = 16 * 1024 * 1024;
|
|
23
|
-
const SEND_TOOL = /(?:^|-)send_session_message$/;
|
|
24
|
-
/** `successorOf` over the hand-offs the sense last recorded (`handoff.ts` refreshes them each minute), read once, when first needed. */
|
|
25
|
-
function handoffSuccessors(agentRoot) {
|
|
26
|
-
let successions = null;
|
|
27
|
-
return id => (0, handoff_1.successorOf)(id, (successions ??= (0, handoff_1.readSuccessions)(agentRoot)));
|
|
28
|
-
}
|
|
29
|
-
const listedAs = (rows, id) => id ? rows.find(row => row.id === id || row.workspaceId === id) : undefined;
|
|
30
|
-
/** The session ids this lane sent messages to, oldest first, from the end of its history. */
|
|
31
|
-
function reportTargets(id, client = {}, maxBytes = exports.REPORT_SCAN_BYTES) {
|
|
32
|
-
const targets = [];
|
|
33
|
-
for (const line of (0, client_1.readEventLog)(id, { ...client, maxBytes }).text.split("\n")) {
|
|
34
|
-
if (!line.includes("send_session_message"))
|
|
35
|
-
continue;
|
|
36
|
-
let event;
|
|
37
|
-
try {
|
|
38
|
-
event = JSON.parse(line);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
for (const request of event.data?.toolRequests ?? []) {
|
|
44
|
-
if (typeof request?.name !== "string" || !SEND_TOOL.test(request.name))
|
|
45
|
-
continue;
|
|
46
|
-
let args = request.arguments;
|
|
47
|
-
if (typeof args === "string") {
|
|
48
|
-
try {
|
|
49
|
-
args = JSON.parse(args);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const target = args?.session_id;
|
|
56
|
-
if (typeof target === "string" && target)
|
|
57
|
-
targets.push(target);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return targets;
|
|
61
|
-
}
|
|
62
|
-
function coordinatorOf(row, rows, deps = {}) {
|
|
63
|
-
const recorded = row.coordinatingCreatorSessionId;
|
|
64
|
-
if (!recorded)
|
|
65
|
-
return null;
|
|
66
|
-
const named = listedAs(rows, recorded);
|
|
67
|
-
if (named && named.id !== row.id)
|
|
68
|
-
return { id: named.id, name: named.name, via: "app" };
|
|
69
|
-
const successor = listedAs(rows, deps.successorOf?.(recorded));
|
|
70
|
-
let found = successor && successor.id !== row.id ? { id: successor.id, name: successor.name, via: "hand-off" } : null;
|
|
71
|
-
if (!found) {
|
|
72
|
-
const latest = reportTargets(row.id, deps.client).reverse().map(id => listedAs(rows, id)).find(target => target && target.id !== row.id);
|
|
73
|
-
if (latest)
|
|
74
|
-
found = { id: latest.id, name: latest.name, via: "reports" };
|
|
75
|
-
}
|
|
76
|
-
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_coordinator_resolved", message: "worked out who coordinates a lane whose recorded coordinator is not listed", meta: { session: row.id, recorded, found: found && "id" in found ? found.id : null, via: found && "via" in found ? found.via : null } });
|
|
77
|
-
return found ?? { gone: true, recorded };
|
|
78
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
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.readSuccessions = exports.FIRST_MESSAGE_SCAN_BYTES = exports.MESSAGE_HEAD_CHARS = exports.SUCCEEDS_LINE = void 0;
|
|
37
|
-
exports.namedPredecessor = namedPredecessor;
|
|
38
|
-
exports.refreshSuccessions = refreshSuccessions;
|
|
39
|
-
exports.successorOf = successorOf;
|
|
40
|
-
exports.isHandedOff = isHandedOff;
|
|
41
|
-
const fs = __importStar(require("node:fs"));
|
|
42
|
-
const path = __importStar(require("node:path"));
|
|
43
|
-
const runtime_1 = require("../../nerves/runtime");
|
|
44
|
-
const client_1 = require("./client");
|
|
45
|
-
const store_1 = require("./store");
|
|
46
|
-
/**
|
|
47
|
-
* Who succeeds whom. A session that takes over another's job says so in its first message: the contract is a line of its
|
|
48
|
-
* own, `Succeeds: <predecessor session id>`, within the message's first 16 KB. Kickoffs written before that line existed
|
|
49
|
-
* are read too, when "successor to" or "successor of" opens the message and is followed closely by a session id, for
|
|
50
|
-
* example `the successor to "desk epoch 3" (cfb84353-…)` or `the fresh successor to session 2fa5297c`.
|
|
51
|
-
*
|
|
52
|
-
* The first message sits after the start-up hooks' events, tens of KB into the history, so each history is read forward
|
|
53
|
-
* at most 1 MB until its first message, once; after that only for the successor's first finished turn.
|
|
54
|
-
*/
|
|
55
|
-
exports.SUCCEEDS_LINE = "Succeeds:";
|
|
56
|
-
const STRUCTURED = /^[ \t>*_`]*Succeeds:[ \t*_`]*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b/im;
|
|
57
|
-
const FREE_TEXT = /\bsuccessor (?:to|of)\b/gi;
|
|
58
|
-
const SESSION_ID = /\b[0-9a-f]{8}(?:-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})?\b/i;
|
|
59
|
-
/** How much of the first message is read for the line. */
|
|
60
|
-
exports.MESSAGE_HEAD_CHARS = 16_384;
|
|
61
|
-
/** The free-text wording counts only where the message opens, and the id only close after it. */
|
|
62
|
-
const FREE_TEXT_OPENING_CHARS = 2_000;
|
|
63
|
-
const FREE_TEXT_ID_WINDOW = 240;
|
|
64
|
-
/** How far into a history the first message is looked for, and the most read per pass while waiting for the first turn. */
|
|
65
|
-
exports.FIRST_MESSAGE_SCAN_BYTES = 1024 * 1024;
|
|
66
|
-
const stateFile = (agentRoot) => path.join((0, store_1.appSessionsStateDir)(agentRoot), "successions.json");
|
|
67
|
-
const readSuccessions = (agentRoot) => (0, store_1.readJson)(stateFile(agentRoot), { sessions: {} }).sessions;
|
|
68
|
-
exports.readSuccessions = readSuccessions;
|
|
69
|
-
/** The session a first message says it succeeds: the `Succeeds:` line, else the older wording. `known` resolves a short id. */
|
|
70
|
-
function namedPredecessor(message, self, known) {
|
|
71
|
-
const head = message.slice(0, exports.MESSAGE_HEAD_CHARS);
|
|
72
|
-
const line = STRUCTURED.exec(head)?.[1]?.toLowerCase();
|
|
73
|
-
if (line && line !== self)
|
|
74
|
-
return { predecessor: line, marker: "structured" };
|
|
75
|
-
const opening = head.slice(0, FREE_TEXT_OPENING_CHARS);
|
|
76
|
-
for (const phrase of opening.matchAll(FREE_TEXT)) {
|
|
77
|
-
const after = head.slice(phrase.index + phrase[0].length, phrase.index + phrase[0].length + FREE_TEXT_ID_WINDOW);
|
|
78
|
-
const id = SESSION_ID.exec(after)?.[0]?.toLowerCase();
|
|
79
|
-
const resolved = id ? known(id) : null;
|
|
80
|
-
if (resolved && resolved !== self)
|
|
81
|
-
return { predecessor: resolved, marker: "free-text" };
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
const sessionsRoot = (client) => path.dirname(path.dirname((0, client_1.eventLogPath)("x", client)));
|
|
86
|
-
function historyIds(client) {
|
|
87
|
-
try {
|
|
88
|
-
return fs.readdirSync(sessionsRoot(client)).filter(name => /^[0-9a-f-]{36}$/i.test(name));
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Read what is new in the history of each session the app lists, as far as succession needs, and remember only those,
|
|
96
|
-
* plus each pending succession: one whose successor has left the sidebar while the session it succeeds is still listed,
|
|
97
|
-
* so that session can still be retired. Anything else the app no longer lists drops out, and the record stays the size
|
|
98
|
-
* of the sidebar.
|
|
99
|
-
*/
|
|
100
|
-
function refreshSuccessions(agentRoot, client, listed) {
|
|
101
|
-
const before = (0, exports.readSuccessions)(agentRoot);
|
|
102
|
-
const live = new Set(listed);
|
|
103
|
-
const ids = historyIds(client);
|
|
104
|
-
const known = (value) => {
|
|
105
|
-
const matches = ids.filter(id => id.toLowerCase().startsWith(value));
|
|
106
|
-
return matches.length === 1 ? matches[0] : null;
|
|
107
|
-
};
|
|
108
|
-
const next = {};
|
|
109
|
-
for (const [id, entry] of Object.entries(before))
|
|
110
|
-
if (!live.has(id) && entry.predecessor && live.has(entry.predecessor))
|
|
111
|
-
next[id] = entry;
|
|
112
|
-
for (const id of live) {
|
|
113
|
-
const was = before[id];
|
|
114
|
-
if (was && !was.pending && (!was.predecessor || was.turned)) {
|
|
115
|
-
next[id] = was;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const entry = was ? { ...was } : { predecessor: null, offset: 0, pending: true };
|
|
119
|
-
let message = null;
|
|
120
|
-
let turned = false;
|
|
121
|
-
const read = (0, client_1.readNewAppEvents)(id, entry.offset, exports.FIRST_MESSAGE_SCAN_BYTES, event => {
|
|
122
|
-
if (event.agentId !== undefined)
|
|
123
|
-
return;
|
|
124
|
-
const data = event.data && typeof event.data === "object" ? event.data : {};
|
|
125
|
-
if (entry.pending && !message && event.type === "user.message" && typeof data.content === "string")
|
|
126
|
-
message = { text: data.content, ...(typeof event.timestamp === "string" ? { at: event.timestamp } : {}) };
|
|
127
|
-
else if ((message || !entry.pending) && event.type === "assistant.turn_end")
|
|
128
|
-
turned = true;
|
|
129
|
-
}, client);
|
|
130
|
-
entry.offset = read.offset;
|
|
131
|
-
if (entry.pending) {
|
|
132
|
-
const first = message;
|
|
133
|
-
if (first) {
|
|
134
|
-
delete entry.pending;
|
|
135
|
-
const named = namedPredecessor(first.text, id, known);
|
|
136
|
-
Object.assign(entry, named ?? {}, first.at ? { at: first.at } : {});
|
|
137
|
-
}
|
|
138
|
-
else if (entry.offset >= exports.FIRST_MESSAGE_SCAN_BYTES)
|
|
139
|
-
delete entry.pending;
|
|
140
|
-
}
|
|
141
|
-
if (entry.predecessor && turned)
|
|
142
|
-
entry.turned = true;
|
|
143
|
-
next[id] = entry;
|
|
144
|
-
}
|
|
145
|
-
(0, store_1.writeJson)(stateFile(agentRoot), { sessions: next });
|
|
146
|
-
return next;
|
|
147
|
-
}
|
|
148
|
-
/** The newest session that took over `id`'s job, following the chain of hand-offs to the live end; null when none did. */
|
|
149
|
-
function successorOf(id, successions) {
|
|
150
|
-
// The newest claim wins when two sessions name the same predecessor.
|
|
151
|
-
const direct = (of) => {
|
|
152
|
-
let newest = null;
|
|
153
|
-
for (const [claimant, entry] of Object.entries(successions)) {
|
|
154
|
-
const at = Date.parse(String(entry.at)) || 0;
|
|
155
|
-
if (entry.predecessor === of && (!newest || at > newest.at))
|
|
156
|
-
newest = { id: claimant, at };
|
|
157
|
-
}
|
|
158
|
-
return newest?.id ?? null;
|
|
159
|
-
};
|
|
160
|
-
let current = id;
|
|
161
|
-
const seen = new Set([id]);
|
|
162
|
-
for (let later = direct(current); later; later = direct(current)) {
|
|
163
|
-
// Sessions that claim to succeed each other own nothing for certain, so none of them is retired.
|
|
164
|
-
if (seen.has(later))
|
|
165
|
-
return null;
|
|
166
|
-
seen.add(later);
|
|
167
|
-
current = later;
|
|
168
|
-
}
|
|
169
|
-
return current === id ? null : current;
|
|
170
|
-
}
|
|
171
|
-
/** Whether a newer session's first message names this one as the session it succeeds (the chain's live end, via `successorOf`). */
|
|
172
|
-
function isHandedOff(agentRoot, row) {
|
|
173
|
-
const successor = successorOf(row.id, (0, exports.readSuccessions)(agentRoot));
|
|
174
|
-
if (successor)
|
|
175
|
-
(0, runtime_1.emitNervesEvent)({ component: "senses", event: "senses.app_sessions_handoff_found", message: "found the successor that a session was handed off to", meta: { session: row.id, successor } });
|
|
176
|
-
return successor !== null;
|
|
177
|
-
}
|