@ouro.bot/cli 0.1.0-alpha.1373 → 0.1.0-alpha.1375
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/core.js +51 -19
- package/dist/heart/providers/anthropic.js +19 -2
- package/dist/heart/turn-execution-lease.js +52 -4
- package/dist/repertoire/tool-catalog.js +97 -3
- package/dist/senses/bluebubbles/active-turns.js +27 -2
- package/dist/senses/bluebubbles/entry.js +4 -15
- package/dist/senses/bluebubbles/index.js +297 -52
- package/dist/senses/bluebubbles/latest-turn.js +33 -2
- package/dist/senses/pipeline.js +1 -1
- package/dist/senses/sense-shutdown.js +72 -0
- package/dist/senses/shepherd-entry.js +8 -9
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/repertoire/deferred-tools.js +0 -129
|
@@ -10,6 +10,7 @@ exports.promote = promote;
|
|
|
10
10
|
exports.isCurrent = isCurrent;
|
|
11
11
|
exports.observationSchedulingKeys = observationSchedulingKeys;
|
|
12
12
|
exports.awaitDeliveryAdmission = awaitDeliveryAdmission;
|
|
13
|
+
exports.listPendingObservationsForAudit = listPendingObservationsForAudit;
|
|
13
14
|
exports.isDeliveryAdmittedNow = isDeliveryAdmittedNow;
|
|
14
15
|
exports.cancel = cancel;
|
|
15
16
|
exports.finish = finish;
|
|
@@ -274,16 +275,46 @@ function observationSchedulingKeys(reservation) {
|
|
|
274
275
|
}
|
|
275
276
|
return Object.freeze([...keys]);
|
|
276
277
|
}
|
|
277
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Resolves when every blocker settles or any signal aborts, whichever comes first.
|
|
280
|
+
* Listeners are removed either way, so a long-lived fence holds no references.
|
|
281
|
+
*/
|
|
282
|
+
function untilSettledOrAborted(blockers, signals) {
|
|
283
|
+
return new Promise((resolve) => {
|
|
284
|
+
const done = () => {
|
|
285
|
+
for (const signal of signals)
|
|
286
|
+
signal.removeEventListener("abort", done);
|
|
287
|
+
resolve();
|
|
288
|
+
};
|
|
289
|
+
for (const signal of signals)
|
|
290
|
+
signal.addEventListener("abort", done, { once: true });
|
|
291
|
+
void Promise.all(blockers.map((entry) => entry.settled)).then(done);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Waits until no newer observation in this chat could still supersede the turn.
|
|
296
|
+
* Resolves false once the turn is no longer current (superseded, cancelled or
|
|
297
|
+
* timed out). Rejects with the reason when `signal` aborts, so a fence that is
|
|
298
|
+
* never settled can never hold a turn past its deadline or shutdown.
|
|
299
|
+
*/
|
|
300
|
+
async function awaitDeliveryAdmission(capability, signal) {
|
|
278
301
|
const value = internal(capability);
|
|
302
|
+
const signals = signal ? [value.signal, signal] : [value.signal];
|
|
279
303
|
while (isCurrent(value)) {
|
|
304
|
+
signal?.throwIfAborted();
|
|
280
305
|
const blockers = [...pending.values()].filter((entry) => pendingIntersects(value, entry));
|
|
281
306
|
if (blockers.length === 0)
|
|
282
307
|
return true;
|
|
283
|
-
await
|
|
308
|
+
await untilSettledOrAborted(blockers, signals);
|
|
284
309
|
}
|
|
285
310
|
return false;
|
|
286
311
|
}
|
|
312
|
+
/** Every observation still pending, oldest first. The sense's ownership audit checks each has an owner. */
|
|
313
|
+
function listPendingObservationsForAudit() {
|
|
314
|
+
return [...pending.values()]
|
|
315
|
+
.sort((left, right) => left.reservation.ordinal - right.reservation.ordinal)
|
|
316
|
+
.map((entry) => entry.reservation);
|
|
317
|
+
}
|
|
287
318
|
function isDeliveryAdmittedNow(capability) {
|
|
288
319
|
const value = internal(capability);
|
|
289
320
|
return isCurrent(value)
|
package/dist/senses/pipeline.js
CHANGED
|
@@ -545,7 +545,7 @@ function erroredTurnReply(errorMessage) {
|
|
|
545
545
|
: "I couldn't finish that one: something went wrong before I had an answer. Ask me again and I'll retry.";
|
|
546
546
|
}
|
|
547
547
|
async function handleInboundTurn(input) {
|
|
548
|
-
return (0, turn_execution_lease_1.withTurnExecutionLease)(() => handleInboundTurnExclusive(input));
|
|
548
|
+
return (0, turn_execution_lease_1.withTurnExecutionLease)(() => handleInboundTurnExclusive(input), input.stopQueueWaitOnAbort ? input.signal : undefined);
|
|
549
549
|
}
|
|
550
550
|
async function handleInboundTurnExclusive(input) {
|
|
551
551
|
// Continuity resumption is structured caller intent. Never infer it from the
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SENSE_SHUTDOWN_GRACE_MS = void 0;
|
|
4
|
+
exports.installSenseShutdown = installSenseShutdown;
|
|
5
|
+
const runtime_1 = require("../nerves/runtime");
|
|
6
|
+
/**
|
|
7
|
+
* How long a sense may spend ending its in-flight turns after SIGTERM before it exits anyway.
|
|
8
|
+
* Kept under the daemon's 4 s stop timeout so the daemon sees the exit and starts the replacement.
|
|
9
|
+
*/
|
|
10
|
+
exports.SENSE_SHUTDOWN_GRACE_MS = 3_000;
|
|
11
|
+
/**
|
|
12
|
+
* Exit within a bounded time on SIGTERM or SIGINT. The sense's `stop` gets
|
|
13
|
+
* `graceMs` to finish; if it hangs, the process exits anyway so the daemon can
|
|
14
|
+
* start a replacement that replays whatever was left pending.
|
|
15
|
+
*/
|
|
16
|
+
function installSenseShutdown(options) {
|
|
17
|
+
const target = options.process ?? process;
|
|
18
|
+
const graceMs = options.graceMs ?? exports.SENSE_SHUTDOWN_GRACE_MS;
|
|
19
|
+
const onSignal = (signal) => {
|
|
20
|
+
uninstall();
|
|
21
|
+
(0, runtime_1.emitNervesEvent)({
|
|
22
|
+
component: "senses",
|
|
23
|
+
event: "senses.shutdown_started",
|
|
24
|
+
message: "sense shutting down",
|
|
25
|
+
meta: { sense: options.sense, signal, graceMs },
|
|
26
|
+
});
|
|
27
|
+
let graceTimer;
|
|
28
|
+
const graceExpired = new Promise((resolve) => {
|
|
29
|
+
graceTimer = setTimeout(() => resolve("grace_expired"), graceMs);
|
|
30
|
+
});
|
|
31
|
+
const stopped = Promise.resolve()
|
|
32
|
+
.then(options.stop)
|
|
33
|
+
.then(() => "stopped", (error) => {
|
|
34
|
+
(0, runtime_1.emitNervesEvent)({
|
|
35
|
+
level: "error",
|
|
36
|
+
component: "senses",
|
|
37
|
+
event: "senses.shutdown_error",
|
|
38
|
+
message: "sense stop failed during shutdown",
|
|
39
|
+
meta: { sense: options.sense, error: error instanceof Error ? error.message : String(error) },
|
|
40
|
+
});
|
|
41
|
+
return "stop_failed";
|
|
42
|
+
});
|
|
43
|
+
void Promise.race([stopped, graceExpired]).then((result) => {
|
|
44
|
+
clearTimeout(graceTimer);
|
|
45
|
+
if (result === "grace_expired") {
|
|
46
|
+
(0, runtime_1.emitNervesEvent)({
|
|
47
|
+
level: "warn",
|
|
48
|
+
component: "senses",
|
|
49
|
+
event: "senses.shutdown_grace_expired",
|
|
50
|
+
message: "sense did not stop within its shutdown grace period; exiting anyway",
|
|
51
|
+
meta: { sense: options.sense, graceMs },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, runtime_1.emitNervesEvent)({
|
|
56
|
+
component: "senses",
|
|
57
|
+
event: "senses.shutdown_complete",
|
|
58
|
+
message: "sense stopped",
|
|
59
|
+
meta: { sense: options.sense, result },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
target.exit(result === "stopped" ? 0 : 1);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
function uninstall() {
|
|
66
|
+
target.removeListener("SIGTERM", onSignal);
|
|
67
|
+
target.removeListener("SIGINT", onSignal);
|
|
68
|
+
}
|
|
69
|
+
target.once("SIGTERM", onSignal);
|
|
70
|
+
target.once("SIGINT", onSignal);
|
|
71
|
+
return uninstall;
|
|
72
|
+
}
|
|
@@ -75,15 +75,14 @@ Promise.resolve().then(() => __importStar(require("../heart/runtime-credentials"
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
process.once("SIGINT", shutdown);
|
|
78
|
+
const { installSenseShutdown } = await Promise.resolve().then(() => __importStar(require("./sense-shutdown")));
|
|
79
|
+
installSenseShutdown({
|
|
80
|
+
sense: "shepherd",
|
|
81
|
+
stop: async () => {
|
|
82
|
+
app.stop();
|
|
83
|
+
await attention?.close();
|
|
84
|
+
},
|
|
85
|
+
});
|
|
87
86
|
})
|
|
88
87
|
.catch((error) => {
|
|
89
88
|
(0, runtime_1.emitNervesEvent)({
|
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.1375",
|
|
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.1375",
|
|
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.1375",
|
|
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": {
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findToolsDefinition = exports.CORE_TOOL_NAMES = exports.FIND_TOOLS_NAME = exports.DEFERRED_TOOLS_FLAG = void 0;
|
|
4
|
-
exports.deferredToolLoadingEnabled = deferredToolLoadingEnabled;
|
|
5
|
-
exports.partitionTools = partitionTools;
|
|
6
|
-
exports.buildFindToolsSchema = buildFindToolsSchema;
|
|
7
|
-
exports.searchDeferredTools = searchDeferredTools;
|
|
8
|
-
exports.formatFindToolsResult = formatFindToolsResult;
|
|
9
|
-
exports.deferredNamesCalledInHistory = deferredNamesCalledInHistory;
|
|
10
|
-
exports.recordDeferredToolsLoaded = recordDeferredToolsLoaded;
|
|
11
|
-
const runtime_1 = require("../nerves/runtime");
|
|
12
|
-
const tool_error_code_1 = require("./tool-error-code");
|
|
13
|
-
/**
|
|
14
|
-
* Deferred tool loading (trial, off by default). When OURO_DEFERRED_TOOLS is set, each request carries the core
|
|
15
|
-
* tools plus `find_tools`; the rest are advertised only after the model asks for them. Selection, relationship
|
|
16
|
-
* filtering, guards and approvals are untouched: this only narrows which already-selected schemas are sent.
|
|
17
|
-
*/
|
|
18
|
-
exports.DEFERRED_TOOLS_FLAG = "OURO_DEFERRED_TOOLS";
|
|
19
|
-
exports.FIND_TOOLS_NAME = "find_tools";
|
|
20
|
-
const MAX_RESULTS = 8;
|
|
21
|
-
function deferredToolLoadingEnabled(env = process.env) {
|
|
22
|
-
return ["1", "true", "on"].includes((env[exports.DEFERRED_TOOLS_FLAG] ?? "").trim().toLowerCase());
|
|
23
|
-
}
|
|
24
|
-
/** Always sent. Engine tools are listed so the offline measurement keeps them; the engine adds them separately. */
|
|
25
|
-
exports.CORE_TOOL_NAMES = new Set([
|
|
26
|
-
"settle", "ponder", "observe", "rest", "speak", "surface", "send_message",
|
|
27
|
-
"load_skill", "list_skills",
|
|
28
|
-
"read_file", "write_file", "edit_file", "glob", "grep", "ls",
|
|
29
|
-
"shell", "shell_status", "shell_tail",
|
|
30
|
-
"web_search", "fetch_url",
|
|
31
|
-
"note", "diary_write", "consult_diary", "consult_notes", "search_facts", "get_friend_note", "save_friend_note",
|
|
32
|
-
]);
|
|
33
|
-
/**
|
|
34
|
-
* Core tools keep their canonical order; loaded tools follow in the order they were loaded, so the cached prefix
|
|
35
|
-
* only grows at the end. `find_tools` is added only when something is deferred.
|
|
36
|
-
*/
|
|
37
|
-
function partitionTools(tools, loaded = [], alwaysKeep = new Set()) {
|
|
38
|
-
const keep = (name) => exports.CORE_TOOL_NAMES.has(name) || alwaysKeep.has(name);
|
|
39
|
-
const core = tools.filter((tool) => keep(tool.function.name));
|
|
40
|
-
const deferred = tools.filter((tool) => !keep(tool.function.name));
|
|
41
|
-
if (deferred.length === 0)
|
|
42
|
-
return { active: [...core], deferred };
|
|
43
|
-
const loadedTools = loaded.flatMap((name) => deferred.filter((tool) => tool.function.name === name));
|
|
44
|
-
return { active: [...core, buildFindToolsSchema(deferred), ...loadedTools], deferred };
|
|
45
|
-
}
|
|
46
|
-
function groupCatalogue(deferred) {
|
|
47
|
-
const groups = new Map();
|
|
48
|
-
for (const tool of deferred) {
|
|
49
|
-
const name = tool.function.name;
|
|
50
|
-
const prefix = name.includes("_") ? name.slice(0, name.indexOf("_")) : name;
|
|
51
|
-
groups.set(prefix, [...(groups.get(prefix) ?? []), name]);
|
|
52
|
-
}
|
|
53
|
-
return [...groups.entries()].map(([prefix, names]) => (names.length === 1 ? names[0] : `${prefix}_*(${names.map((n) => n.slice(prefix.length + 1)).join(",")})`)).join(" ");
|
|
54
|
-
}
|
|
55
|
-
function buildFindToolsSchema(deferred) {
|
|
56
|
-
return {
|
|
57
|
-
type: "function",
|
|
58
|
-
function: {
|
|
59
|
-
name: exports.FIND_TOOLS_NAME,
|
|
60
|
-
description: `more tools exist than are listed. call find_tools with a short query (what you need to do) or select:name1,name2 to load them; they become callable on your next step this turn. not loaded now: ${groupCatalogue(deferred)}`,
|
|
61
|
-
parameters: {
|
|
62
|
-
type: "object",
|
|
63
|
-
properties: { query: { type: "string", description: "what you need, or select:name1,name2" } },
|
|
64
|
-
required: ["query"],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
const STOPWORDS = new Set(["the", "and", "for", "with", "that", "this", "from", "into", "again", "please", "need", "use", "can", "you", "tool", "tools"]);
|
|
70
|
-
const words = (text) => text.toLowerCase().split(/[^a-z0-9]+/).filter((word) => word.length > 2 && !STOPWORDS.has(word)).map((word) => (word.length > 3 && word.endsWith("s") ? word.slice(0, -1) : word));
|
|
71
|
-
function searchDeferredTools(deferred, query) {
|
|
72
|
-
const trimmed = query.trim();
|
|
73
|
-
if (trimmed.toLowerCase().startsWith("select:")) {
|
|
74
|
-
const names = new Set(trimmed.slice(7).split(",").map((name) => name.trim()).filter(Boolean));
|
|
75
|
-
return deferred.filter((tool) => names.has(tool.function.name));
|
|
76
|
-
}
|
|
77
|
-
const terms = words(trimmed);
|
|
78
|
-
const scored = deferred
|
|
79
|
-
.map((tool, index) => {
|
|
80
|
-
const name = tool.function.name.toLowerCase();
|
|
81
|
-
const nameWords = words(name);
|
|
82
|
-
const description = new Set(words(tool.function.description ?? ""));
|
|
83
|
-
const score = terms.reduce((sum, term) => sum + (name === term ? 6 : nameWords.includes(term) ? 4 : name.includes(term) ? 2 : 0) + (description.has(term) ? 1 : 0), 0);
|
|
84
|
-
return { tool, score, index };
|
|
85
|
-
})
|
|
86
|
-
.filter((entry) => entry.score > 0)
|
|
87
|
-
.sort((a, b) => b.score - a.score || a.index - b.index);
|
|
88
|
-
// Drop weak description-only hits when something matches strongly, so the result stays short.
|
|
89
|
-
const floor = scored.length > 0 ? Math.ceil(scored[0].score / 3) : 0;
|
|
90
|
-
return scored.filter((entry) => entry.score >= floor).slice(0, MAX_RESULTS).map((entry) => entry.tool);
|
|
91
|
-
}
|
|
92
|
-
function signature(tool) {
|
|
93
|
-
const parameters = tool.function.parameters;
|
|
94
|
-
const required = new Set(parameters?.required ?? []);
|
|
95
|
-
return Object.keys(parameters?.properties ?? {}).map((key) => (required.has(key) ? key : `${key}?`)).join(", ");
|
|
96
|
-
}
|
|
97
|
-
function formatFindToolsResult(matched) {
|
|
98
|
-
if (matched.length === 0)
|
|
99
|
-
return (0, tool_error_code_1.withCode)("no matching tools. try different words, or select:name1,name2 using a name from the list in find_tools.", "no-matching-tools");
|
|
100
|
-
return `loaded; callable on your next step:\n${matched.map((tool) => `- ${tool.function.name}(${signature(tool)}): ${tool.function.description ?? ""}`).join("\n")}`;
|
|
101
|
-
}
|
|
102
|
-
/** Deferred tools the conversation already called, so a follow-up turn does not have to find them again. */
|
|
103
|
-
function deferredNamesCalledInHistory(messages, deferred) {
|
|
104
|
-
const deferredNames = new Set(deferred.map((tool) => tool.function.name));
|
|
105
|
-
const called = [];
|
|
106
|
-
for (const message of messages) {
|
|
107
|
-
if (message.role !== "assistant")
|
|
108
|
-
continue;
|
|
109
|
-
for (const call of message.tool_calls ?? []) {
|
|
110
|
-
if (call.type === "function" && deferredNames.has(call.function.name) && !called.includes(call.function.name))
|
|
111
|
-
called.push(call.function.name);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return called;
|
|
115
|
-
}
|
|
116
|
-
function recordDeferredToolsLoaded(query, matched) {
|
|
117
|
-
(0, runtime_1.emitNervesEvent)({ component: "engine", event: "engine.deferred_tools_loaded", message: "deferred tools loaded for this turn", meta: { query, loaded: matched.map((tool) => tool.function.name).join(",") } });
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* find_tools's Ouro AX card and risk profile. The engine runs find_tools itself, so this is a declaration rather than
|
|
121
|
-
* a dispatched definition: loading a tool changes only which schemas this turn sends.
|
|
122
|
-
*/
|
|
123
|
-
exports.findToolsDefinition = {
|
|
124
|
-
tool: buildFindToolsSchema([]),
|
|
125
|
-
riskProfile: { mutates: "none", risk: "low" },
|
|
126
|
-
ax: { id: "tool:find_tools", group: "turn-skills", when: "Pick this when the tool you need isn't in your list; it searches the tools held back from this turn and makes the matches callable.", effect: "read", idempotent: true, errors: [
|
|
127
|
-
{ code: "no-matching-tools", means: "No held-back tool matched the query, so nothing was loaded.", fix: "Try other words for the job, or select:name1,name2 with names from the find_tools list." },
|
|
128
|
-
] },
|
|
129
|
-
};
|