@wirecat/cli-core 0.662.0 → 0.663.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 (173) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/calendar/cli/bodies.js +2 -1
  4. package/dist/calendar/cli/index.js +13 -10
  5. package/dist/calendar/mcp/index.d.ts +3 -1
  6. package/dist/calendar/mcp/index.js +4 -4
  7. package/dist/cli/call-stats-command.d.ts +18 -0
  8. package/dist/cli/call-stats-command.js +52 -0
  9. package/dist/cli/contract-templates.js +2 -0
  10. package/dist/cli/envelope.d.ts +0 -5
  11. package/dist/cli/envelope.js +25 -0
  12. package/dist/cli/index.d.ts +2 -1
  13. package/dist/cli/index.js +2 -1
  14. package/dist/cli/meeting-batch.d.ts +2 -1
  15. package/dist/cli/meeting-batch.js +7 -5
  16. package/dist/cli/meeting-preparation-command.js +5 -5
  17. package/dist/cli/meeting-preparation-read.d.ts +5 -5
  18. package/dist/cli/meeting-preparation-read.js +13 -21
  19. package/dist/cli/meeting-series-inventory-command.js +2 -2
  20. package/dist/cli/meeting-series-inventory-read.d.ts +2 -2
  21. package/dist/cli/meeting-series-inventory-read.js +7 -15
  22. package/dist/cli/messenger/admin-statistics-command.js +2 -2
  23. package/dist/cli/messenger/counters-command.js +2 -2
  24. package/dist/cli/messenger/media-archive-command.js +5 -4
  25. package/dist/cli/messenger/media-archive-move-command.js +1 -1
  26. package/dist/cli/messenger/media-archive-timer-command.js +5 -4
  27. package/dist/cli/messenger/metadata-command.js +3 -3
  28. package/dist/cli/messenger/rankings-command.js +3 -3
  29. package/dist/cli/messenger/tags-command.js +7 -2
  30. package/dist/cli/messenger/tasks-command.js +2 -2
  31. package/dist/cli/paging.d.ts +10 -0
  32. package/dist/cli/paging.js +29 -0
  33. package/dist/cli/runs/command.js +6 -4
  34. package/dist/cli/runs/search-command.js +9 -5
  35. package/dist/cli/schedule/schedule-command.js +1 -5
  36. package/dist/domain/moment.d.ts +29 -0
  37. package/dist/domain/moment.js +58 -0
  38. package/dist/domain/providers.d.ts +6 -4
  39. package/dist/domain/providers.js +10 -5
  40. package/dist/domain/send-time.d.ts +3 -4
  41. package/dist/domain/send-time.js +10 -24
  42. package/dist/entities/fields.d.ts +2 -2
  43. package/dist/entities/fields.js +2 -2
  44. package/dist/entities/index.d.ts +92 -1
  45. package/dist/entities/index.js +3 -2
  46. package/dist/entities/meeting.d.ts +1 -1
  47. package/dist/entities/meeting.js +1 -1
  48. package/dist/errors/reasons.js +0 -1
  49. package/dist/mail/cli/index.js +4 -2
  50. package/dist/mail/facts.d.ts +5 -2
  51. package/dist/mail/facts.js +6 -3
  52. package/dist/mail/index.d.ts +1 -1
  53. package/dist/mail/meeting-notes.js +1 -1
  54. package/dist/mail/probe.d.ts +5 -2
  55. package/dist/mail/probe.js +9 -5
  56. package/dist/mail/server-search.js +1 -1
  57. package/dist/mail/sync.js +1 -1
  58. package/dist/mcp/meeting-preparation.js +1 -1
  59. package/dist/mcp/meeting-series-inventory.js +1 -1
  60. package/dist/mcp/prompts.js +6 -9
  61. package/dist/meetings/call-answers.d.ts +106 -0
  62. package/dist/meetings/call-answers.js +171 -0
  63. package/dist/meetings/call-stats.d.ts +121 -0
  64. package/dist/meetings/call-stats.js +211 -0
  65. package/dist/meetings/calls.d.ts +76 -0
  66. package/dist/meetings/calls.js +78 -0
  67. package/dist/meetings/cli/index.d.ts +8 -0
  68. package/dist/meetings/cli/index.js +10 -22
  69. package/dist/meetings/cli/search.d.ts +9 -2
  70. package/dist/meetings/cli/search.js +16 -26
  71. package/dist/meetings/index.d.ts +3 -0
  72. package/dist/meetings/index.js +3 -0
  73. package/dist/meetings/mcp/index.d.ts +6 -3
  74. package/dist/meetings/mcp/index.js +2 -4
  75. package/dist/meetings/mcp/search.d.ts +6 -1
  76. package/dist/meetings/mcp/search.js +3 -3
  77. package/dist/meetings/read-through.d.ts +2 -1
  78. package/dist/meetings/read-through.js +10 -1
  79. package/dist/meetings/stats.d.ts +3 -0
  80. package/dist/meetings/stats.js +3 -3
  81. package/dist/meetings/testing/index.d.ts +1 -0
  82. package/dist/meetings/testing/index.js +1 -0
  83. package/dist/meetings/testing/paging.d.ts +6 -0
  84. package/dist/meetings/testing/paging.js +5 -0
  85. package/dist/moderation/rules.d.ts +2 -0
  86. package/dist/moderation/rules.js +16 -2
  87. package/dist/search/fusion.d.ts +17 -0
  88. package/dist/search/fusion.js +17 -0
  89. package/dist/search/lucene/resolved.d.ts +2 -0
  90. package/dist/search/question-plan.d.ts +2 -0
  91. package/dist/search/question-plan.js +5 -0
  92. package/dist/search/service-query.d.ts +6 -1
  93. package/dist/search/service-query.js +9 -1
  94. package/dist/services/agenda-mail.js +2 -1
  95. package/dist/services/agenda.js +5 -3
  96. package/dist/services/attachments.js +4 -2
  97. package/dist/services/call-stats.d.ts +17 -0
  98. package/dist/services/call-stats.js +41 -0
  99. package/dist/services/chats.js +4 -2
  100. package/dist/services/conversations.js +4 -2
  101. package/dist/services/deps.d.ts +1 -1
  102. package/dist/services/document-source.d.ts +1 -1
  103. package/dist/services/document-source.js +4 -3
  104. package/dist/services/documents/ingestion.js +11 -40
  105. package/dist/services/documents/plan.d.ts +1 -1
  106. package/dist/services/documents/plan.js +30 -17
  107. package/dist/services/documents/ports.d.ts +5 -0
  108. package/dist/services/documents/sync.js +1 -1
  109. package/dist/services/embeddings-search.js +20 -4
  110. package/dist/services/events-search.js +2 -1
  111. package/dist/services/index.d.ts +1 -0
  112. package/dist/services/index.js +1 -0
  113. package/dist/services/mail-search.d.ts +1 -1
  114. package/dist/services/mail-search.js +10 -11
  115. package/dist/services/media-archive-move.js +2 -4
  116. package/dist/services/media-archive.d.ts +0 -1
  117. package/dist/services/media-archive.js +2 -12
  118. package/dist/services/meeting-combined.js +1 -1
  119. package/dist/services/messages-combined.js +15 -4
  120. package/dist/services/moderation.js +10 -2
  121. package/dist/services/moment.d.ts +4 -10
  122. package/dist/services/moment.js +16 -44
  123. package/dist/services/notes-search.d.ts +0 -2
  124. package/dist/services/notes-search.js +1 -2
  125. package/dist/services/search-all.js +2 -1
  126. package/dist/services/tags.js +4 -2
  127. package/dist/services/task-stats.js +2 -2
  128. package/dist/services/tasks.js +2 -2
  129. package/dist/store/accounts.js +2 -1
  130. package/dist/store/sqlite/account-purge.d.ts +3 -0
  131. package/dist/store/sqlite/account-purge.js +143 -0
  132. package/dist/store/sqlite/accounts.d.ts +0 -2
  133. package/dist/store/sqlite/accounts.js +2 -134
  134. package/dist/store/sqlite/calendar.d.ts +1 -0
  135. package/dist/store/sqlite/calendar.js +5 -5
  136. package/dist/store/sqlite/catalog.js +2 -16
  137. package/dist/store/sqlite/chats.js +2 -1
  138. package/dist/store/sqlite/context-document-source.d.ts +3 -3
  139. package/dist/store/sqlite/context-document-source.js +9 -7
  140. package/dist/store/sqlite/context-evidence.js +9 -3
  141. package/dist/store/sqlite/document-listing.js +2 -1
  142. package/dist/store/sqlite/events.js +2 -1
  143. package/dist/store/sqlite/file-note.d.ts +6 -0
  144. package/dist/store/sqlite/file-note.js +15 -0
  145. package/dist/store/sqlite/files.d.ts +3 -2
  146. package/dist/store/sqlite/files.js +5 -3
  147. package/dist/store/sqlite/identities.js +2 -1
  148. package/dist/store/sqlite/imported-documents.js +2 -2
  149. package/dist/store/sqlite/knowledge.js +19 -19
  150. package/dist/store/sqlite/lucene-fields.js +8 -12
  151. package/dist/store/sqlite/mail-rules.js +2 -1
  152. package/dist/store/sqlite/meeting-calls.d.ts +4 -0
  153. package/dist/store/sqlite/meeting-calls.js +66 -0
  154. package/dist/store/sqlite/meetings.d.ts +2 -2
  155. package/dist/store/sqlite/meetings.js +4 -1
  156. package/dist/store/sqlite/mention-sources.js +2 -1
  157. package/dist/store/sqlite/mentions.js +2 -2
  158. package/dist/store/sqlite/messages.js +6 -1
  159. package/dist/store/sqlite/note-search.js +8 -11
  160. package/dist/store/sqlite/notes.d.ts +2 -0
  161. package/dist/store/sqlite/notes.js +24 -13
  162. package/dist/store/sqlite/organizations.js +2 -2
  163. package/dist/store/sqlite/people-list.js +3 -3
  164. package/dist/store/sqlite/query-filter.d.ts +3 -3
  165. package/dist/store/sqlite/query-filter.js +3 -3
  166. package/dist/store/sqlite/reads.d.ts +4 -4
  167. package/dist/store/sqlite/reads.js +4 -4
  168. package/dist/store/sqlite/search.js +11 -7
  169. package/dist/store/sqlite/test-accounts.js +1 -1
  170. package/dist/store/sqlite/trigram-match.d.ts +9 -0
  171. package/dist/store/sqlite/trigram-match.js +28 -0
  172. package/dist/store/sqlite/work-tasks.js +1 -1
  173. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { MAX_TEXT_CHARS } from "../../attachments/limits.js";
