@wirecat/cli-core 0.349.0 → 0.351.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
@@ -7,6 +7,37 @@ shape of this file.
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.351.0 — 19.10.2026
11
+
12
+ ### Added
13
+
14
+ - **`findEvidenceMentions(vocabulary, result, { exclude })`** names the existing projects, tags and topics whose
15
+ name, key or alias appears in a `gatherProjectEvidence` result's excerpts and their neighbours, each match cited
16
+ and marked when the term belongs to more than one entry; a vocabulary over its budget is skipped, not fatal. The
17
+ project matcher behind `createMeetingProjectCandidateReader` is the same code (`matchVocabularyTerms`).
18
+ - **`storedNeighbours(store)`**: the neighbours port for chat messages and mail; a mail hit carries the emails
19
+ before and after it in its thread. `storedMessageNeighbours` returns nothing for a mail reference.
20
+
21
+ ## 0.350.0 — 19.10.2026
22
+
23
+ ### Added
24
+
25
+ - **A messenger that pushes its history can be told the chats the store holds**: the optional
26
+ `PushedHistory.storedChats(ids)` gets every chat id of this account once as `feed` starts, in `serve` and `watch`.
27
+ whatsapp-cli uses it to re-key phone-form chats nothing names again, through `rekeys`. A reject is a
28
+ `stored_chats_failed` warning. The contract kit has a case for it, skipped without the method, and
29
+ `fakeAdapter(seed, { storedChats: true })`.
30
+ - **`loginQr().show(link, scan)` says where to scan only once a code exists**: after the drawn code, or after
31
+ the `--qr-file` note. On a terminal too narrow to draw the code, only the hint to widen it or pass `--qr-file`
32
+ is shown. Before, the CLIs said "scan this code" first, so a narrow terminal asked to scan a code that was
33
+ never drawn. `scan` is optional and nothing changes without it: an adapter drops its own scan note before
34
+ `show()` and passes that text as `show(link, scan)` instead.
35
+
36
+ ### Fixed
37
+
38
+ - **A `storedChats` hook that never finishes no longer says messages were not saved** at exit: after the 5 s wait
39
+ it is a `stored_chats_failed` warning that the hook was abandoned, since it only reads chat ids.
40
+
10
41
  ## 0.349.0 — 19.10.2026
11
42
 
12
43
  ### Added
