@ouro.bot/cli 0.1.0-alpha.1056 → 0.1.0-alpha.1059

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,18 @@
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.1059",
6
+ "changes": [
7
+ "The prompt budget counts each image (a screenshot from a tool, a pasted picture) as a fixed 1,600 tokens instead of by its base64 length. Before, one 193 KB screenshot was estimated at about 64K tokens, so a small turn looked over budget, lost 122 messages to trimming and then failed with 400 Bad Request. If images still don't fit after optional history is dropped, the budget swaps each whole image for a short note rather than slicing it; the required current user message keeps its images. The context trimmer's token estimate also counts images now: an image after a text part used to count as nothing."
8
+ ]
9
+ },
10
+ {
11
+ "version": "0.1.0-alpha.1057",
12
+ "changes": [
13
+ "Habit wakes: require a known trigger, prove it end to end"
14
+ ]
15
+ },
4
16
  {
5
17
  "version": "0.1.0-alpha.1056",
6
18
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1056",
2
+ "runtimeVersion": "0.1.0-alpha.1059",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -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.1056</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1059</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -41,6 +41,7 @@ const identity_1 = require("../identity");
41
41
  const auth_flow_1 = require("../auth/auth-flow");
42
42
  const runtime_1 = require("../../nerves/runtime");
43
43
  const provider_credentials_1 = require("../provider-credentials");
44
+ const flight_recorder_1 = require("../../arc/flight-recorder");
44
45
  const ledger_1 = require("./ledger");
45
46
  function isRecord(value) {
46
47
  return !!value && typeof value === "object" && !Array.isArray(value);
@@ -184,14 +185,7 @@ async function evaluatePolicy(request, context, deps) {
184
185
  reason: "verified daemon await check",
185
186
  };
186
187
  }
187
- const habitTrigger = request.triggerSource.startsWith("habit-") ? request.triggerSource.slice("habit-".length) : "";
188
- if (habitTrigger.length > 0
189
- && hasNonEmptyOriginRef(originRefs, "habit")
190
- && hasOriginRef(originRefs, "habit-trigger", habitTrigger)
191
- && hasNonEmptyOriginRef(originRefs, "habit-occurrence")
192
- && (hasOriginRef(originRefs, "daemon-entry", "habit-scheduler")
193
- || hasOriginRef(originRefs, "daemon-command", "habit.poke")
194
- || hasOriginRef(originRefs, "daemon-command", "habit.probe"))) {
188
+ if (isVerifiedHabitWake(request.triggerSource, originRefs)) {
195
189
  return {
196
190
  result: "allow",
197
191
  reason: "verified daemon habit",
@@ -203,6 +197,26 @@ async function evaluatePolicy(request, context, deps) {
203
197
  deniedReason: "default policy deny",
204
198
  };
205
199
  }
200
+ /** Where a habit wake may come from: the daemon's own scheduler, or `ouro poke`/probe through the daemon. */
201
+ const HABIT_WAKE_SOURCES = [
202
+ ["daemon-entry", "habit-scheduler"],
203
+ ["daemon-command", "habit.poke"],
204
+ ["daemon-command", "habit.probe"],
205
+ ];
206
+ /**
207
+ * A habit wake the daemon built (buildHabitPrivateWakeCommand): it names the habit, its trigger
208
+ * and occurrence, comes from one of the daemon's habit sources, and its trigger source matches
209
+ * its trigger. The daemon has already checked the habit file is active before asking.
210
+ */
211
+ function isVerifiedHabitWake(triggerSource, originRefs) {
212
+ const trigger = originRefs.find((ref) => ref.kind === "habit-trigger")?.id;
213
+ return typeof trigger === "string"
214
+ && (0, flight_recorder_1.isHabitRunTrigger)(trigger)
215
+ && triggerSource === `habit-${trigger}`
216
+ && hasNonEmptyOriginRef(originRefs, "habit")
217
+ && hasNonEmptyOriginRef(originRefs, "habit-occurrence")
218
+ && HABIT_WAKE_SOURCES.some(([kind, id]) => hasOriginRef(originRefs, kind, id));
219
+ }
206
220
  function emptyReceiptId() {
207
221
  return "";
208
222
  }
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROMPT_BUDGET_FALLBACK_CONTEXT_WINDOW_TOKENS = exports.PROMPT_BUDGET_POLICY_VERSION = void 0;
3
+ exports.PROMPT_BUDGET_OMITTED_IMAGE_NOTE = exports.PROMPT_BUDGET_FALLBACK_CONTEXT_WINDOW_TOKENS = exports.PROMPT_BUDGET_POLICY_VERSION = void 0;
4
4
  exports.estimatePromptBudgetTokensForMessage = estimatePromptBudgetTokensForMessage;
5
5
  exports.estimatePromptBudgetTokens = estimatePromptBudgetTokens;
6
6
  exports.assessRequiredPromptEvidenceBudget = assessRequiredPromptEvidenceBudget;
7
7
  exports.applyPromptBudget = applyPromptBudget;
8
8
  const runtime_1 = require("../nerves/runtime");
9
+ const token_estimate_1 = require("./token-estimate");
9
10
  exports.PROMPT_BUDGET_POLICY_VERSION = "prompt-budget/v1";
10
11
  exports.PROMPT_BUDGET_FALLBACK_CONTEXT_WINDOW_TOKENS = 24_000;
12
+ const PROMPT_BUDGET_CHARS_PER_TOKEN = 4;
13
+ const IMAGE_PART_ESTIMATED_CHARACTERS = token_estimate_1.IMAGE_PART_ESTIMATED_TOKENS * PROMPT_BUDGET_CHARS_PER_TOKEN;
14
+ exports.PROMPT_BUDGET_OMITTED_IMAGE_NOTE = "[image omitted to fit the prompt budget]";
11
15
  function contentCharacters(content) {
12
16
  if (typeof content === "string")
13
17
  return content.length;
@@ -19,6 +23,8 @@ function contentCharacters(content) {
19
23
  return total + part.length;
20
24
  if (!part || typeof part !== "object")
21
25
  return total;
26
+ if ((0, token_estimate_1.isImageContentPart)(part))
27
+ return total + IMAGE_PART_ESTIMATED_CHARACTERS;
22
28
  const record = part;
23
29
  if (typeof record.text === "string")
24
30
  return total + record.text.length;
@@ -79,7 +85,7 @@ function estimatePromptBudgetTokensForMessage(message) {
79
85
  characters += record.tool_call_id.length;
80
86
  characters += contentCharacters(record.content);
81
87
  characters += toolCallCharacters(record.tool_calls);
82
- return Math.ceil(characters / 4);
88
+ return Math.ceil(characters / PROMPT_BUDGET_CHARS_PER_TOKEN);
83
89
  }
84
90
  function estimatePromptBudgetTokens(messages) {
85
91
  return messages.reduce((total, message) => total + estimatePromptBudgetTokensForMessage(message), 0);
@@ -316,6 +322,22 @@ function buildPromptBudgetItems(messages, requiredPromptEvidence) {
316
322
  return { ...item, priority: 3, source: "recent-session-tail" };
317
323
  });
318
324
  }
325
+ /** Swaps each whole image part for a short note; an image is never sliced. Null when the item has no images. */
326
+ function withoutImageParts(item) {
327
+ let replaced = false;
328
+ const messages = item.messages.map((message) => {
329
+ if (!Array.isArray(message.content))
330
+ return message;
331
+ const content = message.content.map((part) => {
332
+ if (!part || typeof part !== "object" || !(0, token_estimate_1.isImageContentPart)(part))
333
+ return part;
334
+ replaced = true;
335
+ return { type: "text", text: exports.PROMPT_BUDGET_OMITTED_IMAGE_NOTE };
336
+ });
337
+ return { ...cloneMessage(message), content };
338
+ });
339
+ return replaced ? { ...item, messages } : null;
340
+ }
319
341
  function flattenItems(items) {
320
342
  return items.flatMap((item) => item.messages.map((message) => item.required ? message : cloneMessage(message)));
321
343
  }
@@ -455,6 +477,16 @@ function applyPromptBudget(input) {
455
477
  itemIndex -= 1;
456
478
  }
457
479
  }
480
+ for (let itemIndex = 0; itemIndex < items.length && totalItemTokens(items) > budget.inputTokenLimit; itemIndex += 1) {
481
+ const item = items[itemIndex];
482
+ if (item.required)
483
+ continue;
484
+ const withoutImages = withoutImageParts(item);
485
+ if (!withoutImages)
486
+ continue;
487
+ truncations.push(truncationFor(item, "replaced images with a note to fit prompt budget", itemTokens(item), itemTokens(withoutImages)));
488
+ items = items.map((candidate, index) => index === itemIndex ? withoutImages : candidate);
489
+ }
458
490
  const messages = flattenItems(items);
459
491
  const estimatedAfterTokens = estimatePromptBudgetTokens(messages);
460
492
  const status = estimatedAfterTokens <= budget.inputTokenLimit
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IMAGE_PART_ESTIMATED_TOKENS = void 0;
4
+ exports.isImageContentPart = isImageContentPart;
3
5
  exports.estimateTokensForMessage = estimateTokensForMessage;
4
6
  exports.estimateTokensForMessages = estimateTokensForMessages;
5
7
  const runtime_1 = require("../nerves/runtime");
@@ -7,6 +9,17 @@ const runtime_1 = require("../nerves/runtime");
7
9
  // Goal: avoid context overflows without pulling in tokenizer deps.
8
10
  const CHARS_PER_TOKEN = 4;
9
11
  const PER_MESSAGE_OVERHEAD_TOKENS = 10;
12
+ /**
13
+ * What one image part costs a vision model, whatever its base64 size. Anthropic bills about
14
+ * width*height/750 tokens and scales images to a 1568px long edge, which tops out near 1,600.
15
+ */
16
+ exports.IMAGE_PART_ESTIMATED_TOKENS = 1_600;
17
+ const IMAGE_PART_TYPES = new Set(["image_url", "input_image", "image"]);
18
+ /** True for the image content-part shapes providers see: chat `image_url`, Responses `input_image`, Anthropic `image`. */
19
+ function isImageContentPart(part) {
20
+ const type = part.type;
21
+ return typeof type === "string" && IMAGE_PART_TYPES.has(type);
22
+ }
10
23
  function safeStringify(value) {
11
24
  try {
12
25
  return JSON.stringify(value);
@@ -30,6 +43,10 @@ function countCharsInContent(content) {
30
43
  continue;
31
44
  }
32
45
  if (typeof part === "object") {
46
+ if (isImageContentPart(part)) {
47
+ total += exports.IMAGE_PART_ESTIMATED_TOKENS * CHARS_PER_TOKEN;
48
+ continue;
49
+ }
33
50
  // Common OpenAI content-part shapes: {type:"text", text:"..."}
34
51
  // Be defensive and only count obvious text-like fields.
35
52
  const p = part;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1056",
3
+ "version": "0.1.0-alpha.1059",
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.1056",
9
+ "version": "0.1.0-alpha.1059",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@ouro.bot/friends": "0.1.0-alpha.18",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1056",
3
+ "version": "0.1.0-alpha.1059",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },