@ouro.bot/cli 0.1.0-alpha.1726 → 0.1.0-alpha.1727

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": "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.1727",
6
+ "changes": [
7
+ "When someone sends several messages in a row, the agent now gets every one of them, each on its own line. Before, on iMessage, a message that needed fetching from the server (a link with a preview, a picture) could lose its place to the plain message sent after it and never reach the agent: Slugger told Ari \"no link came through\" when one had. And messages waiting together reached the model run together (\"small size^from rach\"), because the model's API joins back-to-back messages with no break. Now a chat's iMessages take their turn in the order they arrived, the engine puts a line between back-to-back messages for every sense (iMessage, Teams, Telegram and the rest), and the agent's note of what was just said lists each message since its last reply, not only the newest."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1726",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1726",
2
+ "runtimeVersion": "0.1.0-alpha.1727",
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.1726</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1727</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -21,6 +21,7 @@ exports.isExternalStateQuery = isExternalStateQuery;
21
21
  exports.settleContentMismatchError = settleContentMismatchError;
22
22
  exports.getSettleRetryError = getSettleRetryError;
23
23
  exports.stripLastToolCalls = stripLastToolCalls;
24
+ exports.joinAdjacentUserMessages = joinAdjacentUserMessages;
24
25
  exports.repairOrphanedToolCalls = repairOrphanedToolCalls;
25
26
  exports.isRejectedRequest = isRejectedRequest;
26
27
  exports.dropReplayedReasoning = dropReplayedReasoning;
@@ -991,6 +992,42 @@ function stripLastToolCalls(messages) {
991
992
  // message, stop at the next assistant or user message (tool results must be
992
993
  // adjacent to their originating assistant message).
993
994
  const TOOL_SCAN_BOUNDARY_ROLES = new Set(["assistant", "user"]);
995
+ function joinUserContent(left, right) {
996
+ if (typeof left === "string" && typeof right === "string")
997
+ return `${left}\n${right}`;
998
+ const leftParts = typeof left === "string" ? [{ type: "text", text: left }] : [...left];
999
+ const rightParts = typeof right === "string" ? [{ type: "text", text: right }] : [...right];
1000
+ const last = leftParts.at(-1);
1001
+ const first = rightParts[0];
1002
+ if (last?.type === "text" && first?.type === "text") {
1003
+ return [...leftParts.slice(0, -1), { ...last, text: `${last.text}\n${first.text}` }, ...rightParts.slice(1)];
1004
+ }
1005
+ return [...leftParts, ...rightParts];
1006
+ }
1007
+ // Each message a person sends stays its own line. Two user messages in a row (a burst that arrived while a turn ran,
1008
+ // a steering follow-up, a turn that ended without a reply) would otherwise reach the model run together: Claude's API
1009
+ // merges adjacent same-role turns with no separator, which is how Slugger read "small size^from rach" on 2026-11-29.
1010
+ // This builds the request for providers that read `messages` (Anthropic, chat completions); Responses-API providers
1011
+ // build their input from the unjoined messages, where each stays a separate item. The session keeps every message as it was.
1012
+ // A system message between two user messages (a sense's context note before the newest one) doesn't keep them apart:
1013
+ // Claude's API lifts system messages out, so the two would still meet. The note moves ahead of the joined message.
1014
+ function joinAdjacentUserMessages(messages) {
1015
+ const joined = [];
1016
+ for (const message of messages) {
1017
+ let previousIndex = joined.length - 1;
1018
+ while (previousIndex >= 0 && joined[previousIndex].role === "system")
1019
+ previousIndex--;
1020
+ const previous = joined[previousIndex];
1021
+ if (message.role === "user" && previous?.role === "user") {
1022
+ joined.splice(previousIndex, 1);
1023
+ joined.push({ ...previous, content: joinUserContent(previous.content, message.content) });
1024
+ }
1025
+ else {
1026
+ joined.push(message);
1027
+ }
1028
+ }
1029
+ return joined;
1030
+ }
994
1031
  // Repair orphaned tool_calls and tool results anywhere in the message history.
995
1032
  // 1. If an assistant message has tool_calls but missing tool results, inject synthetic error results.
996
1033
  // 2. If a tool result's tool_call_id doesn't match any tool_calls in a preceding assistant message, remove it.
@@ -1826,7 +1863,7 @@ async function runCountedTurn(turnTally, messages, unboundedCallbacks, channel,
1826
1863
  : null;
1827
1864
  try {
1828
1865
  return await providerRuntime.streamTurn({
1829
- messages: attemptMessages,
1866
+ messages: joinAdjacentUserMessages(attemptMessages),
1830
1867
  activeTools,
1831
1868
  // A step narrowed to one tool (a step report, a forced repeat) sends no held-back doors either.
1832
1869
  ...(deferralPool.length > 0 && activeTools === candidateActiveTools ? { deferredTools: deferralPool } : {}),
@@ -226,13 +226,14 @@ const REPLYING_TO_LABEL = {
226
226
  other: " (someone else's message)",
227
227
  };
228
228
  function buildOrientationFrame(input) {
229
- const derivedCurrent = input.currentUserMessages
230
- ? { messages: input.currentUserMessages, firstIndex: input.messages.length }
231
- : currentUserMessagesFrom(input.messages);
229
+ // Current speech is every user message since the last reply: a burst of texts is all of what they said.
230
+ const derivedCurrent = currentUserMessagesFrom(input.messages);
232
231
  const currentUserSpeech = derivedCurrent.messages
233
232
  .map((message) => extractMessageText(message))
234
233
  .filter((text) => text.length > 0);
235
- const replyingTo = derivedCurrent.messages.map(replyingToOf).find((reply) => reply !== undefined);
234
+ // What they replied to is the newest message's: an earlier unanswered message's reply must not stand in for it.
235
+ const newestCurrent = derivedCurrent.messages.at(-1);
236
+ const replyingTo = newestCurrent ? replyingToOf(newestCurrent) : undefined;
236
237
  const previousAssistant = latestAssistantBefore(input.messages, derivedCurrent.firstIndex);
237
238
  // Only the agent's own message holds the list a "the second one" points into.
238
239
  const replyListText = replyingTo && (replyingTo.author ?? "agent") === "agent" ? replyingTo.text : undefined;
@@ -246,7 +246,7 @@ function seededObservationReservation(keyHash, fresh) {
246
246
  function suspendBlueBubblesSemanticObservation(generation) {
247
247
  generation.retry = true;
248
248
  generation.retainedAtMs = Date.now();
249
- (0, latest_turn_1.reactivateObservation)(generation.reservation);
249
+ (0, latest_turn_1.reactivateObservation)(generation.reservation, { retained: true });
250
250
  }
251
251
  function completeBlueBubblesSemanticObservation(keyHash, generation) {
252
252
  (0, latest_turn_1.clearPending)(generation.reservation);
@@ -1977,7 +1977,6 @@ async function handleBlueBubblesNormalizedEvent(event, resolvedDeps, source, opt
1977
1977
  const orientationFrame = (0, orientation_frame_1.buildOrientationFrame)({
1978
1978
  channel: "bluebubbles",
1979
1979
  messages: [...priorMessages, userMessage],
1980
- currentUserMessages: [userMessage],
1981
1980
  structuredOutputs: existing?.structuredOutputs ?? [],
1982
1981
  source: buildBlueBubblesOrientationSource(event, priorMessages, options.orientationEvidence, options.orientationConversationKind, repliedToText, repliedToAuthor),
1983
1982
  });
@@ -2652,11 +2651,11 @@ function semanticCaptureRequiresRoutingRepair(capture) {
2652
2651
  function hasResolvedBlueBubblesRouting(event) {
2653
2652
  return Boolean(event.chat.chatGuid?.trim() || event.chat.chatIdentifier?.trim());
2654
2653
  }
2655
- function reserveBlueBubblesObservation(event) {
2654
+ function reserveBlueBubblesObservation(event, options = {}) {
2656
2655
  return (0, latest_turn_1.reserveObservation)({
2657
2656
  chatGuid: event.chat.chatGuid,
2658
2657
  chatIdentifier: event.chat.chatIdentifier,
2659
- });
2658
+ }, options);
2660
2659
  }
2661
2660
  function groupBlueBubblesObservationsByLane(candidates) {
2662
2661
  let groups = [];
@@ -3074,6 +3073,10 @@ async function handleCapturedBlueBubblesSemanticEvent(captured, resolvedDeps, so
3074
3073
  fromMe: captured.normalized.fromMe,
3075
3074
  sender: captured.normalized.sender,
3076
3075
  };
3076
+ await (0, latest_turn_1.awaitOlderObservations)(reservation, {
3077
+ chatGuid: identityGroundedRepaired.chat.chatGuid,
3078
+ chatIdentifier: identityGroundedRepaired.chat.chatIdentifier,
3079
+ }, options.lifecycleSignal);
3077
3080
  const promotion = (0, latest_turn_1.promote)(reservation, {
3078
3081
  chatGuid: identityGroundedRepaired.chat.chatGuid,
3079
3082
  chatIdentifier: identityGroundedRepaired.chat.chatIdentifier,
@@ -3323,7 +3326,7 @@ async function handleBlueBubblesEvent(payload, deps = {}) {
3323
3326
  }
3324
3327
  const scope = new BlueBubblesObservationScope();
3325
3328
  try {
3326
- const observationReservation = scope.own(reserveBlueBubblesObservation(normalized));
3329
+ const observationReservation = scope.own(reserveBlueBubblesObservation(normalized, { live: true }));
3327
3330
  const captured = await captureBlueBubblesSemanticEvent(normalized, resolvedDeps, "webhook", observationReservation);
3328
3331
  if (captured.status === "audit_only") {
3329
3332
  return { handled: true, notifiedAgent: false, kind: normalized.kind, reason: "ignored" };
@@ -4133,7 +4136,7 @@ function createBlueBubblesWebhookHandler(deps = {}, options = {}) {
4133
4136
  const resolvedDeps = { ...defaultDeps, ...deps };
4134
4137
  // The scope outlives this request: it closes when the queued turn ends.
4135
4138
  const scope = new BlueBubblesObservationScope();
4136
- const observationReservation = scope.own(reserveBlueBubblesObservation(normalized));
4139
+ const observationReservation = scope.own(reserveBlueBubblesObservation(normalized, { live: true }));
4137
4140
  let captured;
4138
4141
  try {
4139
4142
  captured = await captureBlueBubblesSemanticEvent(normalized, resolvedDeps, "webhook", observationReservation);
@@ -10,6 +10,7 @@ exports.promote = promote;
10
10
  exports.isCurrent = isCurrent;
11
11
  exports.observationSchedulingKeys = observationSchedulingKeys;
12
12
  exports.awaitDeliveryAdmission = awaitDeliveryAdmission;
13
+ exports.awaitOlderObservations = awaitOlderObservations;
13
14
  exports.listPendingObservationsForAudit = listPendingObservationsForAudit;
14
15
  exports.isDeliveryAdmittedNow = isDeliveryAdmittedNow;
15
16
  exports.cancel = cancel;
@@ -23,6 +24,7 @@ const pending = new Map();
23
24
  const lanes = new Map();
24
25
  const identifierBindings = new Map();
25
26
  const reservationHints = new WeakMap();
27
+ const liveReservations = new WeakSet();
26
28
  const batchReservations = new WeakMap();
27
29
  const observationEpoch = `${new Date().toISOString()}/${(0, node_crypto_1.randomUUID)()}`;
28
30
  let nextOrdinal = 0;
@@ -64,7 +66,7 @@ function settlePending(ordinal) {
64
66
  pending.delete(ordinal);
65
67
  entry.settle();
66
68
  }
67
- function createReservation(ordinal, input) {
69
+ function createReservation(ordinal, input, live = false) {
68
70
  const knownHints = new Set(observationHints(input));
69
71
  const reservation = Object.freeze({
70
72
  observationEpoch,
@@ -74,6 +76,8 @@ function createReservation(ordinal, input) {
74
76
  },
75
77
  });
76
78
  reservationHints.set(reservation, knownHints);
79
+ if (live)
80
+ liveReservations.add(reservation);
77
81
  let settle;
78
82
  const settled = new Promise((resolve) => {
79
83
  settle = resolve;
@@ -83,11 +87,13 @@ function createReservation(ordinal, input) {
83
87
  hints: new Set(knownHints),
84
88
  settled,
85
89
  settle,
90
+ live,
86
91
  });
87
92
  return reservation;
88
93
  }
89
- function reserveObservation(input) {
90
- return createReservation(++nextOrdinal, input);
94
+ /** `live` marks a webhook arrival, which newer arrivals in its chat wait for before they take the lane. */
95
+ function reserveObservation(input, options = {}) {
96
+ return createReservation(++nextOrdinal, input, options.live === true);
91
97
  }
92
98
  function beginObservationBatch(size) {
93
99
  if (!Number.isSafeInteger(size) || size <= 0)
@@ -118,9 +124,16 @@ function reserveObservationFromBatch(batch, newestOffset, input) {
118
124
  function clearPending(reservation) {
119
125
  settlePending(reservation.ordinal);
120
126
  }
121
- function reactivateObservation(reservation) {
122
- if (pending.has(reservation.ordinal))
127
+ /** Makes a reservation pending again: in flight once more, or `retained` while it waits for recovery. */
128
+ function reactivateObservation(reservation, options = {}) {
129
+ const existing = pending.get(reservation.ordinal);
130
+ if (existing && !(options.retained && !existing.retained)) {
131
+ existing.retained = options.retained;
123
132
  return;
133
+ }
134
+ // Parking an in-flight observation settles it, which wakes newer arrivals waiting on it; it stays pending as retained.
135
+ if (existing)
136
+ settlePending(reservation.ordinal);
124
137
  const knownHints = reservationHints.get(reservation);
125
138
  if (!knownHints)
126
139
  throw new Error("bluebubbles_observation_reservation_unknown");
@@ -133,6 +146,8 @@ function reactivateObservation(reservation) {
133
146
  hints: new Set(knownHints),
134
147
  settled,
135
148
  settle,
149
+ live: liveReservations.has(reservation),
150
+ retained: options.retained,
136
151
  });
137
152
  }
138
153
  function mergeObservationReservations(primary, duplicate) {
@@ -232,16 +247,19 @@ function isCurrent(capability) {
232
247
  function pendingIntersects(capability, entry) {
233
248
  if (entry.reservation.ordinal <= capability.ordinal)
234
249
  return false;
250
+ return pendingIntersectsChat(entry, capability.chatKey, capability.canonicalChat.chatGuid);
251
+ }
252
+ function pendingIntersectsChat(entry, chatKey, chatGuid) {
235
253
  const hasGuidHint = [...entry.hints].some((hint) => hint.startsWith("guid:"));
236
254
  if (entry.hints.size === 0)
237
255
  return true;
238
256
  for (const hint of entry.hints) {
239
- if (hint === capability.chatKey)
257
+ if (hint === chatKey)
240
258
  return true;
241
259
  if (hint.startsWith("identifier:")) {
242
260
  const identifier = hint.slice("identifier:".length);
243
261
  const binding = identifierBindings.get(identifier);
244
- if (binding === capability.canonicalChat.chatGuid)
262
+ if (binding === chatGuid)
245
263
  return true;
246
264
  // An identifier-only observation can repair into any GUID lane. Until
247
265
  // that relation is proved, it is a temporary global delivery fence—not
@@ -309,6 +327,47 @@ async function awaitDeliveryAdmission(capability, signal) {
309
327
  }
310
328
  return false;
311
329
  }
330
+ // Only an observation known to be in this chat holds it back. One without a route yet could be in any chat; it fences
331
+ // delivery, but waiting on it here would stall every chat for its whole capture and repair.
332
+ function provablyInChat(entry, chatKey, chatGuid) {
333
+ for (const hint of entry.hints) {
334
+ if (hint === chatKey)
335
+ return true;
336
+ if (hint.startsWith("identifier:") && identifierBindings.get(hint.slice("identifier:".length)) === chatGuid)
337
+ return true;
338
+ }
339
+ return false;
340
+ }
341
+ /**
342
+ * Waits until every older observation that may belong to this chat has been promoted or settled, so a chat's messages
343
+ * take the lane, and reach its session, in the order they arrived. A message that needs a slow repair (a link preview)
344
+ * would otherwise lose the lane to the plain message after it and never reach the turn (Slugger, 2026-11-29). Only
345
+ * live webhook arrivals are waited for: recovery handles a chat newest first, one at a time, and an observation parked
346
+ * for recovery never holds newer ones back. Rejects with the reason when `signal` aborts.
347
+ */
348
+ async function awaitOlderObservations(reservation, input, signal) {
349
+ const canonicalChat = resolveCanonicalChat(input);
350
+ if (!canonicalChat)
351
+ return;
352
+ const chatKey = guidAlias(canonicalChat.chatGuid);
353
+ const signals = signal ? [signal] : [];
354
+ for (;;) {
355
+ signal?.throwIfAborted();
356
+ const blockers = [...pending.values()].filter((entry) => (entry.reservation.ordinal < reservation.ordinal
357
+ && entry.live === true
358
+ && !entry.retained
359
+ && provablyInChat(entry, chatKey, canonicalChat.chatGuid)));
360
+ if (blockers.length === 0)
361
+ return;
362
+ (0, runtime_1.emitNervesEvent)({
363
+ component: "senses",
364
+ event: "senses.bluebubbles_older_observation_wait",
365
+ message: "waiting for older messages in this chat before taking the lane",
366
+ meta: { chatKey, ordinal: reservation.ordinal, olderCount: blockers.length },
367
+ });
368
+ await untilSettledOrAborted(blockers, signals);
369
+ }
370
+ }
312
371
  /** Every observation still pending, oldest first. The sense's ownership audit checks each has an owner. */
313
372
  function listPendingObservationsForAudit() {
314
373
  return [...pending.values()]
@@ -1035,8 +1035,8 @@ async function handleInboundTurnExclusive(input) {
1035
1035
  : (currentUserMessages.length > 0
1036
1036
  ? (0, orientation_frame_1.buildOrientationFrame)({
1037
1037
  channel: input.channel,
1038
+ // Current speech is every message they sent since the last reply, so a burst reads as all of its lines.
1038
1039
  messages: sessionMessages,
1039
- currentUserMessages,
1040
1040
  structuredOutputs: session.structuredOutputs ?? [],
1041
1041
  familySpeaker,
1042
1042
  })
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1726",
3
+ "version": "0.1.0-alpha.1727",
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.1726",
9
+ "version": "0.1.0-alpha.1727",
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.1726",
3
+ "version": "0.1.0-alpha.1727",
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": {