3
3
  import { googleDocumentLinks } from "../../domain/google-documents.js";
4
- import { ADDED_PROVIDER, DOCUMENT_ACCOUNT_PROVIDERS, filesAccountSql, folderProviderOf, folderProviderSql, isDocumentAccountProvider, notAdded, } from "../../domain/providers.js";
4
+ import { ADDED_PROVIDER, documentAccountProviders, filesAccountSql, folderProviderOf, folderProviderSql, isDocumentAccountProvider, notAdded, } from "../../domain/providers.js";
5
5
  import { parseReference } from "../../domain/references.js";
6
6
  import { isRelationKind } from "../../domain/relations.js";
7
7
  import { normalizeTag } from "../../domain/tags.js";
@@ -11,6 +11,7 @@ import { ulid } from "../ulid.js";
11
11
  import { ownerPerson } from "./actors.js";
12
12
  import { encodeDocumentMetadata, languageOf } from "./document-metadata.js";
13
13
  import { deleteDocumentRow, forgetEvidenceToRow } from "./evidence-signature.js";
14
+ import { fileNoteRow } from "./file-note.js";
14
15
  import { PREFERRED_FILE, syncFile } from "./files.js";
15
16
  import { importedDocumentWhere } from "./imported-documents.js";
16
17
  import { LINK_KINDS, LINK_ORIGINS, linkKind, RELATION_KINDS } from "./link-kinds.js";
@@ -24,6 +25,7 @@ import { addTags, ensureTag, labelsOf } from "./tags.js";
24
25
  import { oneOf, textOf } from "./text-input.js";
25
26
  import { thingOf } from "./things.js";
26
27
  import { write } from "./transaction.js";
28
+ import { trigramPart } from "./trigram-match.js";
27
29
  export const NOTE_FORMATS = ["obsidian", "markdown"];
28
30
  export { LINK_ORIGINS } from "./link-kinds.js";
29
31
  const RELATIONSHIPS = RELATION_KINDS.map(linkKind).join(", ");
@@ -95,7 +97,7 @@ const personsNamed = (database, key) => {
95
97
  const rows = database
96
98
  .prepare("SELECT i.name, i.username, il.person_id FROM identities_fts f JOIN identities i ON i.id = f.rowid " +
97
99
  "JOIN identity_links il ON il.identity_id = i.id WHERE identities_fts MATCH ?")
98
- .all(`"${key.replaceAll('"', '""')}"`);
100
+ .all(trigramPart(key));
99
101
  for (const row of rows) {
100
102
  const names = [row.name, row.username].filter((one) => one != null).map((one) => targetKey(String(one)));
101
103
  if (names.includes(key))
@@ -278,13 +280,14 @@ export const notesStoreOver = (context) => {
278
280
  const isLocal = (accountId) => database
279
281
  .prepare(`SELECT 1 FROM accounts WHERE id = ? AND provider IN ('local', 'obsidian')`)
280
282
  .get(Number(accountId)) !== undefined;
281
- /** Drive's documents are found by its folder and `<id>.md`, whichever account that folder is now. */
282
- const remoteDocument = (row) => {
283
- const front = frontMatterObject(row.front_matter);
284
- return front?.source === "google-drive" || frontMatterObject(row.metadata)?.catalog !== undefined;
285
- };
286
- /** Drive's own saves keep their documents by folder and `<id>.md`; only files on disk join by content. */
287
- const localSave = (folder, frontMatter) => isLocal(folder) && frontMatter?.source !== "google-drive";
283
+ /**
284
+ * A documents provider's documents (their front matter's `source` names it) are found by their account and
285
+ * `<id>.md`, whichever account holds them now.
286
+ */
287
+ const remoteDocument = (row) => isDocumentAccountProvider(frontMatterObject(row.front_matter)?.source) ||
288
+ frontMatterObject(row.metadata)?.catalog !== undefined;
289
+ /** A documents provider's own saves keep their documents by account and `<id>.md`; only files on disk join by content. */
290
+ const localSave = (folder, frontMatter) => isLocal(folder) && !isDocumentAccountProvider(frontMatter?.source);
288
291
  /**
289
292
  * The documents whose shown file has this content: live ones, else gone ones no file holds any more, so a file
290
293
  * moved to another folder is the same document whichever folder syncs first. Empty text matches nothing.
@@ -362,10 +365,13 @@ export const notesStoreOver = (context) => {
362
365
  .run(provider, textOf(account, "an account's id", 200), JSON.stringify({ format: "markdown" }), at, at);
363
366
  return folderOf(find());
364
367
  },
365
- documentsAccounts: async () => database
366
- .prepare(`SELECT * FROM accounts WHERE provider IN (${DOCUMENT_ACCOUNT_PROVIDERS.map(() => "?").join(", ")}) ORDER BY provider, external_id`)
367
- .all(...DOCUMENT_ACCOUNT_PROVIDERS)
368
- .map(folderOf),
368
+ documentsAccounts: async () => {
369
+ const providers = documentAccountProviders();
370
+ return database
371
+ .prepare(`SELECT * FROM accounts WHERE provider IN (${providers.map(() => "?").join(", ") || "NULL"}) ORDER BY provider, external_id`)
372
+ .all(...providers)
373
+ .map(folderOf);
374
+ },
369
375
  saveFileNote: async (input) => write(database, () => {
370
376
  const folder = Number(folderRow(input.folderId, true).id);
371
377
  const path = textOf(input.path, "a note's path", 4096);
@@ -536,6 +542,11 @@ export const notesStoreOver = (context) => {
536
542
  return parsed.type === "note" || parsed.type === "document" ? noteRowOf(database, reference) : undefined;
537
543
  },
538
544
  noteReferences: async (reference) => [anyNote(reference).ref],
545
+ fileNote: async (folderId, path) => {
546
+ const folder = Number(folderRow(folderId).id);
547
+ const row = fileNoteRow(database, folder, isLocal(folder), path);
548
+ return row ? documentOf(row) : undefined;
549
+ },
539
550
  notes: async (options = {}) => {
540
551
  const { limit, offset } = bounded(options.limit, options.offset);
541
552
  if (options.source !== undefined)
@@ -1,5 +1,5 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { evaluate, walkQuery } from "@wirecat/cli-base/query";
2
+ import { evaluate, timezoneOf, walkQuery } from "@wirecat/cli-base/query";
3
3
  import { ORGANIZATIONS_QUERY } from "../knowledge-query.js";
4
4
  import { categorySql } from "./organization-categories.js";
5
5
  import { queryFilter } from "./query-filter.js";
@@ -31,7 +31,7 @@ export const organizationsStoreOver = ({ database, now }) => ({
31
31
  kind: { type: "enum", sql: "kind" },
32
32
  scope: { type: "enum", sql: "scope" },
33
33
  created_at: { type: "time", sql: "created_at" },
34
- });
34
+ }, { zone: timezoneOf() });
35
35
  return database
36
36
  .prepare(`SELECT * FROM organizations o WHERE deleted_at IS NULL${where ? ` AND (${where.sql})` : ""}${inCategory} ` +
37
37
  "ORDER BY name, id LIMIT 500")
@@ -10,9 +10,9 @@ import { ALWAYS_SHOWN, shownReasons } from "./person-ties.js";
10
10
  import { mergedAssignees } from "./task-board.js";
11
11
  import { hiddenTestPeople } from "./test-people.js";
12
12
  import { read, writeBatch } from "./transaction.js";
13
+ import { trigramPart } from "./trigram-match.js";
13
14
  export const PEOPLE_SORTS = ["interactions", "recent", "name", "tasks"];
14
15
  const MIN_QUERY = 3;
15
- const ftsPhrase = (text) => `"${text.replaceAll('"', '""')}"`;
16
16
  const matching = (query) => {
17
17
  if (query === undefined)
18
18
  return { sql: "", params: [] };
@@ -27,7 +27,7 @@ const matching = (query) => {
27
27
  "(SELECT rowid FROM identities_fts WHERE identities_fts MATCH ?)) OR " +
28
28
  forms.map(() => "p.name LIKE ? ESCAPE '\\'").join(" OR ") +
29
29
  ")",
30
- params: [forms.map(ftsPhrase).join(" OR "), ...forms.map(like)],
30
+ params: [forms.map(trigramPart).join(" OR "), ...forms.map(like)],
31
31
  };
32
32
  };
33
33
  const TASK_COUNTS = "WITH merged AS (SELECT json_extract(value, '$[0]') AS id, json_extract(value, '$[1]') AS now FROM json_each(?)) " +
@@ -440,7 +440,7 @@ export const similarPeople = (database, typed, limit) => {
440
440
  ? database
441
441
  .prepare("SELECT l.person_id AS person, i.name, i.username FROM identities_fts f JOIN identities i ON i.id = f.rowid " +
442
442
  "JOIN identity_links l ON l.identity_id = i.id WHERE identities_fts MATCH ?")
443
- .all(spellings(longest).map(ftsPhrase).join(" OR "))
443
+ .all(spellings(longest).map(trigramPart).join(" OR "))
444
444
  : database
445
445
  .prepare("SELECT l.person_id AS person, i.name, i.username FROM identities i " +
446
446
  "JOIN identity_links l ON l.identity_id = i.id WHERE i.name_folded LIKE ? ESCAPE '\\'")
@@ -21,8 +21,8 @@ export type ColumnMap = Readonly<Record<string, {
21
21
  where: (node: Predicate) => Where;
22
22
  }>>;
23
23
  export interface FilterOptions extends QueryContext {
24
- /** Where `today` and a bare date start; the machine's zone when absent, as search reads them. */
25
- zone?: string;
24
+ /** Where `today`, a bare date and a time without an offset are read: the zone the answer reports. Never a default. */
25
+ zone: string;
26
26
  now?: number;
27
27
  }
28
28
  /** A folded text column read by its words: each word of a term, or a whole phrase, is found inside it; a pattern matches it whole. */
@@ -34,6 +34,6 @@ export declare const foldedWords: (column: string) => {
34
34
  * and ref compare without case (a `folded` column for names in any script), a lone NOT means everything else, and a
35
35
  * `should` clause counts only when nothing is required.
36
36
  */
37
- export declare const queryFilter: (ast: QueryAst, columns: ColumnMap, options?: FilterOptions) => Where;
37
+ export declare const queryFilter: (ast: QueryAst, columns: ColumnMap, options: FilterOptions) => Where;
38
38
  /** The SQL a list query compiled to, with its values bound, for a Drizzle `where`. */
39
39
  export declare const bound: ({ sql: text, params }: Where) => SQL;
@@ -1,4 +1,4 @@
1
- import { dateRange, queryError, timezoneOf, } from "@wirecat/cli-base/query";
1
+ import { dateRange, queryError, } from "@wirecat/cli-base/query";
2
2
  import { fold } from "../normalize.js";
3
3
  import { sql } from "./drizzle/core.js";
4
4
  /** A wildcard term as a GLOB pattern: `\x` is a literal x, and a literal `*`, `?` or `[` is bracketed. */
@@ -53,7 +53,7 @@ const leaf = (node, columns, options) => {
53
53
  const range = node.operator === "range"
54
54
  ? [node.value, node.upper ?? "*", node.lower_inclusive ?? true, node.upper_inclusive ?? true]
55
55
  : [node.value, node.value, true, true];
56
- const { lower, upper, lower_inclusive, upper_inclusive } = dateRange(range[0], range[1], range[2], range[3], timezoneOf(options.zone), node.span, options.now);
56
+ const { lower, upper, lower_inclusive, upper_inclusive } = dateRange(range[0], range[1], range[2], range[3], options.zone, node.span, options.now);
57
57
  return all([
58
58
  { sql: `${sql} IS NOT NULL`, params: [] },
59
59
  ...(lower === undefined ? [] : [{ sql: `${sql} ${lower_inclusive ? ">=" : ">"} ?`, params: [lower] }]),
@@ -97,6 +97,6 @@ const compile = (node, columns, options) => {
97
97
  * and ref compare without case (a `folded` column for names in any script), a lone NOT means everything else, and a
98
98
  * `should` clause counts only when nothing is required.
99
99
  */
100
- export const queryFilter = (ast, columns, options = {}) => compile(ast.root, columns, options);
100
+ export const queryFilter = (ast, columns, options) => compile(ast.root, columns, options);
101
101
  /** The SQL a list query compiled to, with its values bound, for a Drizzle `where`. */
102
102
  export const bound = ({ sql: text, params }) => sql.join(text.split("?").map((part, at) => (at < params.length ? sql `${sql.raw(part)}${params[at]}` : sql.raw(part))), sql ``);
@@ -884,10 +884,10 @@ export declare const before: (sentAt: number, pk: number) => SQL<unknown>;
884
884
  export declare const toMessages: ({ orm }: StoreContext, rows: MessageRow[]) => Message[];
885
885
  export declare const countMessages: ({ orm }: StoreContext, chatKey: number, since: string | undefined, until?: string) => number;
886
886
  /**
887
- * What changed in a chat after `at`, a time on this machine's clock: messages first saved or edited
888
- * since, oldest first, and the ids deleted since. Send time cannot answer it — an edit made today to
889
- * a message from last year was sent last year. A change to reactions alone leaves no time, so it is
890
- * not here.
887
+ * What changed in a chat after `at`, a time on this machine's clock: messages first saved, brought back
888
+ * after a deletion or edited since, oldest first, and the ids deleted since. Send time cannot answer it —
889
+ * an edit made today to a message from last year was sent last year. A change to reactions alone leaves
890
+ * no time, so it is not here.
891
891
  */
892
892
  export declare const changesSince: (context: StoreContext, chatKey: number, at: number) => {
893
893
  messages: Message[];
@@ -57,10 +57,10 @@ export const countMessages = ({ orm }, chatKey, since, until) => Number(orm
57
57
  .where(live(chatKey, since === undefined ? undefined : gte(messages.sentAt, toMs(since)), until === undefined ? undefined : lte(messages.sentAt, toMs(until))))
58
58
  .get()?.n);
59
59
  /**
60
- * What changed in a chat after `at`, a time on this machine's clock: messages first saved or edited
61
- * since, oldest first, and the ids deleted since. Send time cannot answer it — an edit made today to
62
- * a message from last year was sent last year. A change to reactions alone leaves no time, so it is
63
- * not here.
60
+ * What changed in a chat after `at`, a time on this machine's clock: messages first saved, brought back
61
+ * after a deletion or edited since, oldest first, and the ids deleted since. Send time cannot answer it —
62
+ * an edit made today to a message from last year was sent last year. A change to reactions alone leaves
63
+ * no time, so it is not here.
64
64
  */
65
65
  export const changesSince = (context, chatKey, at) => {
66
66
  const edited = context.orm
@@ -4,18 +4,24 @@ import { exhausted, QUERY_LIMITS } from "../../search/lucene/types.js";
4
4
  import { alias, and, desc, eq, inArray, isNull, lte, sql } from "./drizzle/core.js";
5
5
  import { MESSAGE_FIELDS, newestFirst, toMessages } from "./reads.js";
6
6
  import { accounts, chats, identities, messages } from "./schema.js";
7
+ import { anyCaseGlob, trigramPart } from "./trigram-match.js";
7
8
  const HIT_FIELDS = {
8
9
  ...MESSAGE_FIELDS,
9
10
  chatTitle: sql `${chats.title}`.as("chat_title"),
10
11
  provider: sql `${accounts.provider}`.as("provider"),
11
12
  accountNativeId: sql `${accounts.externalId}`.as("account_native_id"),
12
13
  };
13
- /** Every word of three characters or more, found anywhere inside the text; a trigram index cannot match a shorter one. */
14
+ /**
15
+ * Every word of three characters or more through the trigram index, found anywhere inside the text; a shorter word,
16
+ * which a trigram cannot match, is checked on those messages' text.
17
+ */
14
18
  const wordsOf = (text) => {
15
- const words = (text.match(/[\p{L}\p{N}]+/gu) ?? []).filter((word) => [...word].length >= 3);
16
- if (words.length === 0)
19
+ const words = text.match(/[\p{L}\p{N}]+/gu) ?? [];
20
+ const long = words.filter((word) => [...word].length >= 3);
21
+ if (long.length === 0)
17
22
  throw new CliError("validation_error", "search needs a word of three letters or more");
18
- return words.map((word) => `"${word}"`).join(" ");
23
+ const short = words.filter((word) => [...word].length < 3);
24
+ return and(sql `${messages.id} IN (SELECT rowid FROM messages_fts WHERE messages_fts MATCH ${long.map(trigramPart).join(" AND ")})`, ...short.map((word) => sql `${messages.text} GLOB ${anyCaseGlob(word)}`));
19
25
  };
20
26
  /** What `find` keeps, as one condition. */
21
27
  export const matching = (context, { provider, account, accounts: within, senders, together = false, text, chatId }) => {
@@ -33,9 +39,7 @@ export const matching = (context, { provider, account, accounts: within, senders
33
39
  throw new CliError("validation_error", "a read across accounts names their provider");
34
40
  }
35
41
  const ids = senders?.length ? [...new Set(senders)] : undefined;
36
- return and(isNull(messages.deletedAt), trimmed
37
- ? sql `${messages.id} IN (SELECT rowid FROM messages_fts WHERE messages_fts MATCH ${wordsOf(trimmed)})`
38
- : undefined, scopeProvider === undefined ? undefined : eq(accounts.provider, scopeProvider), account ? eq(accounts.externalId, account.account) : undefined, within ? inArray(accounts.externalId, within) : undefined, chatId === undefined ? eq(chats.searchable, 1) : eq(chats.externalId, chatId), ids ? and(eq(identities.provider, accounts.provider), inArray(identities.externalId, ids)) : undefined, ids && together ? inArray(messages.chatId, everyoneWrote(context, ids, scopeProvider)) : undefined);
42
+ return and(isNull(messages.deletedAt), trimmed ? wordsOf(trimmed) : undefined, scopeProvider === undefined ? undefined : eq(accounts.provider, scopeProvider), account ? eq(accounts.externalId, account.account) : undefined, within ? inArray(accounts.externalId, within) : undefined, chatId === undefined ? eq(chats.searchable, 1) : eq(chats.externalId, chatId), ids ? and(eq(identities.provider, accounts.provider), inArray(identities.externalId, ids)) : undefined, ids && together ? inArray(messages.chatId, everyoneWrote(context, ids, scopeProvider)) : undefined);
39
43
  };
40
44
  /** The chats where every one of `ids` has a message — the outer row's provider when no scope names one. */
41
45
  const everyoneWrote = ({ orm }, ids, scopeProvider) => {
@@ -1,4 +1,4 @@
1
- import { purgeAccount } from "./accounts.js";
1
+ import { purgeAccount } from "./account-purge.js";
2
2
  import { write } from "./transaction.js";
3
3
  /** Set by store version 48 and deleted once the purge ran. */
4
4
  export const TEST_ACCOUNTS_TO_PURGE = "test_accounts_to_purge";
@@ -0,0 +1,9 @@
1
+ /** Every spelling of `run` with each е or ё as either: a trigram index keeps the text as written. */
2
+ export declare const yoSpellings: (run: string) => string[] | undefined;
3
+ /**
4
+ * An FTS5 trigram MATCH for `part` anywhere in the text, ё and е either way, as message text matches. The index folds
5
+ * case itself; past 64 spellings only the typed one is asked.
6
+ */
7
+ export declare const trigramPart: (part: string) => string;
8
+ /** A GLOB pattern for `word` anywhere in the text, in any case, ё and е either way: what a trigram cannot match. */
9
+ export declare const anyCaseGlob: (word: string) => string;
@@ -0,0 +1,28 @@
1
+ const MOST_YO_SPELLINGS = 64;
2
+ /** Every spelling of `run` with each е or ё as either: a trigram index keeps the text as written. */
3
+ export const yoSpellings = (run) => {
4
+ let spellings = [""];
5
+ for (const c of run) {
6
+ spellings = spellings.flatMap((start) => (c === "е" || c === "ё" ? [`${start}е`, `${start}ё`] : [`${start}${c}`]));
7
+ if (spellings.length > MOST_YO_SPELLINGS)
8
+ return undefined;
9
+ }
10
+ return spellings;
11
+ };
12
+ const phrase = (value) => `"${value.replaceAll('"', '""')}"`;
13
+ /**
14
+ * An FTS5 trigram MATCH for `part` anywhere in the text, ё and е either way, as message text matches. The index folds
15
+ * case itself; past 64 spellings only the typed one is asked.
16
+ */
17
+ export const trigramPart = (part) => {
18
+ const typed = part.normalize("NFC").toLowerCase();
19
+ const spellings = yoSpellings(typed) ?? [typed];
20
+ return spellings.length === 1 ? phrase(typed) : `(${spellings.map(phrase).join(" OR ")})`;
21
+ };
22
+ /** A GLOB pattern for `word` anywhere in the text, in any case, ё and е either way: what a trigram cannot match. */
23
+ export const anyCaseGlob = (word) => `*${[...word.normalize("NFC")]
24
+ .map((c) => {
25
+ const forms = new Set([c, c.toLowerCase(), c.toUpperCase(), ...("еёЕЁ".includes(c) ? ["е", "ё", "Е", "Ё"] : [])].filter((form) => [...form].length === 1));
26
+ return forms.size === 1 ? c : `[${[...forms].join("")}]`;
27
+ })
28
+ .join("")}*`;
@@ -167,7 +167,7 @@ export const workTaskOperationsOver = (context) => {
167
167
  const where = queryFilter(query, projectTaskColumns(at, timezoneOf(zone), database), {
168
168
  command: "tasks list",
169
169
  now: at,
170
- ...(zone ? { zone } : {}),
170
+ zone: timezoneOf(zone),
171
171
  });
172
172
  return { sql: `${BOARD_SCOPE} AND (${where.sql})`, params: where.params };
173
173
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.662.0",
3
+ "version": "0.663.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",
@@ -287,7 +287,7 @@
287
287
  "@types/pngjs": "6.0.5",
288
288
  "@types/ssh2": "1.15.5",
289
289
  "@vitest/coverage-v8": "^5.0.5",
290
- "@wirecat/cli-base": "0.99.0",
290
+ "@wirecat/cli-base": "0.100.0",
291
291
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
292
292
  "ajv": "8.17.1",
293
293
  "commander": "15.0.0",
@@ -309,7 +309,7 @@
309
309
  },
310
310
  "peerDependencies": {
311
311
  "@napi-rs/canvas": ">=0.1.69 <2",
312
- "@wirecat/cli-base": ">=0.98.0 <1.0.0",
312
+ "@wirecat/cli-base": ">=0.100.0 <1.0.0",
313
313
  "commander": ">=15",
314
314
  "ssh2": "^1.17.0"
315
315
  },