@wirecat/cli-core 0.671.0 → 0.673.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,40 @@ 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.673.0 — 16.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`DocumentSource.childrenPage(id, cursor?)`, an optional page-at-a-time listing for the documents sync.** A Notion
13
+ database of 12 000 rows and more did not fit in one step, so a first sync over MCP (45 s) never got past it. With
14
+ `childrenPage` the walk lists one page per budget step and saves the next page's cursor in the walk's stack entry
15
+ (`SourceWalk.stack[].listing`), so the next sync goes on mid-folder. A 404 on a later page lists the folder again
16
+ from its first page and drops nothing; only a 404 on the first page is checked with `metadata`. A source without it,
17
+ such as drive, and walks saved before are listed as before. A cursor the provider no longer accepts must fail as
18
+ `not_found`, and a CLI that validates its walk file must keep `listing`. `documentSourceContract` checks the pages against `children()`, and `fakeDocumentSource(account, { pageSize })`
19
+ lists a page at a time. See [Walks over several syncs](docs/dev/DOCUMENTS.md#walks-over-several-syncs).
20
+
21
+ ### Fixed
22
+
23
+ - **A Drive file two Drive profiles imported links to its meeting.** A Meet transcript or "Notes by Gemini" doc shared
24
+ with two Drive profiles is two documents, and its calendar event's or meeting's `attached` link stayed unresolved:
25
+ `search all` showed the meeting and the document apart, and the meetings filter "only with transcript" missed it.
26
+ The link now takes the older of the documents, whichever of Drive or Calendar is saved first, and keeps it when
27
+ either profile imports the file again. See
28
+ [MEETING-PROVIDERS.md](docs/dev/MEETING-PROVIDERS.md#a-meetings-drive-documents).
29
+
30
+ ## 0.672.0 — 16.11.2026
31
+
32
+ ### Fixed
33
+
34
+ - **An option an agent guesses on a search or a message read fails with the form that runs.** `search all`, `search
35
+ messages`, `search notes` and `search conversations` answer `--since`, `--after`, `--until`, `--before` (and
36
+ `--from`, `--to`) with where the date goes (`date>=…` in the query, or `--since-time` and `--filter` for
37
+ conversations), `--around` with `messages context <hit ref> --before-n 5 --after-n 5`, and `--only` with
38
+ `search all … --only`. `messages list`, `show` and `context` answer `--chat` with the chat as the first argument,
39
+ and `context` answers `--before` and `--after` with `--before-n` and `--after-n`. Before, commander said a bare
40
+ "unknown option", or suggested an unrelated near name (`--since` → `--source`); each guess cost an agent a call.
41
+
8
42
  ## 0.671.0 — 15.11.2026
9
43
 
10
44
  ### Changed — may break callers
@@ -111,6 +111,37 @@ export const documentSourceContract = (make) => {
111
111
  assert.ok(named.has(file) || named.has(folder), `the feed names ${file} or its folder ${folder}`);
112
112
  },
113
113
  });
