@ouro.bot/cli 0.1.0-alpha.1707 → 0.1.0-alpha.1709

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
@@ -2,9 +2,11 @@
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
4
  {
5
- "version": "0.1.0-alpha.1707",
5
+ "version": "0.1.0-alpha.1709",
6
6
  "changes": [
7
- "Internal: the release script's npm-wait tests that run an hour on a fake clock now have a 60 s timeout, so they no longer fail on a busy CI runner (#2053)."
7
+ "Internal: the release script's npm-wait tests that run an hour on a fake clock now have a 60 s timeout, so they no longer fail on a busy CI runner (#2053).",
8
+ "iMessage no longer misses a message that iMessage delivers minutes after it was sent. Catch-up used to look only at messages sent in the last 90 seconds, so a late message that BlueBubbles sent no webhook for waited until the next outage to be found (8.5 minutes on 2026-11-27). Each 30-second catch-up now also reads the rows that reached the Messages database since the last one, by arrival order, so the agent gets such a message within about 30 seconds of it landing, and the log says how late iMessage delivered it. If that turn fails, the next catch-up reaches back to the message again, for up to a day.",
9
+ "Update the Ouro UI files to Ouro UI v1.3.637."
8
10
  ]
9
11
  },
10
12
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1707",
2
+ "runtimeVersion": "0.1.0-alpha.1709",
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.1707</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1709</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -29,6 +29,17 @@ class BlueBubblesSendError extends Error {
29
29
  }
30
30
  }
31
31
  exports.BlueBubblesSendError = BlueBubblesSendError;
