@wirecat/cli-core 0.731.0 → 0.732.0

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.md CHANGED
@@ -5,6 +5,18 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.732.0 — 23.11.2026
9
+
10
+ ### Fixed
11
+
12
+ - **A sync keeps the thread replies it read when it is stopped.** A messenger's `threadReplies` may answer in
13
+ batches (an async iterable); `messages sync` saves each one as it comes and moves the thread point only after the
14
+ last, so a stopped or killed sync keeps what it read and the next one reads from the same point. A plain array still
15
+ works.
16
+ - **A failed server search says what the messenger refused, by its keys.** Each `failed` entry carries
17
+ `error: {code, reason?}`, and the note reads `server search incomplete: search_failed (permission_error:
18
+ oauth.scope-missing)`. The provider's own words still stay out.
19
+
8
20
  ## 0.731.0 — 23.11.2026
9
21
 
10
22
  ### Added
@@ -25,6 +25,10 @@ export const noteServer = (context, server) => {
25
25
  return;
26
26
  if (server.skipped)
27
27
  context.renderer.note(`server search skipped: ${server.skipped} — the answer is the archive's`);
28
- else if (!server.complete)
29
- context.renderer.note(`server search incomplete${server.failed.length ? `: ${[...new Set(server.failed.map(({ reason }) => reason))].join(", ")}` : ""}`);
28
+ else if (!server.complete) {
29
+ const reasons = [
30
+ ...new Set(server.failed.map(({ reason, error }) => error ? `${reason} (${[error.code, error.reason].filter(Boolean).join(": ")})` : reason)),
31
+ ];
32
+ context.renderer.note(`server search incomplete${reasons.length ? `: ${reasons.join(", ")}` : ""}`);
33
+ }
30
34
  };
@@ -301,11 +301,12 @@ export interface ThreadReplies {
301
301
  /**
302
302
  * Replies `history` leaves out, such as Slack's thread replies: those sent after `since` (epoch milliseconds, left
303
303
  * out on the chat's first read) to the roots the adapter picks, oldest first. `messages sync` asks after the chat's
304
- * history and saves them without marking a stretch held.
304
+ * history and saves them without marking a stretch held. A chat with many threads answers in batches: each is saved
305
+ * as it comes, so a stopped or killed sync keeps what it read; the next one reads from the same point again.
305
306
  */
306
307
  threadReplies(chatId: Id, window: {
307
308
  since?: number;
308
- }): Promise<Message[]>;
309
+ }): Promise<Message[]> | AsyncIterable<Message[]>;
309
310
  }
310
311
  export interface MessageButtons {
311
312
  /** The keyboard one message carries, row by row; a message without one answers `[]`. */
@@ -437,11 +437,19 @@ const savedReplies = async (connection, store, account, chatId, stop) => {
437
437
  return 0;
438
438
  const startedAt = Date.now();
439
439
  const point = Number((await store.sync.syncState(account, threadsKey(chatId)))?.value);
440
- const replies = await connection.threadReplies(chatId, Number.isFinite(point) ? { since: point } : {});
441
- if (replies.length > 0)
442
- await store.messages.saveMessages(account, chatId, replies, { via: "history", seenAt: startedAt });
440
+ const answer = connection.threadReplies(chatId, Number.isFinite(point) ? { since: point } : {});
441
+ const batches = Symbol.asyncIterator in answer ? answer : [await answer];
442
+ let saved = 0;
443
+ for await (const replies of batches) {
444
+ if (replies.length > 0)
445
+ await store.messages.saveMessages(account, chatId, replies, { via: "history", seenAt: startedAt });
446
+ saved += replies.length;
447
+ // The point moves only once every batch is saved, so a stopped run reads them again.
448
+ if (stop.aborted)
449
+ return saved;
450
+ }
443
451
  await store.sync.setSyncState(account, threadsKey(chatId), String(startedAt));
444
- return replies.length;
452
+ return saved;
445
453
  };
446
454
  /** When the message a held stretch starts at was sent: by time the key is the time; by id, the stored message says. */
447
455
  const timeOfKey = async (store, account, chatId, key, byTime, fallback) => {
@@ -29,6 +29,11 @@ export interface ServerSearched {
29
29
  failed: {
30
30
  chat: string | null;
31
31
  reason: "rate_limited" | "search_failed" | "time_or_abort_bound";
32
+ /** The messenger's error by its keys alone, such as a missing permission: its words may carry private detail. */
33
+ error?: {
34
+ code: string;
35
+ reason?: string;
36
+ };
32
37
  }[];
33
38
  /** Candidates stored from their first `SERVER_BOUNDS.textBytes`, without the attachments; a sync reads them whole. */
34
39
  partial?: number;
@@ -9,6 +9,10 @@ export const SERVER_SEARCH_KEY = "messages.server-search";
9
9
  */
10
10
  export const SERVER_BOUNDS = { timeMs: 5_000, perCall: 100, maxCalls: 3, textBytes: 262_144 };
11
11
  export const DEFAULT_BACKEND = "both";
12
+ const keysOf = (error) => {
13
+ const { reason } = error.details;
14
+ return { code: error.code, ...(typeof reason === "string" ? { reason } : {}) };
15
+ };
12
16
  export const sourceKey = (chatId, id) => JSON.stringify([chatId, id]);
13
17
  const merge = (one, other) => {
14
18
  if (one.chat !== undefined && other.chat !== undefined && one.chat !== other.chat)
@@ -149,10 +153,14 @@ export const searchServer = async (deps, request) => {
149
153
  const pending = new Set(calls);
150
154
  const found = [];
151
155
  let open = true;
152
- const fail = (branch, reason) => {
156
+ const fail = (branch, reason, error) => {
153
157
  pending.delete(branch);
154
158
  report.complete = false;
155
- report.failed.push({ chat: branch.chat ?? null, reason });
159
+ report.failed.push({
160
+ chat: branch.chat ?? null,
161
+ reason,
162
+ ...(error instanceof CliError ? { error: keysOf(error) } : {}),
163
+ });
156
164
  };
157
165
  const ask = async (adapter) => {
158
166
  const search = capability(adapter, "searchMessages", "search messages on its server");
@@ -172,7 +180,7 @@ export const searchServer = async (deps, request) => {
172
180
  catch (error) {
173
181
  if (!open)
174
182
  return;
175
- fail(branch, error instanceof CliError && error.code === "rate_limited" ? "rate_limited" : "search_failed");
183
+ fail(branch, error instanceof CliError && error.code === "rate_limited" ? "rate_limited" : "search_failed", error);
176
184
  }
177
185
  }));
178
186
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.731.0",
3
+ "version": "0.732.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",