@wirecat/cli-core 0.667.0 → 0.669.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/calendar/mcp/index.d.ts +2909 -186
  3. package/dist/calendar/mcp/index.js +20 -7
  4. package/dist/calendar/testing/writer-contract.js +33 -0
  5. package/dist/cli/documents/catalog.js +3 -14
  6. package/dist/cli/documents/sync.d.ts +21 -5
  7. package/dist/cli/documents/sync.js +39 -8
  8. package/dist/cli/documents/testing/source-contract.d.ts +9 -0
  9. package/dist/cli/documents/testing/source-contract.js +12 -0
  10. package/dist/cli/meeting-batch.js +2 -2
  11. package/dist/documents/model.d.ts +4 -0
  12. package/dist/entities/index.d.ts +1 -0
  13. package/dist/errors/reasons.js +1 -0
  14. package/dist/meetings/answers.d.ts +2 -0
  15. package/dist/meetings/answers.js +3 -0
  16. package/dist/meetings/cli/index.d.ts +2 -0
  17. package/dist/meetings/cli/index.js +4 -1
  18. package/dist/meetings/cli/management.d.ts +2 -0
  19. package/dist/meetings/cli/management.js +6 -1
  20. package/dist/meetings/cli/passage.js +2 -2
  21. package/dist/meetings/index.d.ts +2 -2
  22. package/dist/meetings/index.js +2 -2
  23. package/dist/meetings/mcp/passage.js +2 -2
  24. package/dist/meetings/passage.d.ts +5 -0
  25. package/dist/meetings/passage.js +10 -0
  26. package/dist/meetings/read-answers.d.ts +2 -0
  27. package/dist/meetings/read-answers.js +2 -0
  28. package/dist/meetings/read-through.d.ts +1 -1
  29. package/dist/meetings/read-through.js +4 -0
  30. package/dist/meetings/reads.d.ts +3 -17
  31. package/dist/meetings/reads.js +10 -1
  32. package/dist/meetings/store.d.ts +6 -0
  33. package/dist/meetings/store.js +13 -0
  34. package/dist/services/documents/ingestion.d.ts +3 -0
  35. package/dist/services/documents/ingestion.js +9 -2
  36. package/dist/services/documents/plan.d.ts +16 -1
  37. package/dist/services/documents/plan.js +163 -103
  38. package/dist/services/documents/ports.d.ts +13 -0
  39. package/dist/services/documents/sync.d.ts +11 -0
  40. package/dist/services/documents/sync.js +41 -3
  41. package/dist/services/metadata.d.ts +1 -1
  42. package/dist/store/sqlite/catalog.d.ts +2 -1
  43. package/dist/store/sqlite/catalog.js +4 -1
  44. package/dist/store/sqlite/meeting-listing.js +28 -7
  45. package/dist/store/sqlite/note-search.d.ts +10 -1
  46. package/dist/store/sqlite/note-search.js +35 -1
  47. package/package.json +3 -3
