@wirecat/cli-core 0.672.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,28 @@ 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
+
8
30
  ## 0.672.0 — 16.11.2026
9
31
 
10
32
  ### Fixed
@@ -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))
@@ -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.672.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",