32
+ function toMessageArrival(row) {
33
+ const record = asRecord(row);
34
+ const rowId = record?.originalROWID ?? record?.ROWID;
35
+ if (typeof rowId !== "number" || !Number.isInteger(rowId))
36
+ return null;
37
+ return {
38
+ rowId,
39
+ sentAt: hasValidRawMessageCausalTimestamp(row) ? record.dateCreated : null,
40
+ fromMe: record.isFromMe === true,
41
+ };
42
+ }
32
43
  function buildBlueBubblesApiUrl(baseUrl, endpoint, password) {
33
44
  const root = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
34
45
  const url = new URL(endpoint.replace(/^\//, ""), root);
@@ -684,6 +695,52 @@ function createBlueBubblesClient(config = (0, config_1.getBlueBubblesConfig)(),
684
695
  request,
685
696
  };
686
697
  },
698
+ async listArrivalsAfter(params) {
699
+ await assertHostAccount();
700
+ const url = buildBlueBubblesApiUrl(config.serverUrl, "/api/v1/message/query", config.password);
701
+ const body = {
702
+ limit: params.limit,
703
+ offset: params.offset,
704
+ sort: "DESC",
705
+ with: [],
706
+ ...(params.afterRowId === undefined && params.throughRowId === undefined
707
+ ? {}
708
+ : {
709
+ where: [
710
+ ...(params.afterRowId === undefined
711
+ ? []
712
+ : [{ statement: "message.ROWID > :afterRowId", args: { afterRowId: params.afterRowId } }]),
713
+ ...(params.throughRowId === undefined
714
+ ? []
715
+ : [{ statement: "message.ROWID <= :throughRowId", args: { throughRowId: params.throughRowId } }]),
716
+ ],
717
+ }),
718
+ };
719
+ const response = await fetch(url, {
720
+ method: "POST",
721
+ headers: { "Content-Type": "application/json" },
722
+ body: JSON.stringify(body),
723
+ signal: AbortSignal.timeout(channelConfig.requestTimeoutMs),
724
+ });
725
+ if (!response.ok) {
726
+ const errorText = await response.text().catch(() => "");
727
+ throw new Error(`BlueBubbles arrival query failed (${response.status}): ${errorText || "unknown"}`);
728
+ }
729
+ const rows = extractMessageQueryRows(await parseJsonBody(response));
730
+ const arrivals = rows.map(toMessageArrival).filter((arrival) => arrival !== null);
731
+ (0, runtime_1.emitNervesEvent)({
732
+ component: "senses",
733
+ event: "senses.bluebubbles_arrivals_listed",
734
+ message: "listed bluebubbles message arrivals",
735
+ meta: {
736
+ afterRowId: params.afterRowId ?? null,
737
+ throughRowId: params.throughRowId ?? null,
738
+ rows: rows.length,
739
+ arrivals: arrivals.length,
740
+ },
741
+ });
742
+ return arrivals;
743
+ },
687
744
  async listRecentMessages(params = {}) {
688
745
  const result = await this.queryRecentMessagesWithMetadata(params);
689
746
  return result.messages;
@@ -478,6 +478,7 @@ const BLUEBUBBLES_LIVE_TURN_STALLED_MS = 5 * 60_000;
478
478
  const BLUEBUBBLES_CALLBACK_CLEANUP_TIMEOUT_MS = 2_000;
479
479
  const BLUEBUBBLES_ACTIVITY_OPERATION_TIMEOUT_MS = 20_000;
480
480
  const BLUEBUBBLES_CATCHUP_PAGE_SIZE = 50;
481
+ const BLUEBUBBLES_ARRIVAL_PAGE_SIZE = 100;
481
482
  const BLUEBUBBLES_CATCHUP_MAX_PAGES = 20;
482
483
  const BLUEBUBBLES_HEALTHY_CATCHUP_OVERLAP_MS = 90_000;
483
484
  const BLUEBUBBLES_RECOVERY_CATCHUP_LOOKBACK_MS = 24 * 60 * 60 * 1000;
@@ -3450,6 +3451,8 @@ async function syncBlueBubblesRuntime(deps = {}, options = {}) {
3450
3451
  detail: formatBlueBubblesRuntimeDetail(pendingAfterCatchup, failed, activeAfterCatchup),
3451
3452
  lastCheckedAt: checkedAt,
3452
3453
  catchUpThrough: checkedAt,
3454
+ catchUpRowId: catchUp.arrivalCursor,
3455
+ catchUpLateSince: catchUp.lateSince ?? null,
3453
3456
  ...recoveryLookback,
3454
3457
  proofMethod: "bluebubbles.checkHealth",
3455
3458
  ...pendingAfterCatchup,
@@ -3555,6 +3558,59 @@ async function recoverQueuedBlueBubblesMessages(deps = {}, options = {}) {
3555
3558
  }
3556
3559
  return { recovered, skipped, failed, pendingRecoveryCount };
3557
3560
  }
3561
+ function highestArrivalRowId(arrivals) {
3562
+ return arrivals.length === 0 ? undefined : arrivals.reduce((highest, arrival) => Math.max(highest, arrival.rowId), -1);
3563
+ }
3564
+ /**
3565
+ * Reads the rows past the cursor. A short first page is all of them. A longer backlog is read oldest first, in ROWID
3566
+ * windows a page wide, so a pass that reaches the page limit has read a contiguous run and the next pass carries on
3567
+ * from where it stopped.
3568
+ */
3569
+ async function readBlueBubblesArrivalsSince(client, afterRowId, options) {
3570
+ /* v8 ignore next -- older injected test doubles may omit the arrival query method */
3571
+ if (!client.listArrivalsAfter)
3572
+ return { arrivals: [], cursor: afterRowId };
3573
+ const list = async (params) => {
3574
+ const rows = await client.listArrivalsAfter({ ...params, limit: BLUEBUBBLES_ARRIVAL_PAGE_SIZE, offset: 0 });
3575
+ options.lifecycleSignal?.throwIfAborted();
3576
+ options.onProgress?.();
3577
+ return rows;
3578
+ };
3579
+ if (afterRowId === undefined) {
3580
+ // With no cursor yet, the newest rows start one, and nothing counts as late.
3581
+ return { arrivals: [], cursor: highestArrivalRowId(await list({})) };
3582
+ }
3583
+ const first = await list({ afterRowId });
3584
+ if (first.length === 0) {
3585
+ // A quiet pass, unless the rows near the cursor are gone too. The newest page is by sent time, not ROWID, so it is
3586
+ // no test of where the cursor stands; it only picks a lower restart point, and a lower cursor only reads rows again.
3587
+ const nearCursor = await list({ afterRowId: Math.max(afterRowId - BLUEBUBBLES_ARRIVAL_PAGE_SIZE, 0), throughRowId: afterRowId });
3588
+ if (nearCursor.length > 0)
3589
+ return { arrivals: [], cursor: afterRowId };
3590
+ const newest = highestArrivalRowId(await list({}));
3591
+ if (newest !== undefined)
3592
+ return { arrivals: [], cursor: newest, resetFromRowId: afterRowId };
3593
+ return { arrivals: [], cursor: afterRowId };
3594
+ }
3595
+ if (first.length < BLUEBUBBLES_ARRIVAL_PAGE_SIZE)
3596
+ return { arrivals: first, cursor: highestArrivalRowId(first) };
3597
+ const arrivals = [];
3598
+ let cursor = afterRowId;
3599
+ for (let page = 1; page < BLUEBUBBLES_CATCHUP_MAX_PAGES; page++) {
3600
+ const windowEnd = cursor + BLUEBUBBLES_ARRIVAL_PAGE_SIZE;
3601
+ const rows = await list({ afterRowId: cursor, throughRowId: windowEnd });
3602
+ arrivals.push(...rows);
3603
+ if (rows.length > 0) {
3604
+ cursor = highestArrivalRowId(rows);
3605
+ continue;
3606
+ }
3607
+ // An empty window is a run of deleted rows when a later row exists (new rows only ever get higher ROWIDs), or the end.
3608
+ if ((await list({ afterRowId: windowEnd })).length === 0)
3609
+ break;
3610
+ cursor = windowEnd;
3611
+ }
3612
+ return { arrivals, cursor };
3613
+ }
3558
3614
  function catchUpMissedBlueBubblesMessages(deps = {}, previousState, options = {}) {
3559
3615
  return withObservationScope((scope) => catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousState, options));
3560
3616
  }
@@ -3567,7 +3623,60 @@ async function catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousStat
3567
3623
  const state = previousState ?? (0, runtime_state_1.readBlueBubblesRuntimeState)(agentName);
3568
3624
  const cutover = (0, semantic_receipts_1.initializeBlueBubblesSemanticCutover)(agentName);
3569
3625
  const catchUpWindow = resolveBlueBubblesCatchUpWindow(state);
3570
- const catchUpSince = Math.max(catchUpWindow.since, Date.parse(cutover.effectiveAt));
3626
+ /* v8 ignore next -- older injected test doubles may omit the catch-up query method */
3627
+ if (!client.listRecentMessages)
3628
+ return result;
3629
+ // The window below is in sent time, but iMessage can deliver a message minutes after it was sent, and BlueBubbles
3630
+ // sends no webhook for some of those (2026-11-27: 3 to 8 minutes late, four times in one afternoon). Rows that
3631
+ // arrived since the last pass are found by ROWID, and the window reaches back to the oldest one's sent time.
3632
+ let catchUpQueryFailed = false;
3633
+ let reachedPageLimit = false;
3634
+ const arrivalRead = await readBlueBubblesArrivalsSince(client, state.catchUpRowId, options).catch((error) => {
3635
+ if (options.lifecycleSignal?.aborted)
3636
+ throw options.lifecycleSignal.reason;
3637
+ catchUpQueryFailed = true;
3638
+ result.failed++;
3639
+ (0, runtime_1.emitNervesEvent)({
3640
+ level: "warn",
3641
+ component: "senses",
3642
+ event: "senses.bluebubbles_catchup_error",
3643
+ message: "bluebubbles upstream arrival query failed",
3644
+ meta: { stage: "arrivals", reason: error instanceof Error ? error.message : String(error) },
3645
+ });
3646
+ return null;
3647
+ });
3648
+ if (arrivalRead?.resetFromRowId !== undefined) {
3649
+ (0, runtime_1.emitNervesEvent)({
3650
+ level: "warn",
3651
+ component: "senses",
3652
+ event: "senses.bluebubbles_arrival_cursor_reset",
3653
+ message: "every bluebubbles message row sits below the arrival cursor; starting it again from the newest",
3654
+ meta: { fromRowId: arrivalRead.resetFromRowId, toRowId: arrivalRead.cursor },
3655
+ });
3656
+ }
3657
+ const nowMs = Date.now();
3658
+ const lateArrivalSentAt = (arrivalRead?.arrivals ?? [])
3659
+ .filter((arrival) => !arrival.fromMe && arrival.sentAt !== null)
3660
+ .reduce((oldest, arrival) => Math.min(oldest, arrival.sentAt), Number.POSITIVE_INFINITY);
3661
+ // A late arrival an earlier pass could not finish is carried in state, since the cursor has already moved past it.
3662
+ // It is dropped once older than the day-long lookback, so one message that keeps failing cannot widen every pass.
3663
+ const lookbackFloor = nowMs - BLUEBUBBLES_RECOVERY_CATCHUP_LOOKBACK_MS;
3664
+ const carriedLateSince = parseTimestampMs(state.catchUpLateSince ?? undefined);
3665
+ const unfinishedLateSince = Math.min(lateArrivalSentAt, carriedLateSince !== null && carriedLateSince >= lookbackFloor ? carriedLateSince : Number.POSITIVE_INFINITY);
3666
+ const catchUpSince = Math.max(Math.min(catchUpWindow.since, Math.max(unfinishedLateSince, lookbackFloor)), Date.parse(cutover.effectiveAt));
3667
+ if (lateArrivalSentAt < catchUpWindow.since) {
3668
+ (0, runtime_1.emitNervesEvent)({
3669
+ level: "warn",
3670
+ component: "senses",
3671
+ event: "senses.bluebubbles_late_arrival_seen",
3672
+ message: "a bluebubbles message reached the Messages database long after it was sent",
3673
+ meta: {
3674
+ sentAt: new Date(lateArrivalSentAt).toISOString(),
3675
+ lateByMs: nowMs - lateArrivalSentAt,
3676
+ mode: catchUpWindow.mode,
3677
+ },
3678
+ });
3679
+ }
3571
3680
  // Healthy passes run every 30 s and stay at info; outage passes are logged, so a miss leaves evidence.
3572
3681
  const catchUpLogLevel = catchUpWindow.mode === "recovery" || catchUpWindow.mode === "settling" ? "warn" : "info";
3573
3682
  const processTurns = options.processTurns !== false;
@@ -3576,9 +3685,6 @@ async function catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousStat
3576
3685
  pendingKeyHashes ??= new Set((0, semantic_receipts_1.listPendingBlueBubblesSemanticCaptures)(agentName).map((capture) => capture.keyHash));
3577
3686
  return pendingKeyHashes;
3578
3687
  };
3579
- /* v8 ignore next -- older injected test doubles may omit the catch-up query method */
3580
- if (!client.listRecentMessages)
3581
- return result;
3582
3688
  (0, runtime_1.emitNervesEvent)({
3583
3689
  level: catchUpWindow.mode === "recovery" ? "warn" : "info",
3584
3690
  component: "senses",
@@ -3606,6 +3712,7 @@ async function catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousStat
3606
3712
  catch (error) {
3607
3713
  if (options.lifecycleSignal?.aborted)
3608
3714
  throw options.lifecycleSignal.reason;
3715
+ catchUpQueryFailed = true;
3609
3716
  result.failed++;
3610
3717
  (0, runtime_1.emitNervesEvent)({
3611
3718
  level: "warn",
@@ -3654,6 +3761,7 @@ async function catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousStat
3654
3761
  if (oldestMessageTimestamp <= catchUpSince)
3655
3762
  break;
3656
3763
  if (page === BLUEBUBBLES_CATCHUP_MAX_PAGES - 1) {
3764
+ reachedPageLimit = true;
3657
3765
  result.failed++;
3658
3766
  (0, runtime_1.emitNervesEvent)({
3659
3767
  level: "warn",
@@ -3755,10 +3863,19 @@ async function catchUpMissedBlueBubblesMessagesInScope(scope, deps, previousStat
3755
3863
  }
3756
3864
  }
3757
3865
  }));
3866
+ // The cursor holds only when a query failed, so those arrivals are read again. Any other failure, such as a failed
3867
+ // turn, moves the cursor on but carries the oldest late sent time forward, so the next pass reaches it again. The page
3868
+ // limit alone carries nothing: the next pass would stop at the same limit, so it would only fail every pass for a day.
3869
+ if (!catchUpQueryFailed)
3870
+ result.arrivalCursor = arrivalRead?.cursor;
3871
+ const unfinishedFailures = result.failed - (reachedPageLimit ? 1 : 0);
3872
+ if (unfinishedFailures > 0 && Number.isFinite(unfinishedLateSince))
3873
+ result.lateSince = new Date(unfinishedLateSince).toISOString();
3758
3874
  const foundWork = result.recovered > 0 || (result.queued ?? 0) > 0 || result.failed > 0;
3759
3875
  if (result.inspected > 0 || foundWork || catchUpWindow.mode === "recovery") {
3760
3876
  (0, runtime_1.emitNervesEvent)({
3761
- level: foundWork || catchUpWindow.mode === "recovery" ? catchUpLogLevel : "info",
3877
+ // Work a healthy pass finds is a message the webhook missed, so it is logged like an outage pass's.
3878
+ level: foundWork ? "warn" : catchUpWindow.mode === "recovery" ? catchUpLogLevel : "info",
3762
3879
  component: "senses",
3763
3880
  event: "senses.bluebubbles_catchup_complete",
3764
3881
  message: "bluebubbles upstream catch-up pass completed",
@@ -68,6 +68,10 @@ function readBlueBubblesRuntimeState(agentName, agentRoot) {
68
68
  lastCheckedAt: typeof parsed.lastCheckedAt === "string" ? parsed.lastCheckedAt : undefined,
69
69
  lastHeartbeatAt: typeof parsed.lastHeartbeatAt === "string" ? parsed.lastHeartbeatAt : undefined,
70
70
  catchUpThrough: typeof parsed.catchUpThrough === "string" ? parsed.catchUpThrough : undefined,
71
+ catchUpRowId: typeof parsed.catchUpRowId === "number" && Number.isInteger(parsed.catchUpRowId)
72
+ ? parsed.catchUpRowId
73
+ : undefined,
74
+ catchUpLateSince: typeof parsed.catchUpLateSince === "string" ? parsed.catchUpLateSince : undefined,
71
75
  recoveryLookbackSince: typeof parsed.recoveryLookbackSince === "string" ? parsed.recoveryLookbackSince : undefined,
72
76
  recoveryLookbackUntil: typeof parsed.recoveryLookbackUntil === "string" ? parsed.recoveryLookbackUntil : undefined,
73
77
  proofMethod: typeof parsed.proofMethod === "string" && parsed.proofMethod.trim()
@@ -108,16 +112,24 @@ function readBlueBubblesRuntimeState(agentName, agentRoot) {
108
112
  function writeBlueBubblesRuntimeState(agentName, state, agentRoot) {
109
113
  const filePath = getBlueBubblesRuntimeStatePath(agentName, agentRoot);
110
114
  try {
111
- const kept = state.catchUpThrough === undefined || state.recoveryLookbackUntil === undefined
115
+ const kept = state.catchUpThrough === undefined
116
+ || state.catchUpRowId === undefined
117
+ || state.catchUpLateSince === undefined
118
+ || state.recoveryLookbackUntil === undefined
112
119
  ? readBlueBubblesRuntimeState(agentName, agentRoot)
113
120
  : null;
114
121
  const catchUpThrough = state.catchUpThrough ?? kept?.catchUpThrough;
122
+ const catchUpRowId = state.catchUpRowId ?? kept?.catchUpRowId;
123
+ const catchUpLateSince = state.catchUpLateSince === undefined ? kept?.catchUpLateSince : state.catchUpLateSince;
115
124
  const recoveryLookbackSince = state.recoveryLookbackUntil === undefined ? kept?.recoveryLookbackSince : state.recoveryLookbackSince;
116
125
  const recoveryLookbackUntil = state.recoveryLookbackUntil ?? kept?.recoveryLookbackUntil;
117
126
  // Replaced whole, so the daemon reading it mid-write never sees half a file.
118
127
  (0, atomic_file_1.writeJsonAtomicSync)(filePath, {
119
128
  ...state,
120
129
  ...(catchUpThrough === undefined ? {} : { catchUpThrough }),
130
+ ...(catchUpRowId === undefined ? {} : { catchUpRowId }),
131
+ // Null clears it: an undefined value is left out of the file.
132
+ catchUpLateSince: catchUpLateSince ?? undefined,
121
133
  ...(recoveryLookbackSince === undefined || recoveryLookbackUntil === undefined ? {} : { recoveryLookbackSince, recoveryLookbackUntil }),
122
134
  lastHeartbeatAt: new Date(Date.now()).toISOString(),
123
135
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1707",
3
+ "version": "0.1.0-alpha.1709",
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.1707",
9
+ "version": "0.1.0-alpha.1709",
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.1707",
3
+ "version": "0.1.0-alpha.1709",
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": {