114
+ cases.push({
115
+ name: "childrenPage: the pages of a folder, cursor to cursor, list what children() lists, each entry once",
116
+ async run() {
117
+ const fixture = await make();
118
+ const { source } = fixture;
119
+ if (!source.childrenPage)
120
+ return;
121
+ const stack = [fixture.root];
122
+ while (stack.length) {
123
+ const parent = stack.pop();
124
+ const paged = [];
125
+ let cursor;
126
+ for (let pages = 1;; pages++) {
127
+ assert.ok(pages <= MAX_ENTRIES, `childrenPage(${parent}) ends`);
128
+ const page = await source.childrenPage(parent, cursor);
129
+ assert.ok(Array.isArray(page.files), "a page has files");
130
+ paged.push(...page.files.map((file) => file.id));
131
+ for (const file of page.files)
132
+ if (fixture.isFolder(file))
133
+ stack.push(file.id);
134
+ if (page.cursor === undefined)
135
+ break;
136
+ assert.ok(typeof page.cursor === "string" && page.cursor !== cursor, "a page gives a new cursor or none");
137
+ cursor = page.cursor;
138
+ }
139
+ assert.equal(new Set(paged).size, paged.length, `childrenPage(${parent}) lists each entry once`);
140
+ const listed = (await source.children(parent)).map((file) => file.id);
141
+ assert.deepEqual([...paged].sort(), [...listed].sort(), `childrenPage(${parent}) lists what children() does`);
142
+ }
143
+ },
144
+ });
114
145
  cases.push({
115
146
  name: "metadata: an id the provider does not know is not_found",
116
147
  async run() {
@@ -9,5 +9,10 @@ export interface FakeDocumentSource extends DocumentSource {
9
9
  /** Takes one out, and lists it as removed in the next change feed. */
10
10
  remove(id: string): void;
11
11
  }
12
- /** A provider in memory: a root folder, a nested folder and two text files, with a change feed and a cursor. */
13
- export declare const fakeDocumentSource: (account?: string) => FakeDocumentSource;
12
+ /**
13
+ * A provider in memory: a root folder, a nested folder and two text files, with a change feed and a cursor. With
14
+ * `pageSize` it also lists a folder's children a page at a time through `childrenPage`.
15
+ */
16
+ export declare const fakeDocumentSource: (account?: string, options?: {
17
+ pageSize?: number;
18
+ }) => FakeDocumentSource;
@@ -12,8 +12,11 @@ export const fakeFile = (id, parents = ["root"], mime = "text/plain") => ({
12
12
  version: "1",
13
13
  modifiedAt: "2026-10-16T00:00:00.000Z",
14
14
  });
15
- /** A provider in memory: a root folder, a nested folder and two text files, with a change feed and a cursor. */
16
- export const fakeDocumentSource = (account = "alpha") => {
15
+ /**
16
+ * A provider in memory: a root folder, a nested folder and two text files, with a change feed and a cursor. With
17
+ * `pageSize` it also lists a folder's children a page at a time through `childrenPage`.
18
+ */
19
+ export const fakeDocumentSource = (account = "alpha", options = {}) => {
17
20
  const files = new Map();
18
21
  const texts = new Map();
19
22
  let feed = [];
@@ -24,6 +27,8 @@ export const fakeDocumentSource = (account = "alpha") => {
24
27
  throw new CliError("not_found", "no such synthetic file", { reason: "document.not-found" });
25
28
  return structuredClone(found);
26
29
  };
30
+ const children = async (id) => [...files.values()].filter((item) => item.parents.includes(id)).map((item) => structuredClone(item));
31
+ const { pageSize } = options;
27
32
  const source = {
28
33
  files,
29
34
  put(file, text) {
@@ -39,7 +44,19 @@ export const fakeDocumentSource = (account = "alpha") => {
39
44
  },
40
45
  identity: async () => account,
41
46
  metadata,
42
- children: async (id) => [...files.values()].filter((item) => item.parents.includes(id)).map((item) => structuredClone(item)),
47
+ children,
48
+ ...(pageSize
49
+ ? {
50
+ childrenPage: async (id, cursor) => {
51
+ if (cursor !== undefined && !/^page-\d+$/.test(cursor))
52
+ throw new CliError("validation_error", "unknown synthetic page cursor");
53
+ const from = cursor === undefined ? 0 : Number(cursor.slice("page-".length));
54
+ const all = await children(id);
55
+ const end = from + pageSize;
56
+ return { files: all.slice(from, end), ...(end < all.length ? { cursor: `page-${end}` } : {}) };
57
+ },
58
+ }
59
+ : {}),
43
60
  startToken: async () => `cursor-${cursor}`,
44
61
  changes: async (token) => {
45
62
  if (!/^cursor-\d+$/.test(token))
@@ -12,7 +12,7 @@ import { modelWith, spoken } from "../../speech/hearing.js";
12
12
  import { REMOTE_READ } from "../effects.js";
13
13
  import { itemOf, listOf, renderAnswer } from "../envelope.js";
14
14
  import { queryHelp } from "../list-query.js";
15
- import { withOptionHints } from "../option-hints.js";
15
+ import { AROUND_HINT, END_FLAGS, hintsFor, START_FLAGS, withOptionHints } from "../option-hints.js";
16
16
  import { positiveCount } from "../paging.js";
17
17
  import { marksUntrusted } from "../untrusted-marks.js";
18
18
  import { syncCommand } from "./backfill-command.js";
@@ -101,7 +101,11 @@ export const messagesCommand = (messenger) => {
101
101
  }), () => renderMessages(spokenItems(page.items, hearing), viewOf(context, messenger)));
102
102
  });
103
103
  annotate(list, { output: { entity: "message" }, query: history });
104
- withOptionHints(list, Object.fromEntries(TIME_FLAGS.map((flag) => [flag, `messages list reads a window by its query: '${WINDOW_EXAMPLE}'`])));
104
+ withOptionHints(list, {
105
+ ...hintsFor([...TIME_FLAGS, ...START_FLAGS, ...END_FLAGS], `messages list reads a window by its query: '${WINDOW_EXAMPLE}'`),
106
+ "--chat": CHAT_FIRST("list"),
107
+ "--around": AROUND_HINT,
108
+ });
105
109
  const readWindow = async (command, chat, message, window) => {
106
110
  const context = messengerContext(command, messenger);
107
111
  const { found, reader } = await context.withServices(async (services) => ({
@@ -198,8 +202,18 @@ export const messagesCommand = (messenger) => {
198
202
  messages.addCommand(commentsCommand(messenger));
199
203
  messages.addCommand(linksCommand(messenger));
200
204
  messages.addCommand(syncCommand(messenger));
205
+ for (const name of ["show", "context"]) {
206
+ const command = messages.commands.find((one) => one.name() === name);
207
+ if (command)
208
+ withOptionHints(command, {
209
+ "--chat": CHAT_FIRST(name),
210
+ "--around": name === "show" ? AROUND_HINT : "the window is around the message already; --before-n 5 --after-n 5",
211
+ ...(name === "context" ? { "--before": "--before-n <n>", "--after": "--after-n <n>" } : {}),
212
+ });
213
+ }
201
214
  return hideNever(messenger, messages);
202
215
  };
216
+ const CHAT_FIRST = (name) => `the chat is the first argument: messages ${name} <chat>${name === "list" ? "" : " <message>, or a hit's msg: ref"}`;
203
217
  /** Mail lives in the mail tables of the store, whichever messenger CLI reads it. */
204
218
  const isMailLocator = (chat, message) => message === undefined && isLocator(chat) && parseLocator(chat).provider === "email";
205
219
  const count = (value) => {
@@ -5,7 +5,7 @@ import { SAVE_HELP } from "../../meetings/index.js";
5
5
  import { searchNotesOf } from "../../services/notes-search.js";
6
6
  import { LOCAL_READ, REMOTE_READ } from "../effects.js";
7
7
  import { renderAnswer } from "../envelope.js";
8
- import { withOptionHints } from "../option-hints.js";
8
+ import { AROUND_HINT, END_FLAGS, hintsFor, START_FLAGS, withOptionHints } from "../option-hints.js";
9
9
  import { positiveCount } from "../paging.js";
10
10
  import { runsSearchCommand } from "../runs/search-command.js";
11
11
  import { commandAt } from "../steps.js";
@@ -16,6 +16,7 @@ import { messagesSearchCommand } from "./messages-search-command.js";
16
16
  import { allAnswer, meaningNote, notesAnswer, offsetOf, SOURCE_SEARCHED, shownOf, } from "./search-answers.js";
17
17
  import { backendOptions, backendRequest, noteServer } from "./search-backend-options.js";
18
18
  import { topicsSearchCommand } from "./topics-command.js";
19
+ const ONLY_HINT = "this search reads one kind already; --only belongs to search all: search all 'words' --only messages";
19
20
  export const searchAllOnlyOf = (value, allowed = SOURCE_SEARCHED) => {
20
21
  const chosen = value.split(",").map((one) => one.trim());
21
22
  if (chosen.includes("mail"))
@@ -186,12 +187,28 @@ export const searchCommand = (messenger, { topics = false } = {}) => {
186
187
  if (command)
187
188
  annotate(command, { examples: [`${messenger.app.command} personal search ${path} ${args}`] });
188
189
  }
189
- for (const path of ["all", "messages"]) {
190
+ for (const path of ["all", "messages", "notes"]) {
190
191
  const command = commandAt(search, path);
192
+ const dates = hintsFor([...START_FLAGS, ...END_FLAGS], `put the dates in the query: search ${path} 'words date>=2026-10-01 date<2026-10-20', or 'words date:7d'`);
191
193
  if (command)
192
194
  withOptionHints(command, {
193
- "--chat": `search in one chat with chat:<chat> in the query: search ${path} 'chat:<chat> words'`,
195
+ ...dates,
196
+ ...(path === "notes"
197
+ ? {}
198
+ : {
199
+ "--chat": `search in one chat with chat:<chat> in the query: search ${path} 'chat:<chat> words'`,
200
+ "--around": AROUND_HINT,
201
+ }),
202
+ ...(path === "all" ? {} : { "--only": ONLY_HINT }),
194
203
  });
195
204
  }
205
+ const conversations = commandAt(search, "conversations");
206
+ if (conversations)
207
+ withOptionHints(conversations, {
208
+ ...hintsFor(START_FLAGS, "--since-time 7d, or --since-time 2026-10-01"),
209
+ ...hintsFor(END_FLAGS, "put the end in the filter: --filter 'date<2026-10-20'"),
210
+ "--around": AROUND_HINT,
211
+ "--only": ONLY_HINT,
212
+ });
196
213
  return search;
197
214
  };
@@ -4,3 +4,9 @@ import type { Command } from "commander";
4
4
  * commander's bare "unknown option".
5
5
  */
6
6
  export declare const withOptionHints: (command: Command, hints: Readonly<Record<string, string>>) => Command;
7
+ /** The same hint for each of these flags. */
8
+ export declare const hintsFor: (flags: readonly string[], hint: string) => Record<string, string>;
9
+ /** Date flags agents guess; commander would suggest an unrelated near name (`--since` → `--source`). */
10
+ export declare const START_FLAGS: string[];
11
+ export declare const END_FLAGS: string[];
12
+ export declare const AROUND_HINT: string;
@@ -13,3 +13,10 @@ export const withOptionHints = (command, hints) => {
13
13
  };
14
14
  return command;
15
15
  };
16
+ /** The same hint for each of these flags. */
17
+ export const hintsFor = (flags, hint) => Object.fromEntries(flags.map((flag) => [flag, hint]));
18
+ /** Date flags agents guess; commander would suggest an unrelated near name (`--since` → `--source`). */
19
+ export const START_FLAGS = ["--since", "--after", "--from", "--since-date", "--after-date", "--start"];
20
+ export const END_FLAGS = ["--until", "--before", "--to", "--until-date", "--before-date", "--end"];
21
+ export const AROUND_HINT = "read the messages either side of one: messages context <hit ref> --before-n 5 --after-n 5 " +
22
+ "(or messages context <chat> <message>)";
@@ -35,6 +35,16 @@ export interface DocumentSource<M extends SourceFile = SourceFile> {
35
35
  identity(): Promise<string>;
36
36
  metadata(id: string): Promise<M>;
37
37
  children(id: string): Promise<M[]>;
38
+ /**
39
+ * One page of a folder's children, for a provider whose folder can be too big for one step of a sync (a Notion
40
+ * database of 12,000 rows). A sync with it lists one page per step and saves the cursor between calls. A cursor
41
+ * the provider no longer accepts must fail as `not_found` (through `errorOf`): the sync then lists the folder again
42
+ * from its first page, where any other error fails every later sync on that page until a `--rescan`.
43
+ */
44
+ childrenPage?(id: string, cursor?: string): Promise<{
45
+ files: M[];
46
+ cursor?: string;
47
+ }>;
38
48
  startToken(): Promise<string>;
39
49
  changes(token: string): Promise<{
40
50
  items: SourceChange<M>[];
@@ -90,10 +100,12 @@ export interface PictureWriter {
90
100
  export interface SourceWalk<M extends SourceFile = SourceFile> {
91
101
  scope: string;
92
102
  cursor: string;
103
+ /** `listing`: the cursor of the folder's next page, while a source with `childrenPage` is part way through it. */
93
104
  stack: {
94
105
  id: string;
95
106
  ancestry: string[];
96
107
  folder?: M;
108
+ listing?: string;
97
109
  }[];
98
110
  visited: string[];
99
111
  folders: Record<string, M>;
@@ -53,7 +53,7 @@ export interface EntryAttachment {
53
53
  entryId: number;
54
54
  fileId: string;
55
55
  title: string | null;
56
- /** `null` while no Drive account holds the file, while two do, or while its document is deleted. */
56
+ /** `null` while no Drive account holds the file, or while its document is deleted. */
57
57
  documentId: number | null;
58
58
  }
59
59
  export type EntryKind = "single" | "series" | "occurrence";
@@ -51,7 +51,7 @@ export interface MeetingDocument {
51
51
  fileId: string;
52
52
  role: MeetingDocumentRole;
53
53
  title: string | null;
54
- /** `null` while no Drive account holds the file, while two do (CORE-54), or while its document is deleted. */
54
+ /** `null` while no Drive account holds the file, or while its document is deleted. */
55
55
  documentId: number | null;
56
56
  }
57
57
  export interface ChatInput extends Omit<NewRecord<ChatLine>, "meetingId" | "senderParticipantId"> {
@@ -13,7 +13,7 @@ export interface WalkProgress {
13
13
  folders_left: number;
14
14
  /** Entries the walk has found over every call so far. */
15
15
  entries: number;
16
- /** Folders this call listed: 0 means it moved nothing on. */
16
+ /** Listings this call made (a folder, or one page of it): 0 means it moved nothing on. */
17
17
  listed: number;
18
18
  stopped: WalkStop;
19
19
  }
@@ -169,7 +169,7 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
169
169
  walk.stack.pop();
170
170
  continue;
171
171
  }
172
- // One folder at least per call, so a folder with more children than the bound still gets listed.
172
+ // One listing at least per call, so a folder with more children than the bound still moves on.
173
173
  // The run's own signal too: a cooperative sync is not cut from outside, and a CLI may pass no budget.
174
174
  stopped = options.signal?.aborted
175
175
  ? "cancelled"
@@ -184,14 +184,28 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
184
184
  if (!step.folder)
185
185
  container(folder);
186
186
  let children;
187
+ let more;
187
188
  try {
188
- children = await source.children(folder.id);
189
+ if (source.childrenPage)
190
+ ({ files: children, cursor: more } = await source.childrenPage(folder.id, step.listing));
191
+ else
192
+ children = await source.children(folder.id);
189
193
  }
190
194
  catch (error) {
195
+ if (errorOf(error).code !== "not_found")
196
+ throw error;
197
+ // A later page's 404 can be a cursor the provider no longer knows: the folder is listed again from its first
198
+ // page, which tells a gone folder from a stale cursor, and the files already kept are only kept again.
199
+ if (step.listing !== undefined) {
200
+ delete step.listing;
201
+ spent++;
202
+ listed++;
203
+ continue;
204
+ }
191
205
  // Deleted or unshared since the walk saved it: gone, with what is below it, instead of failing every sync.
192
206
  // A listing's 404 alone can be passing, so the folder is read again and is gone only when that read is a
193
207
  // 404 too or finds it trashed; on any doubt the call fails and the next sync lists it again.
194
- if (errorOf(error).code !== "not_found" || !(await vanished(folder.id)))
208
+ if (!(await vanished(folder.id)))
195
209
  throw error;
196
210
  walk.stack.pop();
197
211
  visited.add(folder.id);
@@ -204,8 +218,6 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
204
218
  spent += 1 + children.length;
205
219
  listed++;
206
220
  walk.discovered += children.length;
207
- walk.stack.pop();
208
- visited.add(folder.id);
209
221
  folders[folder.id] = folder;
210
222
  const nested = [];
211
223
  for (const file of children)
@@ -218,8 +230,14 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
218
230
  }
219
231
  else
220
232
  keep(file);
233
+ walk.stack.pop();
221
234
  for (const entry of nested.reverse())
222
235
  walk.stack.push(entry);
236
+ // A folder with more pages goes back on top with its cursor, above its child folders.
237
+ if (more)
238
+ walk.stack.push({ ...step, folder, listing: more });
239
+ else
240
+ visited.add(folder.id);
223
241
  if (now() - savedAt > SAVE_EVERY_MS)
224
242
  record();
225
243
  }
@@ -17,7 +17,10 @@ export declare const logFileLink: (database: CacheDatabase, now: number, fileId:
17
17
  };
18
18
  /** How an `attached` link names a Drive file it waits for: by its Drive id, since no row may hold it yet. */
19
19
  export declare const driveFileTarget: (fileId: string) => string;
20
- /** The document of the Drive file with this id; `null` when no Drive account holds it, or two do. */
20
+ /**
21
+ * The document of the Drive file with this id; `null` when no Drive account holds it. A file two Drive profiles hold
22
+ * (one shared with both) is the oldest document: it stays the same whichever profile imports again.
23
+ */
21
24
  export declare const driveDocumentOf: (database: CacheDatabase, fileId: string) => number | null;
22
25
  /**
23
26
  * Writes the `files` row of one document from the document as it is now: the document's source record. A documents
@@ -51,13 +51,16 @@ export const logFileLink = (database, now, fileId, from, to, method = "import",
51
51
  .run(fileId, from == null ? null : Number(from), to, method, author, now);
52
52
  /** How an `attached` link names a Drive file it waits for: by its Drive id, since no row may hold it yet. */
53
53
  export const driveFileTarget = (fileId) => `google-drive:${fileId}`;
54
- /** The document of the Drive file with this id; `null` when no Drive account holds it, or two do. */
54
+ /**
55
+ * The document of the Drive file with this id; `null` when no Drive account holds it. A file two Drive profiles hold
56
+ * (one shared with both) is the oldest document: it stays the same whichever profile imports again.
57
+ */
55
58
  export const driveDocumentOf = (database, fileId) => {
56
- const rows = database
57
- .prepare("SELECT DISTINCT f.document_id AS id FROM files f JOIN accounts a ON a.id = f.account_id WHERE a.provider = 'google-drive' " +
58
- "AND f.external_id = ? AND f.deleted_at IS NULL AND f.document_id IS NOT NULL LIMIT 2")
59
- .all(fileId);
60
- return rows.length === 1 ? Number(rows[0]?.id) : null;
59
+ const row = database
60
+ .prepare("SELECT MIN(f.document_id) AS id FROM files f JOIN accounts a ON a.id = f.account_id " +
61
+ "WHERE a.provider = 'google-drive' AND f.external_id = ? AND f.deleted_at IS NULL AND f.document_id IS NOT NULL")
62
+ .get(fileId);
63
+ return row?.id == null ? null : Number(row.id);
61
64
  };
62
65
  /** Calendar entries that named this Drive file before Drive stored it now link its document. */
63
66
  const linkAttached = (database, now, fileId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.671.0",
3
+ "version": "0.673.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",