@ouro.bot/cli 0.1.0-alpha.1461 → 0.1.0-alpha.1462
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,20 @@
|
|
|
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.1462",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Every turn now logs one counts-only event, `engine.turn_summary`, when it ends, including a turn that ends by throwing. The event records:",
|
|
8
|
+
"the channel, how the turn ended and, for a turn that failed, the class of error (such as `auth-failure` or `rate-limit`);",
|
|
9
|
+
"the provider and model the turn ended on, and how many times it fell back to another provider;",
|
|
10
|
+
"the provider calls the main loop made and any step-budget stop;",
|
|
11
|
+
"the tool calls by name, the tool errors and any calls to a name the turn never offered;",
|
|
12
|
+
"how `find_tools` did: calls, calls that loaded a tool, and loaded tools called afterwards;",
|
|
13
|
+
"the tools offered up front and those held back;",
|
|
14
|
+
"the input, output and reasoning tokens summed over the main loop's provider calls.",
|
|
15
|
+
"It holds only numbers and values from fixed lists, never message text, tool arguments or results. An MCP tool is named only by its server, and a made-up tool name is counted as `unknown`. A failure to log the event never affects the turn. Side calls such as the kept-notes judge, and attempts that failed and were retried, aren't in the step or token counts."
|
|
16
|
+
]
|
|
17
|
+
},
|
|
4
18
|
{
|
|
5
19
|
"version": "0.1.0-alpha.1461",
|
|
6
20
|
"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.1462</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
package/dist/heart/core.js
CHANGED
|
@@ -84,6 +84,7 @@ const provider_fallback_1 = require("./provider-fallback");
|
|
|
84
84
|
const habit_session_1 = require("./habits/habit-session");
|
|
85
85
|
const provider_attempt_1 = require("./provider-attempt");
|
|
86
86
|
const openai_codex_token_1 = require("./providers/openai-codex-token");
|
|
87
|
+
const turn_summary_1 = require("./turn-summary");
|
|
87
88
|
// Cache only immutable provider construction inputs. ProviderRuntime owns
|
|
88
89
|
// mutable per-turn state (for example Responses nativeInput), so every caller
|
|
89
90
|
// must receive a fresh instance even when its binding fingerprint is unchanged.
|
|
@@ -1147,6 +1148,23 @@ function buildAuthFailureGuidance(provider, model, agentName, detail) {
|
|
|
1147
1148
|
return lines.join("\n");
|
|
1148
1149
|
}
|
|
1149
1150
|
async function runAgent(messages, callbacks, channel, signal, options) {
|
|
1151
|
+
// engine.turn_summary (counts only; see turn-summary.ts) is emitted once however the turn ends, a throw included.
|
|
1152
|
+
const turnTally = new turn_summary_1.TurnTally();
|
|
1153
|
+
let result;
|
|
1154
|
+
try {
|
|
1155
|
+
result = await runCountedTurn(turnTally, messages, (0, turn_summary_1.tallyToolEnds)(callbacks, turnTally), channel, signal, options);
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1158
|
+
finally {
|
|
1159
|
+
(0, turn_summary_1.emitTurnSummary)(turnTally, {
|
|
1160
|
+
channel,
|
|
1161
|
+
outcome: result?.outcome ?? "errored",
|
|
1162
|
+
errorClass: result ? result.errorClassification ?? "none" : "unknown",
|
|
1163
|
+
traceId: options?.traceId,
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
async function runCountedTurn(turnTally, messages, callbacks, channel, signal, options) {
|
|
1150
1168
|
const generatedMessages = [];
|
|
1151
1169
|
let nextAttemptControls = [];
|
|
1152
1170
|
let rejectedAttempt = [];
|
|
@@ -1164,12 +1182,14 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1164
1182
|
: undefined;
|
|
1165
1183
|
// Automatic fallback (opt-in via agent.json providerFallback): start on the first chain entry not cooling down.
|
|
1166
1184
|
let providerRuntime = options?.providerRuntimeOverride ?? await getProviderRuntime(facing, owner);
|
|
1185
|
+
turnTally.route(providerRuntime.id, providerRuntime.model);
|
|
1167
1186
|
const fallbackChain = options?.providerRuntimeOverride ? [] : resolveTurnFallbackChain(facing, owner);
|
|
1168
1187
|
let chainIndex = 0;
|
|
1169
1188
|
const switchToChainEntry = async (from, firstCandidate, reason) => {
|
|
1170
1189
|
for (let candidate = firstCandidate; candidate !== null; candidate = (0, provider_fallback_1.nextReadyChainIndex)(fallbackChain, candidate)) {
|
|
1171
1190
|
try {
|
|
1172
1191
|
providerRuntime = await getChainEntryRuntime(fallbackChain[candidate], owner);
|
|
1192
|
+
turnTally.route(providerRuntime.id, providerRuntime.model);
|
|
1173
1193
|
chainIndex = candidate;
|
|
1174
1194
|
(0, runtime_1.emitNervesEvent)({
|
|
1175
1195
|
level: "warn",
|
|
@@ -1681,6 +1701,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1681
1701
|
})()
|
|
1682
1702
|
: ordinaryActiveTools;
|
|
1683
1703
|
const candidateToolNames = new Set(candidateActiveTools.map((tool) => tool.function.name));
|
|
1704
|
+
turnTally.offer(candidateActiveTools, deferralPool, ordinaryDefinitionsByName);
|
|
1684
1705
|
budgetNoteToolNames = candidateToolNames;
|
|
1685
1706
|
const unadvertisedRequiredTool = requiredToolCallNames.find((name) => !candidateToolNames.has(name));
|
|
1686
1707
|
if (unadvertisedRequiredTool) {
|
|
@@ -1882,6 +1903,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1882
1903
|
servedByProvider = true;
|
|
1883
1904
|
nextAttemptControls = [];
|
|
1884
1905
|
providerIterations += 1;
|
|
1906
|
+
turnTally.step(result.usage, providerRuntime.id, providerRuntime.model);
|
|
1885
1907
|
if (stepReportIteration !== null) {
|
|
1886
1908
|
// The progress-report call is the last one: it must settle (or rest), or the turn errors.
|
|
1887
1909
|
const settledReport = result.toolCalls.length === 1 && result.toolCalls[0].name === stepReportTool;
|
|
@@ -1967,6 +1989,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
1967
1989
|
{ role: "user", content: wrapUpTool === "settle" ? STEP_BUDGET_REPORT_INSTRUCTION : STEP_BUDGET_REST_INSTRUCTION },
|
|
1968
1990
|
]);
|
|
1969
1991
|
callbacks.onClearText?.();
|
|
1992
|
+
turnTally.stepBudgetExhausted();
|
|
1970
1993
|
(0, runtime_1.emitNervesEvent)({ level: "warn", component: "engine", event: "engine.step_budget_exhausted", message: `step budget used up; requesting a ${wrapUpTool}-only progress report`, meta: { stepBudget, providerIterations } });
|
|
1971
1994
|
continue;
|
|
1972
1995
|
}
|
|
@@ -2180,6 +2203,8 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2180
2203
|
? (0, tools_base_1.withCode)(`rejected: ${entry.call.name} was not advertised for this channel; no handler was executed.`, "unknown-tool")
|
|
2181
2204
|
: (0, tools_base_1.withCode)(`invalid tool arguments: ${detail}`, "invalid-arguments");
|
|
2182
2205
|
rejections.push(rejection);
|
|
2206
|
+
// A rejected call never reaches onToolEnd; count it as a failed call (a name the turn never offered is "unknown").
|
|
2207
|
+
turnTally.rejected(entry.call.name);
|
|
2183
2208
|
options?.toolBoundaryObserver?.({
|
|
2184
2209
|
name: entry.call.name,
|
|
2185
2210
|
reason: callableToolNames.has(entry.call.name) ? "invalid_arguments" : "profile_excluded",
|
|
@@ -2716,6 +2741,7 @@ async function runAgent(messages, callbacks, channel, signal, options) {
|
|
|
2716
2741
|
for (const name of matchedNames)
|
|
2717
2742
|
if (!loadedDeferredTools.includes(name))
|
|
2718
2743
|
loadedDeferredTools.push(name);
|
|
2744
|
+
turnTally.findTools(matched.map((tool) => tool.function.name));
|
|
2719
2745
|
// A job a bundle does with a command its skill documents has no door to find; the skill's section answers.
|
|
2720
2746
|
const skills = (0, skill_search_1.findToolsSkillNote)(query, activeToolNames);
|
|
2721
2747
|
if (matched.length > 0 || skills.hits > 0)
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TurnTally = exports.UNKNOWN_TOOL = exports.TURN_SUMMARY_CHANNELS = exports.ERROR_CLASSES_COVERED = exports.TURN_SUMMARY_ERROR_CLASSES = exports.RUN_AGENT_OUTCOMES_COVERED = exports.TURN_SUMMARY_OUTCOMES = void 0;
|
|
4
|
+
exports.tallyToolEnds = tallyToolEnds;
|
|
5
|
+
exports.emitTurnSummary = emitTurnSummary;
|
|
6
|
+
const runtime_1 = require("../nerves/runtime");
|
|
7
|
+
const tool_catalog_1 = require("../repertoire/tool-catalog");
|
|
8
|
+
/** Every value `runAgent` can end with; `RunAgentOutcome` in core.ts must stay a subset (a test pins it). */
|
|
9
|
+
exports.TURN_SUMMARY_OUTCOMES = ["settled", "suspended", "blocked", "superseded", "aborted", "errored", "observed", "rested"];
|
|
10
|
+
/** Fails to compile when `RunAgentOutcome` gains a value this list doesn't have. */
|
|
11
|
+
exports.RUN_AGENT_OUTCOMES_COVERED = true;
|
|
12
|
+
/** Why an errored turn failed: the provider error classes, or `none` when the turn didn't fail on an error. */
|
|
13
|
+
exports.TURN_SUMMARY_ERROR_CLASSES = ["auth-failure", "usage-limit", "rate-limit", "server-error", "network-error", "unknown", "none"];
|
|
14
|
+
/** Fails to compile when `ProviderErrorClassification` gains a value this list doesn't have. */
|
|
15
|
+
exports.ERROR_CLASSES_COVERED = true;
|
|
16
|
+
const CHANNEL_SET = {
|
|
17
|
+
cli: true, teams: true, bluebubbles: true, mail: true, voice: true, a2a: true, inner: true, mcp: true, telegram: true,
|
|
18
|
+
};
|
|
19
|
+
/** The channels a summary may name; anything else (or no channel) is `none`. */
|
|
20
|
+
exports.TURN_SUMMARY_CHANNELS = [...Object.keys(CHANNEL_SET), "none"];
|
|
21
|
+
/** The bucket for a tool name the turn never offered. */
|
|
22
|
+
exports.UNKNOWN_TOOL = "unknown";
|
|
23
|
+
/** The counters one `runAgent` call keeps. Every method is cheap and never throws on ordinary input. */
|
|
24
|
+
class TurnTally {
|
|
25
|
+
offered = new Map();
|
|
26
|
+
loaded = new Set();
|
|
27
|
+
calls = new Map();
|
|
28
|
+
provider = "unknown";
|
|
29
|
+
model = "unknown";
|
|
30
|
+
routed = false;
|
|
31
|
+
switches = 0;
|
|
32
|
+
emitted = false;
|
|
33
|
+
steps = 0;
|
|
34
|
+
budgetStops = 0;
|
|
35
|
+
errors = 0;
|
|
36
|
+
unknown = 0;
|
|
37
|
+
findCalls = 0;
|
|
38
|
+
findLoaded = 0;
|
|
39
|
+
loadedCalled = 0;
|
|
40
|
+
eager = 0;
|
|
41
|
+
deferred = 0;
|
|
42
|
+
input = 0;
|
|
43
|
+
output = 0;
|
|
44
|
+
reasoning = 0;
|
|
45
|
+
/** Records the doors a step offered (and those held back behind find_tools), so later calls can be named safely. */
|
|
46
|
+
offer(active, deferredPool, definitions) {
|
|
47
|
+
for (const tool of [...active, ...deferredPool]) {
|
|
48
|
+
const name = tool.function.name;
|
|
49
|
+
const server = definitions.get(name)?.mcpServer;
|
|
50
|
+
this.offered.set(name, server ? `mcp:${server}` : name);
|
|
51
|
+
}
|
|
52
|
+
const upFront = active.filter((tool) => tool.function.name !== tool_catalog_1.FIND_TOOLS_NAME && !this.loaded.has(tool.function.name));
|
|
53
|
+
this.eager = Math.max(this.eager, upFront.length);
|
|
54
|
+
this.deferred = Math.max(this.deferred, deferredPool.length);
|
|
55
|
+
}
|
|
56
|
+
/** The provider the turn is on; a change after the first counts as a fallback. */
|
|
57
|
+
route(provider, model) {
|
|
58
|
+
if (this.routed && (provider !== this.provider || model !== this.model))
|
|
59
|
+
this.switches += 1;
|
|
60
|
+
this.routed = true;
|
|
61
|
+
this.provider = provider;
|
|
62
|
+
this.model = model;
|
|
63
|
+
}
|
|
64
|
+
/** One provider call that returned, with the provider that served it and the usage it reported. */
|
|
65
|
+
step(usage, provider, model) {
|
|
66
|
+
this.route(provider, model);
|
|
67
|
+
this.steps += 1;
|
|
68
|
+
if (!usage)
|
|
69
|
+
return;
|
|
70
|
+
this.input += usage.input_tokens;
|
|
71
|
+
this.output += usage.output_tokens;
|
|
72
|
+
this.reasoning += usage.reasoning_tokens;
|
|
73
|
+
}
|
|
74
|
+
stepBudgetExhausted() {
|
|
75
|
+
this.budgetStops += 1;
|
|
76
|
+
}
|
|
77
|
+
/** A find_tools call and the door names it loaded. */
|
|
78
|
+
findTools(loadedNames) {
|
|
79
|
+
this.findCalls += 1;
|
|
80
|
+
if (loadedNames.length > 0)
|
|
81
|
+
this.findLoaded += 1;
|
|
82
|
+
for (const name of loadedNames)
|
|
83
|
+
this.loaded.add(name);
|
|
84
|
+
}
|
|
85
|
+
/** A tool call ended. find_tools is counted by `findTools`, so its own end is ignored here. */
|
|
86
|
+
toolEnd(name, success) {
|
|
87
|
+
if (name === tool_catalog_1.FIND_TOOLS_NAME)
|
|
88
|
+
return;
|
|
89
|
+
const label = this.offered.get(name);
|
|
90
|
+
if (label === undefined) {
|
|
91
|
+
this.unknown += 1;
|
|
92
|
+
this.calls.set(exports.UNKNOWN_TOOL, (this.calls.get(exports.UNKNOWN_TOOL) ?? 0) + 1);
|
|
93
|
+
if (!success)
|
|
94
|
+
this.errors += 1;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.calls.set(label, (this.calls.get(label) ?? 0) + 1);
|
|
98
|
+
if (!success)
|
|
99
|
+
this.errors += 1;
|
|
100
|
+
if (this.loaded.has(name))
|
|
101
|
+
this.loadedCalled += 1;
|
|
102
|
+
}
|
|
103
|
+
/** A call rejected before it ran (a name the turn didn't offer, or bad arguments): a failed call. */
|
|
104
|
+
rejected(name) {
|
|
105
|
+
if (name === tool_catalog_1.FIND_TOOLS_NAME) {
|
|
106
|
+
this.findCalls += 1;
|
|
107
|
+
this.errors += 1;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.toolEnd(name, false);
|
|
111
|
+
}
|
|
112
|
+
/** True the first time only, so a turn is summarized once. */
|
|
113
|
+
claimEmit() {
|
|
114
|
+
if (this.emitted)
|
|
115
|
+
return false;
|
|
116
|
+
this.emitted = true;
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
summarize(input) {
|
|
120
|
+
const channel = input.channel !== undefined && Object.hasOwn(CHANNEL_SET, input.channel) ? input.channel : "none";
|
|
121
|
+
const outcome = exports.TURN_SUMMARY_OUTCOMES.includes(input.outcome) ? input.outcome : "errored";
|
|
122
|
+
const errorClass = exports.TURN_SUMMARY_ERROR_CLASSES.includes(input.errorClass) ? input.errorClass : "unknown";
|
|
123
|
+
return {
|
|
124
|
+
channel,
|
|
125
|
+
outcome,
|
|
126
|
+
errorClass,
|
|
127
|
+
provider: safeLabel(this.provider),
|
|
128
|
+
model: safeLabel(this.model),
|
|
129
|
+
providerSwitches: this.switches,
|
|
130
|
+
steps: this.steps,
|
|
131
|
+
stepBudgetExhausted: this.budgetStops,
|
|
132
|
+
toolCalls: Object.fromEntries([...this.calls.entries()].sort(([a], [b]) => a.localeCompare(b))),
|
|
133
|
+
toolErrors: this.errors,
|
|
134
|
+
unknownToolCalls: this.unknown,
|
|
135
|
+
findToolsCalls: this.findCalls,
|
|
136
|
+
findToolsLoaded: this.findLoaded,
|
|
137
|
+
loadedThenCalled: this.loadedCalled,
|
|
138
|
+
eagerDoors: this.eager,
|
|
139
|
+
deferredDoors: this.deferred,
|
|
140
|
+
inputTokens: this.input,
|
|
141
|
+
outputTokens: this.output,
|
|
142
|
+
reasoningTokens: this.reasoning,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.TurnTally = TurnTally;
|
|
147
|
+
/**
|
|
148
|
+
* The channel callbacks with every `onToolEnd` also counted in `tally`. Everything else passes through untouched,
|
|
149
|
+
* including methods' `this`, and the tally never stops the original callback from running.
|
|
150
|
+
*/
|
|
151
|
+
function tallyToolEnds(callbacks, tally) {
|
|
152
|
+
return new Proxy(callbacks, {
|
|
153
|
+
get(target, property, receiver) {
|
|
154
|
+
const value = Reflect.get(target, property, receiver);
|
|
155
|
+
if (property !== "onToolEnd" || typeof value !== "function")
|
|
156
|
+
return value;
|
|
157
|
+
// A proxy must return a frozen property as it is; such callbacks go uncounted rather than break the turn.
|
|
158
|
+
const own = Object.getOwnPropertyDescriptor(target, property);
|
|
159
|
+
if (own && !own.configurable && !own.writable)
|
|
160
|
+
return value;
|
|
161
|
+
return (name, summary, success) => {
|
|
162
|
+
try {
|
|
163
|
+
tally.toolEnd(name, success);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Counting must never change what the turn does.
|
|
167
|
+
}
|
|
168
|
+
return value.call(target, name, summary, success);
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/** Provider and model ids come from configuration; anything that doesn't look like an id is replaced. */
|
|
174
|
+
function safeLabel(value) {
|
|
175
|
+
return /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,79}$/.test(value) ? value : "other";
|
|
176
|
+
}
|
|
177
|
+
/** Emits `engine.turn_summary` for a finished turn. It never throws: a summary that fails is dropped. */
|
|
178
|
+
function emitTurnSummary(tally, input) {
|
|
179
|
+
try {
|
|
180
|
+
if (!tally.claimEmit())
|
|
181
|
+
return;
|
|
182
|
+
(0, runtime_1.emitNervesEvent)({
|
|
183
|
+
event: "engine.turn_summary",
|
|
184
|
+
trace_id: input.traceId,
|
|
185
|
+
component: "engine",
|
|
186
|
+
message: "turn summary (counts only)",
|
|
187
|
+
meta: tally.summarize(input),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// The turn already finished; a lost summary must not change its result.
|
|
192
|
+
}
|
|
193
|
+
}
|
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.1462",
|
|
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.1462",
|
|
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.1462",
|
|
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": {
|