@@ -30,7 +30,8 @@ export interface CatalogEntry extends CatalogInput {
30
30
  export declare const CATALOG_QUERY: import("@wirecat/cli-base/query").QueryRegistry;
31
31
  export interface CatalogQuery {
32
32
  ast?: QueryAst;
33
- parent?: string;
33
+ /** A direct parent's external ID, or several: an entry under any of them. */
34
+ parent?: string | string[];
34
35
  kind?: CatalogInput["kind"];
35
36
  mime?: string;
36
37
  search?: string;
@@ -205,7 +205,10 @@ export const catalogStoreOver = ({ database, now }) => {
205
205
  const actorSql = "json_each(d.metadata, '$.catalog.folded.people')";
206
206
  const tagSql = "SELECT 1 FROM taggings g JOIN resolved_tags t ON t.id=g.tag_id WHERE g.taggable_type='document' AND g.taggable_id=d.id AND t.name=?";
207
207
  const tag = (name) => canonicalTagNamed(database, name)?.name ?? normalizeTag(name);
208
- if (query.parent !== undefined)
208
+ // Several parents in one json_each per entry: an OR of one EXISTS each read the entry's parents once per parent.
209
+ if (Array.isArray(query.parent))
210
+ add("EXISTS(SELECT 1 FROM json_each(d.metadata, '$.catalog.parents') WHERE value IN (SELECT value FROM json_each(?)))", JSON.stringify(query.parent.map((parent) => field(parent))));
211
+ else if (query.parent !== undefined)
209
212
  add("EXISTS(SELECT 1 FROM json_each(d.metadata, '$.catalog.parents') WHERE value=?)", query.parent);
210
213
  if (query.kind !== undefined)
211
214
  add("json_extract(d.metadata, '$.catalog.kind')=?", query.kind);
@@ -1,5 +1,5 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { formatMeetingReference, joinKeyOf, MEETING_FINDINGS_KIND, parseMeetingReference, } from "../../meetings/index.js";
2
+ import { formatMeetingReference, joinKeyOf, MEETING_FINDINGS_KIND, parseMeetingReference, TRANSCRIPT_WORDS, } from "../../meetings/index.js";
3
3
  import { fold } from "../normalize.js";
4
4
  import { eventWindow } from "./calendar-events.js";
5
5
  import { COUNTERPART_ROLE, linkKind } from "./link-kinds.js";
@@ -115,6 +115,28 @@ const rowsOf = (context, filter) => {
115
115
  };
116
116
  const ROW_MEETINGS = "r.meetings";
117
117
  const inRowMeetings = (condition) => `EXISTS (SELECT 1 FROM json_each(${ROW_MEETINGS}) rm WHERE ${condition.replaceAll("{m}", "rm.value")})`;
118
+ /** The meeting's own transcript, or a Drive document Meet named as its transcript or Gemini notes, once imported. */
119
+ const MEETING_TRANSCRIPT = `(EXISTS (SELECT 1 FROM meeting_transcripts t WHERE t.meeting_id = {m} AND t.deleted_at IS NULL
120
+ AND t.superseded_at IS NULL)
121
+ OR EXISTS (SELECT 1 FROM links tl JOIN documents td ON td.id = tl.to_id WHERE tl.from_type = 'meeting'
122
+ AND tl.from_id = {m} AND tl.kind = 'attached' AND tl.to_type = 'document' AND tl.role IN ('transcript', 'notes')
123
+ AND td.deleted_at IS NULL))`;
124
+ const literal = (text) => `'${text.replaceAll("'", "''")}'`;
125
+ // LIKE folds ASCII case only, so the lower-cased word also catches a lower-cased Russian title.
126
+ const namedLikeTranscript = (title) => `(${TRANSCRIPT_WORDS.flatMap((word) => [
127
+ `${title} LIKE ${literal(`%${word}%`)}`,
128
+ `instr(${title}, ${literal(word.toLowerCase())}) > 0`,
129
+ ]).join(" OR ")})`;
130
+ /**
131
+ * A calendar entry's attachment carries no role, so an imported Drive document counts by the words drive finds
132
+ * transcripts and Gemini notes by.
133
+ */
134
+ const EVENT_TRANSCRIPT = `EXISTS (SELECT 1 FROM calendar_entries tc JOIN links tl ON tl.from_type = 'calendar_entry'
135
+ AND tl.from_id = tc.id AND tl.kind = 'attached' AND tl.to_type = 'document'
136
+ JOIN documents td ON td.id = tl.to_id WHERE tc.event_id = {e} AND td.deleted_at IS NULL
137
+ AND ${namedLikeTranscript("td.title")})`;
138
+ /** One rule for the row's flag and the `has_transcript` filter. */
139
+ const ROW_TRANSCRIPT = `((r.type = 'event' AND ${EVENT_TRANSCRIPT.replaceAll("{e}", "r.id")}) OR ${inRowMeetings(MEETING_TRANSCRIPT)})`;
118
140
  const PHONE_MEETING = "(SELECT a.provider FROM meetings km JOIN accounts a ON a.id = km.account_id WHERE km.id = {m}) = 'phone'";
119
141
  const KIND = `(CASE
120
142
  WHEN (r.type = 'event' AND EXISTS (SELECT 1 FROM calendar_entries kc WHERE kc.event_id = r.id
@@ -149,8 +171,7 @@ const filtersOf = (database, filter) => {
149
171
  params.push(people, people, people);
150
172
  }
151
173
  if (filter.hasTranscript !== undefined) {
152
- clauses.push(`${filter.hasTranscript ? "" : "NOT "}${inRowMeetings("EXISTS (SELECT 1 FROM meeting_transcripts t WHERE t.meeting_id = {m} AND t.deleted_at IS NULL " +
153
- "AND t.superseded_at IS NULL)")}`);
174
+ clauses.push(`${filter.hasTranscript ? "" : "NOT "}${ROW_TRANSCRIPT}`);
154
175
  }
155
176
  return { sql: clauses.length ? `WHERE ${clauses.join(" AND ")}` : "", params };
156
177
  };
@@ -206,7 +227,8 @@ const hydrate = (database, page) => {
206
227
  const eventIds = page.filter(({ type }) => type === "event").map(({ id }) => id);
207
228
  const meetingIds = [...new Set(page.flatMap(({ meetingIds }) => meetingIds))];
208
229
  const events = new Map(database
209
- .prepare("SELECT * FROM events WHERE id IN (SELECT value FROM json_each(?))")
230
+ .prepare(`SELECT e.*, ${EVENT_TRANSCRIPT.replaceAll("{e}", "e.id")} AS has_transcript FROM events e
231
+ WHERE e.id IN (SELECT value FROM json_each(?))`)
210
232
  .all(ids(eventIds))
211
233
  .map((row) => [Number(row.id), row]));
212
234
  const entries = database
@@ -222,8 +244,7 @@ const hydrate = (database, page) => {
222
244
  .map((row) => [Number(row.id), row.recurrence == null ? null : JSON.parse(String(row.recurrence))]));
223
245
  const meetings = new Map(database
224
246
  .prepare(`SELECT m.*, a.provider, a.external_id AS account,
225
- EXISTS (SELECT 1 FROM meeting_transcripts t WHERE t.meeting_id = m.id AND t.deleted_at IS NULL
226
- AND t.superseded_at IS NULL) AS has_transcript,
247
+ ${MEETING_TRANSCRIPT.replaceAll("{m}", "m.id")} AS has_transcript,
227
248
  EXISTS (SELECT 1 FROM meeting_summaries s WHERE s.meeting_id = m.id) AS has_summary,
228
249
  (EXISTS (SELECT 1 FROM attachments ra WHERE ra.attachable_type = 'meeting' AND ra.attachable_id = m.id
229
250
  AND (ra.kind IN ('audio', 'video') OR ra.mime LIKE 'audio/%' OR ra.mime LIKE 'video/%'))
@@ -358,7 +379,7 @@ const hydrate = (database, page) => {
358
379
  sources,
359
380
  participants: [...participants.values()],
360
381
  hasRecording: held.some((meeting) => Number(meeting.has_recording) === 1),
361
- hasTranscript: held.some((meeting) => Number(meeting.has_transcript) === 1),
382
+ hasTranscript: Number(event?.has_transcript ?? 0) === 1 || held.some((meeting) => Number(meeting.has_transcript) === 1),
362
383
  hasSummary: held.some((meeting) => Number(meeting.has_summary) === 1),
363
384
  documents: [...linked.values()],
364
385
  seriesId: num(event?.event_series_id),
@@ -1,6 +1,6 @@
1
1
  import type { ResolvedNode } from "../../search/lucene/resolved.js";
2
2
  import type { Stemmer } from "../../search/stem.js";
3
- import type { SqlValue } from "../driver.js";
3
+ import { type SqlValue } from "../driver.js";
4
4
  import { type DocumentPictureStore } from "./document-pictures.js";
5
5
  import { type NoteIndexState } from "./note-index.js";
6
6
  import { type Note } from "./notes.js";
@@ -112,6 +112,15 @@ export interface NoteSearch extends DocumentPictureStore {
112
112
  hasMore: boolean;
113
113
  }>;
114
114
  indexState(): Promise<NoteIndexState | undefined>;
115
+ /**
116
+ * Indexes the documents and notes written since the last search, so a reader that cannot write finds them by their
117
+ * words. The queue is the store's own, shared by every tool that writes to it, not only the caller's rows. Works a
118
+ * batch of 50 at a time and yields between batches, so `until` (a deadline, a signal) is asked often; 0 under a
119
+ * read-only store.
120
+ */
121
+ indexWritten(options?: {
122
+ until?: () => boolean;
123
+ }): Promise<number>;
115
124
  /** Live notes' chunks with no vector of `model`, by hash from `after`, each with its text cut again. */
116
125
  chunksToEmbed(model: string, options: {
117
126
  after?: string;
@@ -4,13 +4,14 @@ import { fuseRanked } from "../../search/fusion.js";
4
4
  import { compileAutomaton, foldRegex, wildcardPattern, } from "../../search/lucene/automaton.js";
5
5
  import { isStemmed } from "../../search/lucene/resolved.js";
6
6
  import { exhausted, outOfTime, QUERY_LIMITS, searchError } from "../../search/lucene/types.js";
7
+ import { isQueryOnly } from "../driver.js";
7
8
  import { normalize } from "../normalize.js";
8
9
  import { contextDocumentTime } from "./context-document-source.js";
9
10
  import { documentPicturesOver } from "./document-pictures.js";
10
11
  import { ENRICHMENT_POSITION, enrichmentText } from "./enrichments.js";
11
12
  import { linkKind } from "./link-kinds.js";
12
13
  import { prefixOf } from "./lucene.js";
13
- import { drainNoteIndex, noteIndexState, noteIndexText } from "./note-index.js";
14
+ import { drainCorpus, drainNoteIndex, fillTrigrams, CORPORA as INDEXED, noteIndexState, noteIndexText, } from "./note-index.js";
14
15
  import { documentOf, noteOf } from "./notes.js";
15
16
  import { stemmerCache } from "./stems.js";
16
17
  import { canonicalTagNamed } from "./tags.js";
@@ -336,6 +337,7 @@ export const searchCorpus = (context, query, corpus) => {
336
337
  });
337
338
  };
338
339
  const SCAN_PAGE = 5_000;
340
+ const SETTLE_BATCH = 50;
339
341
  /** The live documents and notes of a chunk scan, narrowed by folder and source. */
340
342
  const LIVE = "((k.chunkable_type = 'document' AND EXISTS (SELECT 1 FROM documents d WHERE d.id = k.chunkable_id AND d.deleted_at IS NULL AND coalesce(json_extract(d.metadata, '$.catalog.active'), 1)=1 " +
341
343
  "AND (? IS NULL OR d.account_id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))))) " +
@@ -367,6 +369,38 @@ export const noteSearchOver = (context) => {
367
369
  return matchingNoteRefs(context, query);
368
370
  },
369
371
  indexState: async () => noteIndexState(database),
372
+ indexWritten: async ({ until = () => false } = {}) => {
373
+ if (isQueryOnly(database))
374
+ return 0;
375
+ // One batch per step: a step's own `until` lets it run once, so every corpus moves on each round.
376
+ const once = () => {
377
+ let ran = false;
378
+ return () => {
379
+ const stop = ran;
380
+ ran = true;
381
+ return stop;
382
+ };
383
+ };
384
+ const steps = [
385
+ () => drainCorpus(database, INDEXED.document, stemmerFor, { batch: SETTLE_BATCH, until: once() }),
386
+ () => drainCorpus(database, INDEXED.note, stemmerFor, { batch: SETTLE_BATCH, until: once() }),
387
+ () => fillTrigrams(database, { batch: SETTLE_BATCH, until: once() }),
388
+ ];
389
+ let total = 0;
390
+ for (;;) {
391
+ let done = 0;
392
+ for (const step of steps) {
393
+ if (until())
394
+ return total;
395
+ done += step();
396
+ }
397
+ total += done;
398
+ if (done === 0)
399
+ return total;
400
+ // A synchronous drain would hide an abort or a timer until it ends.
401
+ await new Promise((resolve) => setImmediate(resolve));
402
+ }
403
+ },
370
404
  chunksToEmbed: async (model, { after, limit }) => {
371
405
  drain();
372
406
  const scope = live(undefined, undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.667.0",
3
+ "version": "0.669.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",
@@ -300,7 +300,7 @@
300
300
  "@types/pngjs": "6.0.5",
301
301
  "@types/ssh2": "1.15.5",
302
302
  "@vitest/coverage-v8": "^5.0.5",
303
- "@wirecat/cli-base": "0.101.0",
303
+ "@wirecat/cli-base": "0.102.1",
304
304
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
305
305
  "ajv": "8.17.1",
306
306
  "commander": "15.0.0",
@@ -324,7 +324,7 @@
324
324
  },
325
325
  "peerDependencies": {
326
326
  "@napi-rs/canvas": ">=0.1.69 <2",
327
- "@wirecat/cli-base": ">=0.101.0 <1.0.0",
327
+ "@wirecat/cli-base": ">=0.102.1 <1.0.0",
328
328
  "commander": ">=15",
329
329
  "mysql2": "^3.24.6",
330
330
  "pg": "^8.23.1",