@@ -193,6 +193,7 @@ export const connected = (connection, { app, provider, name, deletedWithoutChat,
193
193
  const pacer = new Pacer(pacePathFor(app, settings.profile, env), rate);
194
194
  const adapter = observed(flooded(connection, memory, { name: name ?? app.command, warn: renderer.warn, pacer }), events);
195
195
  const pending = new Set();
196
+ const announcing = new Set();
196
197
  const saving = self === null
197
198
  ? adapter
198
199
  : stored(adapter, {
@@ -202,6 +203,7 @@ export const connected = (connection, { app, provider, name, deletedWithoutChat,
202
203
  warn: renderer.warn,
203
204
  events,
204
205
  pending,
206
+ announcing,
205
207
  ...(deletedWithoutChat ? { deletedWithoutChat } : {}),
206
208
  rekeyed: (from, to) => rekeyRecipients(app, settings.profile, env, renderer.warn, from, to),
207
209
  ...(history === "store" ? { namesFromStore: savedChatId ? { savedChatId } : {} } : {}),
@@ -226,10 +228,15 @@ export const connected = (connection, { app, provider, name, deletedWithoutChat,
226
228
  events({ event: "warning", code: "store_not_written", operation });
227
229
  renderer.warn(`not saved to the local store: the messenger was still handing on ${what} at exit`);
228
230
  });
229
- if (!(await settled(pending, SAVES_WAIT_MS))) {
231
+ await settled(new Set([...pending, ...announcing]), SAVES_WAIT_MS);
232
+ if (pending.size > 0) {
230
233
  events({ event: "warning", code: "store_not_written", operation: "close" });
231
234
  renderer.warn("not saved to the local store: the last messages were still being written at exit");
232
235
  }
236
+ if (announcing.size > 0) {
237
+ events({ event: "warning", code: "stored_chats_failed", operation: "close" });
238
+ renderer.warn("the messenger's stored-chats hook did not finish and was abandoned at exit; nothing is lost");
239
+ }
233
240
  }
234
241
  finally {
235
242
  await store.close();
@@ -3,7 +3,7 @@ import { isCliFailure } from "../../errors/failures.js";
3
3
  import { throughWrapper } from "../../ports/messenger.js";
4
4
  import { providerErrorKey } from "../../runs/events.js";
5
5
  import { holdEnd } from "../../sends/flood.js";
6
- const LONG_LIVED = new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml"]);
6
+ const LONG_LIVED = new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
7
7
  /** Neither held nor paced, as they listen for as long as the run does; what ends them is still remembered. */
8
8
  const LISTENING = new Set(["watch", "feed", "listen", "listenHistory"]);
9
9
  const BLOCKING = new Set(["frozen", "limited", "banned"]);
@@ -10,6 +10,7 @@ import { environmentOf } from "../context.js";
10
10
  export const lentConnection = (connection, watchers) => throughWrapper(connection, {
11
11
  close: async () => { },
12
12
  feed: undefined,
13
+ storedChats: undefined,
13
14
  listen: undefined,
14
15
  listenHistory: undefined,
15
16
  ...(connection.watch && watchers
@@ -11,6 +11,8 @@ export interface Saving {
11
11
  events: EventSink;
12
12
  /** Saves still writing, for the closer to wait on: `watch` does not hold the next event for one. */
13
13
  pending?: Set<Promise<void>>;
14
+ /** `storedChats` calls still running, apart from `pending`: one abandoned at exit leaves nothing unsaved. */
15
+ announcing?: Set<Promise<void>>;
14
16
  deletedWithoutChat?: DeletionScope;
15
17
  /** The app command and profile running, recorded with the first save so another app can name this account. */
16
18
  profile?: {
@@ -33,4 +35,4 @@ export interface Saving {
33
35
  * would erase what `chats list` stored. Nor are `chat` and `contact`: a card's member list is not
34
36
  * known to be whole, and `saveMembers` replaces the list.
35
37
  */
36
- export declare const stored: (messenger: MessengerAdapter, { account, store, warn, events, pending, deletedWithoutChat, profile, rekeyed, namesFromStore }: Saving) => MessengerAdapter;
38
+ export declare const stored: (messenger: MessengerAdapter, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, namesFromStore }: Saving) => MessengerAdapter;
@@ -11,7 +11,7 @@ import { chatIdIn } from "../../services/message-resolution.js";
11
11
  * would erase what `chats list` stored. Nor are `chat` and `contact`: a card's member list is not
12
12
  * known to be whole, and `saveMembers` replaces the list.
13
13
  */
14
- export const stored = (messenger, { account, store, warn, events, pending, deletedWithoutChat, profile, rekeyed, namesFromStore }) => {
14
+ export const stored = (messenger, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, namesFromStore }) => {
15
15
  let warned = false;
16
16
  let recorded = profile === undefined;
17
17
  const attempt = async (operation, write) => {
@@ -243,7 +243,14 @@ export const stored = (messenger, { account, store, warn, events, pending, delet
243
243
  : {}),
244
244
  ...(messenger.feed
245
245
  ? {
246
- feed: (onBatch, signal) => messenger.feed?.(saveBatches("history.feed", onBatch), signal) ?? Promise.resolve(),
246
+ feed: (onBatch, signal) => {
247
+ if (messenger.storedChats) {
248
+ const announced = announceStoredChats(messenger, store, account, events, warn);
249
+ announcing?.add(announced);
250
+ void announced.finally(() => announcing?.delete(announced));
251
+ }
252
+ return messenger.feed?.(saveBatches("history.feed", onBatch), signal) ?? Promise.resolve();
253
+ },
247
254
  }
248
255
  : {}),
249
256
  ...(messenger.listenHistory
@@ -348,6 +355,19 @@ const personIn = (people, reference) => {
348
355
  throw error;
349
356
  }
350
357
  };
358
+ const announceStoredChats = async (messenger, store, account, events, warn) => {
359
+ try {
360
+ const opened = await store();
361
+ if (!opened)
362
+ return;
363
+ const ids = (await opened.forAccount(account).chats.chats({})).items.map((chat) => chat.id);
364
+ await messenger.storedChats?.(ids);
365
+ }
366
+ catch (error) {
367
+ events({ event: "warning", code: "stored_chats_failed", operation: "history.stored_chats" });
368
+ warn(`the messenger was not told the stored chats: ${error instanceof Error ? error.message : String(error)}`);
369
+ }
370
+ };
351
371
  /** Read once when `watch` starts: a store read per event would let a later event overtake an earlier one. */
352
372
  const rememberTitles = async (store, account, titles) => {
353
373
  try {
@@ -22,7 +22,7 @@ export interface ContractOptions {
22
22
  history?: "server" | "store";
23
23
  }
24
24
  /** Every method of the optional groups, which `capability` hands over or refuses. */
25
- export declare const OPTIONAL_METHODS: readonly ["fetchCounters", "chats", "history", "around", "contact", "historyAfter", "historyBefore", "topics", "inspect", "edit", "forward", "delete", "pin", "unpin", "star", "react", "markRead", "markTopicRead", "poll", "vote", "closePoll", "createPoll", "watch", "listen", "listenHistory", "feed", "download", "transcribe", "scheduled", "members", "admins", "chatEvents", "sessions", "lookup", "addressBook", "people", "createGroup", "join", "leave", "group", "updateGroup", "resetInviteLink", "addMembers", "removeMembers", "addAdmin", "removeAdmin", "folders", "createFolder", "updateFolder", "deleteFolder", "addContact", "removeContact", "block", "unblock", "renameContact", "importContacts", "updateProfile", "endOtherSessions"];
25
+ export declare const OPTIONAL_METHODS: readonly ["fetchCounters", "chats", "history", "around", "contact", "historyAfter", "historyBefore", "topics", "inspect", "edit", "forward", "delete", "pin", "unpin", "star", "react", "markRead", "markTopicRead", "poll", "vote", "closePoll", "createPoll", "watch", "listen", "listenHistory", "feed", "storedChats", "download", "transcribe", "scheduled", "members", "admins", "chatEvents", "sessions", "lookup", "addressBook", "people", "createGroup", "join", "leave", "group", "updateGroup", "resetInviteLink", "addMembers", "removeMembers", "addAdmin", "removeAdmin", "folders", "createFolder", "updateFolder", "deleteFolder", "addContact", "removeContact", "block", "unblock", "renameContact", "importContacts", "updateProfile", "endOtherSessions"];
26
26
  /**
27
27
  * The port's promises as cases any test runner can run: each connects through `connect`, checks
28
28
  * with `node:assert/strict` and closes the adapter. None needs a live service.
@@ -31,6 +31,7 @@ export const OPTIONAL_METHODS = [
31
31
  "listen",
32
32
  "listenHistory",
33
33
  "feed",
34
+ "storedChats",
34
35
  "download",
35
36
  "transcribe",
36
37
  "scheduled",
@@ -486,6 +487,17 @@ export const contractCases = ({ connect, ids = wordIds, orderBy = "id", waitMs =
486
487
  },
487
488
  "the fake pushes the seed's history once connected, as `fakeAdapter(seed, { feed: true })` does",
488
489
  ],
490
+ [
491
+ "storedChats takes no ids, and ids it does not know, without rejecting",
492
+ async (adapter, seed) => {
493
+ const skipped = lacking(adapter, "storedChats");
494
+ if (skipped)
495
+ return skipped;
496
+ await within(Promise.resolve(adapter.storedChats?.([])), "storedChats did not resolve for no ids", waitMs);
497
+ const ids = [...seed.chats.map((chat) => chat.id), unknownChat];
498
+ await within(Promise.resolve(adapter.storedChats?.(ids)), "storedChats did not resolve for the ids", waitMs);
499
+ },
500
+ ],
489
501
  ]),
490
502
  {
491
503
  name: "self() is null before a login",
@@ -6,4 +6,5 @@ export declare const fakeAdapter: (seed?: Seed, options?: {
6
6
  feed?: boolean;
7
7
  listen?: boolean;
8
8
  listenHistory?: boolean;
9
+ storedChats?: boolean;
9
10
  }) => FakeAdapter;
package/dist/kit/fake.js CHANGED
@@ -29,7 +29,8 @@ const missing = (what) => new CliError("not_found", `the fake adapter has no ${w
29
29
  * With `{ feed: true }` it also pushes its history, as a messenger with `history: "store"` does:
30
30
  * the chats and people in one batch, then each chat's messages in a batch of their own.
31
31
  * With `{ listen: true }` it also has `listen`, which hands on what `watch` does, and with `{ listenHistory: true }`
32
- * `listenHistory`, which hands on what `feed` does.
32
+ * `listenHistory`, which hands on what `feed` does. With `{ storedChats: true }` it takes the stored chat ids and
33
+ * does nothing with them.
33
34
  */
34
35
  const withRules = (folder, { emoji, include, skip, exclude, pin }) => {
35
36
  if (emoji !== undefined)
@@ -337,6 +338,7 @@ export const fakeAdapter = (seed = contractSeed(), options = {}) => {
337
338
  : {}),
338
339
  ...(options.feed ? { feed: pushHistory } : {}),
339
340
  ...(options.listenHistory ? { listenHistory: pushHistory } : {}),
341
+ ...(options.storedChats ? { storedChats: async () => { } } : {}),
340
342
  download: async (reference, messageId) => {
341
343
  const message = messageOf(chatOf(reference).id, messageId);
342
344
  return {
@@ -38,7 +38,6 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
- limit?: undefined;
42
41
  event_id?: undefined;
43
42
  series_id?: undefined;
44
43
  page?: undefined;
@@ -54,11 +53,11 @@ export declare const meetingTools: ({
54
53
  format?: undefined;
55
54
  transcript_id?: undefined;
56
55
  query?: undefined;
56
+ limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
- limit?: undefined;
62
61
  event_id?: undefined;
63
62
  series_id?: undefined;
64
63
  page?: undefined;
@@ -76,11 +75,11 @@ export declare const meetingTools: ({
76
75
  format?: undefined;
77
76
  transcript_id?: undefined;
78
77
  query?: undefined;
78
+ limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
- limit?: undefined;
84
83
  event_id?: undefined;
85
84
  series_id?: undefined;
86
85
  page?: undefined;
@@ -102,6 +101,7 @@ export declare const meetingTools: ({
102
101
  minimum: number;
103
102
  };
104
103
  query?: undefined;
104
+ limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,7 +188,6 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
- limit?: undefined;
192
191
  event_id?: undefined;
193
192
  series_id?: undefined;
194
193
  page?: undefined;
@@ -204,11 +203,11 @@ export declare const meetingTools: ({
204
203
  format?: undefined;
205
204
  transcript_id?: undefined;
206
205
  query?: undefined;
206
+ limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
- limit?: undefined;
212
211
  event_id?: undefined;
213
212
  series_id?: undefined;
214
213
  page?: undefined;
@@ -226,11 +225,11 @@ export declare const meetingTools: ({
226
225
  format?: undefined;
227
226
  transcript_id?: undefined;
228
227
  query?: undefined;
228
+ limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
- limit?: undefined;
234
233
  event_id?: undefined;
235
234
  series_id?: undefined;
236
235
  page?: undefined;
@@ -252,6 +251,7 @@ export declare const meetingTools: ({
252
251
  minimum: number;
253
252
  };
254
253
  query?: undefined;
254
+ limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,7 +338,6 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
- limit?: undefined;
342
341
  event_id?: undefined;
343
342
  series_id?: undefined;
344
343
  page?: undefined;
@@ -354,11 +353,11 @@ export declare const meetingTools: ({
354
353
  format?: undefined;
355
354
  transcript_id?: undefined;
356
355
  query?: undefined;
356
+ limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
- limit?: undefined;
362
361
  event_id?: undefined;
363
362
  series_id?: undefined;
364
363
  page?: undefined;
@@ -376,11 +375,11 @@ export declare const meetingTools: ({
376
375
  format?: undefined;
377
376
  transcript_id?: undefined;
378
377
  query?: undefined;
378
+ limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
- limit?: undefined;
384
383
  event_id?: undefined;
385
384
  series_id?: undefined;
386
385
  page?: undefined;
@@ -402,6 +401,7 @@ export declare const meetingTools: ({
402
401
  minimum: number;
403
402
  };
404
403
  query?: undefined;
404
+ limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,7 +488,6 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
- limit?: undefined;
492
491
  event_id?: undefined;
493
492
  series_id?: undefined;
494
493
  page?: undefined;
@@ -504,11 +503,11 @@ export declare const meetingTools: ({
504
503
  format?: undefined;
505
504
  transcript_id?: undefined;
506
505
  query?: undefined;
506
+ limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
- limit?: undefined;
512
511
  event_id?: undefined;
513
512
  series_id?: undefined;
514
513
  page?: undefined;
@@ -526,11 +525,11 @@ export declare const meetingTools: ({
526
525
  format?: undefined;
527
526
  transcript_id?: undefined;
528
527
  query?: undefined;
528
+ limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
- limit?: undefined;
534
533
  event_id?: undefined;
535
534
  series_id?: undefined;
536
535
  page?: undefined;
@@ -552,6 +551,7 @@ export declare const meetingTools: ({
552
551
  minimum: number;
553
552
  };
554
553
  query?: undefined;
554
+ limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,7 +638,6 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
- limit?: undefined;
642
641
  event_id?: undefined;
643
642
  series_id?: undefined;
644
643
  page?: undefined;
@@ -654,11 +653,11 @@ export declare const meetingTools: ({
654
653
  format?: undefined;
655
654
  transcript_id?: undefined;
656
655
  query?: undefined;
656
+ limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
- limit?: undefined;
662
661
  event_id?: undefined;
663
662
  series_id?: undefined;
664
663
  page?: undefined;
@@ -676,11 +675,11 @@ export declare const meetingTools: ({
676
675
  format?: undefined;
677
676
  transcript_id?: undefined;
678
677
  query?: undefined;
678
+ limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
- limit?: undefined;
684
683
  event_id?: undefined;
685
684
  series_id?: undefined;
686
685
  page?: undefined;
@@ -702,6 +701,7 @@ export declare const meetingTools: ({
702
701
  minimum: number;
703
702
  };
704
703
  query?: undefined;
704
+ limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -365,6 +365,11 @@ export interface HistoryBatch {
365
365
  export interface PushedHistory {
366
366
  /** Chats, people and past messages as the messenger pushes them, until `signal` aborts. */
367
367
  feed(onBatch: (batch: HistoryBatch) => void, signal: AbortSignal): Promise<void>;
368
+ /**
369
+ * Every chat id the store holds for this account, handed over once as `feed` starts, so a chat nothing names again
370
+ * can still be re-keyed through a later batch's `rekeys`. A reject is a warning; `feed` goes on.
371
+ */
372
+ storedChats?(ids: readonly Id[]): void | Promise<void>;
368
373
  }
369
374
  /** A message's files and its speech, fetched from the messenger. */
370
375
  export interface MessageMedia {
@@ -5,7 +5,9 @@ export { type DownloadedModel, downloadImageModel, downloadTextModel, type Model
5
5
  export type { ProjectEvidenceItem, ProjectGathering, ProjectGatheringPorts, ProjectGatheringStop, ProjectIndexCatchUp, ProjectSourceFetcher, } from "./project-gathering.js";
6
6
  export { gatherProjectEvidence } from "./project-gathering.js";
7
7
  export type { ProjectNeighbour, ProjectNeighbourReader } from "./project-gathering-around.js";
8
- export { storedMessageNeighbours } from "./project-gathering-around.js";
8
+ export { storedMessageNeighbours, storedNeighbours } from "./project-gathering-around.js";
9
+ export type { EvidenceMention, EvidenceMentions } from "./project-gathering-mentions.js";
10
+ export { findEvidenceMentions } from "./project-gathering-mentions.js";
9
11
  export type { ProjectFetchState, ProjectGatheringBudgets, ProjectGatheringRequest, ProjectLane, ProjectLaneKind, ProjectUnitState, } from "./project-gathering-request.js";
10
12
  import { type AccountService } from "./account.js";
11
13
  import { type AdminService } from "./admin.js";
@@ -2,7 +2,8 @@ import { botCheckService } from "../botcheck/service.js";
2
2
  export { createContextEvidenceReader } from "./context-evidence.js";
3
3
  export { downloadImageModel, downloadTextModel, } from "./model-downloads.js";
4
4
  export { gatherProjectEvidence } from "./project-gathering.js";
5
- export { storedMessageNeighbours } from "./project-gathering-around.js";
5
+ export { storedMessageNeighbours, storedNeighbours } from "./project-gathering-around.js";
6
+ export { findEvidenceMentions } from "./project-gathering-mentions.js";
6
7
  import { accountService } from "./account.js";
7
8
  import { adminService } from "./admin.js";
8
9
  import { adminStatisticsService } from "./admin-statistics.js";
@@ -1,5 +1,24 @@
1
1
  import type { MeetingProjectCandidateInput } from "../meetings/index.js";
2
2
  import type { VocabularyCatalog } from "../store/index.js";
3
+ type Entry = VocabularyCatalog["entries"][number];
4
+ export type VocabularyTerm = {
5
+ name: string;
6
+ kind: "canonical" | "key" | "alias";
7
+ aliasId?: string;
8
+ };
9
+ /** Every entry whose name, key or alias stands as whole words in a text, at most 20 matches an entry. */
10
+ export declare const matchVocabularyTerms: <S>(catalog: VocabularyCatalog, texts: readonly {
11
+ text: string;
12
+ source: S;
13
+ }[]) => {
14
+ entry: Entry;
15
+ matches: {
16
+ term: VocabularyTerm;
17
+ source: S;
18
+ ambiguous: boolean;
19
+ }[];
20
+ omitted: number;
21
+ }[];
3
22
  export declare const matchProjectCandidates: (catalog: VocabularyCatalog, input: MeetingProjectCandidateInput) => {
4
23
  project: {
5
24
  reference: string;
@@ -10,3 +29,4 @@ export declare const matchProjectCandidates: (catalog: VocabularyCatalog, input:
10
29
  matches: import("../meetings/project-candidates.js").MeetingProjectCandidateMatch[];
11
30
  omittedMatches: number;
12
31
  }[];
32
+ export {};
@@ -5,7 +5,8 @@ const termsOf = (entry) => [
5
5
  ...(entry.key ? [{ name: entry.key, kind: "key" }] : []),
6
6
  ...entry.aliases.map((alias) => ({ name: alias.name, kind: "alias", aliasId: alias.id })),
7
7
  ];
8
- export const matchProjectCandidates = (catalog, input) => {
8
+ /** Every entry whose name, key or alias stands as whole words in a text, at most 20 matches an entry. */
9
+ export const matchVocabularyTerms = (catalog, texts) => {
9
10
  const owners = new Map();
10
11
  for (const entry of catalog.entries)
11
12
  for (const term of termsOf(entry)) {
@@ -14,29 +15,11 @@ export const matchProjectCandidates = (catalog, input) => {
14
15
  ids.add(entry.id);
15
16
  owners.set(key, ids);
16
17
  }
17
- const sources = [
18
- ...(input.title === undefined
19
- ? []
20
- : [
21
- {
22
- text: normalizedText(input.title),
23
- source: { kind: "metadata-title", reference: input.reference, fingerprint: null, revision: null },
24
- },
25
- ]),
26
- ...(input.cues ?? []).map((cue) => ({
27
- text: normalizedText(cue.text),
28
- source: {
29
- kind: "transcript",
30
- reference: cue.reference,
31
- fingerprint: cue.fingerprint,
32
- revision: cue.revision,
33
- },
34
- })),
35
- ];
18
+ const sources = texts.map(({ text, source }) => ({ text: normalizedText(text), source }));
36
19
  const result = [];
37
20
  for (const entry of catalog.entries) {
38
21
  const matches = [];
39
- let omittedMatches = 0;
22
+ let omitted = 0;
40
23
  const seen = new Set();
41
24
  for (const term of termsOf(entry)) {
42
25
  const normalized = normalizeVocabularyName(term.name);
@@ -48,18 +31,37 @@ export const matchProjectCandidates = (catalog, input) => {
48
31
  if (!pattern.test(text))
49
32
  continue;
50
33
  if (matches.length === 20) {
51
- omittedMatches++;
34
+ omitted++;
52
35
  continue;
53
36
  }
54
37
  matches.push({ term, source, ambiguous: (owners.get(normalized)?.size ?? 0) > 1 });
55
38
  }
56
39
  }
57
40
  if (matches.length)
58
- result.push({
59
- project: { reference: `project:${entry.id}`, id: entry.id, name: entry.name, key: entry.key },
60
- matches,
61
- omittedMatches,
62
- });
41
+ result.push({ entry, matches, omitted });
63
42
  }
64
- return result.sort((a, b) => Number(a.project.id) - Number(b.project.id));
43
+ return result.sort((a, b) => Number(a.entry.id) - Number(b.entry.id));
65
44
  };
45
+ export const matchProjectCandidates = (catalog, input) => matchVocabularyTerms(catalog, [
46
+ ...(input.title === undefined
47
+ ? []
48
+ : [
49
+ {
50
+ text: input.title,
51
+ source: { kind: "metadata-title", reference: input.reference, fingerprint: null, revision: null },
52
+ },
53
+ ]),
54
+ ...(input.cues ?? []).map((cue) => ({
55
+ text: cue.text,
56
+ source: {
57
+ kind: "transcript",
58
+ reference: cue.reference,
59
+ fingerprint: cue.fingerprint,
60
+ revision: cue.revision,
61
+ },
62
+ })),
63
+ ]).map(({ entry, matches, omitted }) => ({
64
+ project: { reference: `project:${entry.id}`, id: entry.id, name: entry.name, key: entry.key },
65
+ matches: matches.map(({ term, source, ambiguous }) => ({ term, source, ambiguous })),
66
+ omittedMatches: omitted,
67
+ }));
@@ -1,3 +1,4 @@
1
+ import type { MessageStore } from "../store/index.js";
1
2
  import type { MessagesStore } from "../store/messages.js";
2
3
  export interface ProjectNeighbour {
3
4
  ref: string;
@@ -6,7 +7,7 @@ export interface ProjectNeighbour {
6
7
  text: string;
7
8
  found: boolean;
8
9
  }
9
- /** The stored messages next to a hit in its chat, oldest first, without the hit itself. */
10
+ /** The stored messages or emails next to a hit, oldest first, without the hit itself. */
10
11
  export interface ProjectNeighbourReader {
11
12
  around(ref: string, window: {
12
13
  before: number;
@@ -35,3 +36,5 @@ export declare const attachNeighbours: (items: {
35
36
  remaining: () => number;
36
37
  charge: (bytes: number) => void;
37
38
  }, known: (ref: string) => boolean, signal?: AbortSignal) => Promise<void>;
39
+ /** Chat messages next to a hit in its chat, and the emails before and after a mail hit in its thread. */
40
+ export declare const storedNeighbours: (store: Pick<MessageStore, "messages" | "mail" | "accounts">) => ProjectNeighbourReader;
@@ -4,6 +4,8 @@ import { excerpt } from "./excerpt.js";
4
4
  export const storedMessageNeighbours = (messages) => ({
5
5
  async around(ref, window) {
6
6
  const at = parseLocator(ref);
7
+ if (at.provider === "email")
8
+ return [];
7
9
  const rows = await messages.around({ provider: at.provider, account: at.account }, at.chat, at.message, window);
8
10
  return rows
9
11
  .filter((row) => !row.anchor)
@@ -23,7 +25,7 @@ export const attachNeighbours = async (items, reader, window, budget, known, sig
23
25
  if (!reader || window.before + window.after === 0)
24
26
  return;
25
27
  for (const item of items) {
26
- if (item.kind !== "message")
28
+ if (item.kind !== "message" && item.kind !== "mail")
27
29
  continue;
28
30
  if (budget.remaining() <= 0) {
29
31
  item.around = null;
@@ -55,3 +57,32 @@ export const attachNeighbours = async (items, reader, window, budget, known, sig
55
57
  }
56
58
  }
57
59
  };
60
+ /** Chat messages next to a hit in its chat, and the emails before and after a mail hit in its thread. */
61
+ export const storedNeighbours = (store) => {
62
+ const messages = storedMessageNeighbours(store.messages);
63
+ return {
64
+ async around(ref, window) {
65
+ const at = parseLocator(ref);
66
+ if (at.provider !== "email")
67
+ return messages.around(ref, window);
68
+ const account = await store.accounts.storedAccount({ provider: at.provider, account: at.account });
69
+ const email = await store.mail.email(account.id, at.message);
70
+ if (!email)
71
+ throw new CliError("not_found", "the hit's email is no longer stored");
72
+ const thread = await store.mail.thread(email.emailThreadId);
73
+ const emails = thread?.emails ?? [];
74
+ const index = emails.findIndex((one) => one.id === email.id);
75
+ if (index < 0)
76
+ return [];
77
+ return [
78
+ ...emails.slice(Math.max(0, index - window.before), index),
79
+ ...emails.slice(index + 1, index + 1 + window.after),
80
+ ].map((one) => ({
81
+ ref: formatLocator({ ...at, message: one.externalId }),
82
+ at: one.sentAt ?? one.receivedAt ?? 0,
83
+ sender: one.fromName ?? one.fromAddress,
84
+ text: [one.subject, one.bodyText ?? one.snippet].filter(Boolean).join(" — "),
85
+ }));
86
+ },
87
+ };
88
+ };
@@ -0,0 +1,44 @@
1
+ import type { VocabularyKind, VocabularyStore } from "../store/index.js";
2
+ import { type VocabularyTerm } from "./meeting-project-candidate-matching.js";
3
+ import type { ProjectGathering } from "./project-gathering.js";
4
+ export interface EvidenceMention {
5
+ target: {
6
+ kind: VocabularyKind;
7
+ id: string;
8
+ reference: string;
9
+ name: string;
10
+ key: string | null;
11
+ };
12
+ matches: {
13
+ term: VocabularyTerm;
14
+ ambiguous: boolean;
15
+ reference: string;
16
+ in: "hit" | "around";
17
+ }[];
18
+ omittedMatches: number;
19
+ }
20
+ export interface EvidenceMentions {
21
+ kind: "evidence_mentions";
22
+ association: "unconfirmed-literal-evidence";
23
+ items: EvidenceMention[];
24
+ vocabularyFingerprints: Partial<Record<VocabularyKind, string>>;
25
+ coverage: {
26
+ texts: "returned-excerpts";
27
+ matching: "unicode-normalized-literal-word-boundaries";
28
+ hasMore: boolean;
29
+ skipped: {
30
+ kind: VocabularyKind;
31
+ code: string;
32
+ reason: string | null;
33
+ }[];
34
+ };
35
+ }
36
+ /**
37
+ * Which existing projects, tags and topics the returned excerpts and their neighbours name. A name is evidence to
38
+ * review, never membership; the gathered project itself is left out.
39
+ */
40
+ export declare const findEvidenceMentions: (vocabulary: Pick<VocabularyStore, "vocabulary">, gathering: Pick<ProjectGathering, "items">, options?: {
41
+ exclude?: string | null;
42
+ limit?: number;
43
+ signal?: AbortSignal;
44
+ }) => Promise<EvidenceMentions>;
@@ -0,0 +1,60 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { matchVocabularyTerms } from "./meeting-project-candidate-matching.js";
3
+ const KINDS = ["project", "tag", "topic"];
4
+ /**
5
+ * Which existing projects, tags and topics the returned excerpts and their neighbours name. A name is evidence to
6
+ * review, never membership; the gathered project itself is left out.
7
+ */
8
+ export const findEvidenceMentions = async (vocabulary, gathering, options = {}) => {
9
+ if (typeof vocabulary?.vocabulary !== "function")
10
+ throw new CliError("configuration_error", "evidence mentions need the store's vocabulary");
11
+ const limit = options.limit ?? 50;
12
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 200)
13
+ throw new CliError("validation_error", "limit must be a whole number from 1 to 200", { param: "limit" });
14
+ const texts = gathering.items.flatMap((item) => [
15
+ { text: `${item.title ?? ""} ${item.text}`, source: { reference: item.ref, in: "hit" } },
16
+ ...(item.around ?? []).map((one) => ({ text: one.text, source: { reference: one.ref, in: "around" } })),
17
+ ]);
18
+ const items = [];
19
+ const vocabularyFingerprints = {};
20
+ const skipped = [];
21
+ for (const kind of KINDS) {
22
+ options.signal?.throwIfAborted();
23
+ let catalog;
24
+ try {
25
+ catalog = await vocabulary.vocabulary({ kind, signal: options.signal });
26
+ }
27
+ catch (error) {
28
+ options.signal?.throwIfAborted();
29
+ if (!(error instanceof CliError))
30
+ throw error;
31
+ const reason = error.details?.reason;
32
+ skipped.push({ kind, code: error.code, reason: typeof reason === "string" ? reason : null });
33
+ continue;
34
+ }
35
+ vocabularyFingerprints[kind] = catalog.fingerprint;
36
+ for (const { entry, matches, omitted } of matchVocabularyTerms(catalog, texts)) {
37
+ const reference = `${kind}:${entry.id}`;
38
+ if (reference === options.exclude)
39
+ continue;
40
+ items.push({
41
+ target: { kind, id: entry.id, reference, name: entry.name, key: entry.key },
42
+ matches: matches.map(({ term, source, ambiguous }) => ({ term, ambiguous, ...source })),
43
+ omittedMatches: omitted,
44
+ });
45
+ }
46
+ }
47
+ items.sort((a, b) => b.matches.length - a.matches.length);
48
+ return {
49
+ kind: "evidence_mentions",
50
+ association: "unconfirmed-literal-evidence",
51
+ items: items.slice(0, limit),
52
+ vocabularyFingerprints,
53
+ coverage: {
54
+ texts: "returned-excerpts",
55
+ matching: "unicode-normalized-literal-word-boundaries",
56
+ hasMore: items.length > limit,
57
+ skipped,
58
+ },
59
+ };
60
+ };
@@ -19,8 +19,11 @@ export interface LoginQrOptions {
19
19
  }
20
20
  export interface LoginQr {
21
21
  readonly path: string | undefined;
22
- /** Never throws for a code that does not fit: the messengers call it from inside their own event loops. */
23
- show: (link: string) => void;
22
+ /**
23
+ * `scan` says where to scan; it follows the code, and is not said when the terminal is too narrow to draw one.
24
+ * Never throws for a code that does not fit: the messengers call it from inside their own event loops.
25
+ */
26
+ show: (link: string, scan?: string) => void;
24
27
  /** The image logs the account in while it is valid; call this in `finally`. */
25
28
  close: () => void;
26
29
  }
@@ -17,11 +17,13 @@ export const loginQr = ({ qrFile, diagnostic, note, indent: pad = 0, columns = (
17
17
  let written = false;
18
18
  return {
19
19
  path,
20
- show: (link) => {
20
+ show: (link, scan) => {
21
21
  if (path) {
22
22
  writeSecurely(path, qrPng(link), 0o600);
23
23
  written = true;
24
24
  note(`the QR code is in ${path} — it is replaced when the code renews`);
25
+ if (scan)
26
+ note(scan);
25
27
  return;
26
28
  }
27
29
  const drawn = terminalQr(link);
@@ -33,6 +35,8 @@ export const loginQr = ({ qrFile, diagnostic, note, indent: pad = 0, columns = (
33
35
  return;
34
36
  }
35
37
  diagnostic(`\n${indent(drawn.text, pad + MARGIN)}`);
38
+ if (scan)
39
+ note(scan);
36
40
  },
37
41
  close: () => {
38
42
  if (!path || !written)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.349.0",
3
+ "version": "0.351.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",