@wirecat/cli-core 0.348.0 → 0.350.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 +48 -0
- package/dist/cli/messenger/context.js +8 -1
- package/dist/cli/messenger/flooded.js +1 -1
- package/dist/cli/messenger/observed.js +6 -3
- package/dist/cli/messenger/serve-relay.js +1 -0
- package/dist/cli/messenger/stored.d.ts +3 -1
- package/dist/cli/messenger/stored.js +22 -2
- package/dist/context/evidence.d.ts +10 -0
- package/dist/kit/contract.d.ts +1 -1
- package/dist/kit/contract.js +12 -0
- package/dist/kit/fake.d.ts +1 -0
- package/dist/kit/fake.js +3 -1
- package/dist/ports/messenger.d.ts +5 -0
- package/dist/services/context-evidence.d.ts +1 -1
- package/dist/services/index.d.ts +5 -3
- package/dist/services/index.js +1 -0
- package/dist/services/project-gathering-around.d.ts +37 -0
- package/dist/services/project-gathering-around.js +57 -0
- package/dist/services/project-gathering-request.d.ts +13 -1
- package/dist/services/project-gathering-request.js +23 -5
- package/dist/services/project-gathering.d.ts +15 -1
- package/dist/services/project-gathering.js +32 -1
- package/dist/store/sqlite/context-evidence.d.ts +4 -1
- package/dist/store/sqlite/context-evidence.js +12 -0
- package/dist/store/store.d.ts +2 -1
- package/dist/store/store.js +5 -1
- package/dist/terminal/login-qr.d.ts +5 -2
- package/dist/terminal/login-qr.js +5 -1
- package/package.json +1 -1
- package/parity.json +2 -12
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,54 @@ shape of this file.
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 0.350.0 — 19.10.2026
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **A messenger that pushes its history can be told the chats the store holds**: the optional
|
|
15
|
+
`PushedHistory.storedChats(ids)` gets every chat id of this account once as `feed` starts, in `serve` and `watch`.
|
|
16
|
+
whatsapp-cli uses it to re-key phone-form chats nothing names again, through `rekeys`. A reject is a
|
|
17
|
+
`stored_chats_failed` warning. The contract kit has a case for it, skipped without the method, and
|
|
18
|
+
`fakeAdapter(seed, { storedChats: true })`.
|
|
19
|
+
- **`loginQr().show(link, scan)` says where to scan only once a code exists**: after the drawn code, or after
|
|
20
|
+
the `--qr-file` note. On a terminal too narrow to draw the code, only the hint to widen it or pass `--qr-file`
|
|
21
|
+
is shown. Before, the CLIs said "scan this code" first, so a narrow terminal asked to scan a code that was
|
|
22
|
+
never drawn. `scan` is optional and nothing changes without it: an adapter drops its own scan note before
|
|
23
|
+
`show()` and passes that text as `show(link, scan)` instead.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **A `storedChats` hook that never finishes no longer says messages were not saved** at exit: after the 5 s wait
|
|
28
|
+
it is a `stored_chats_failed` warning that the hook was abandoned, since it only reads chat ids.
|
|
29
|
+
|
|
30
|
+
## 0.349.0 — 19.10.2026
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- **`gatherProjectEvidence` brings the mail and document index up to date before reading** through the new
|
|
35
|
+
optional `MessageStore.contextIndex` port (`ContextIndex.catchUp`), the same fills a mail search and the notes
|
|
36
|
+
search run. `index: "as-is"` skips it; the result's `index` says what happened. On a store just synced, new
|
|
37
|
+
mail and imported documents were missed before.
|
|
38
|
+
- **The project key is a search lane of its own** (`project.key`, lane kind `key`), and an explicit window may
|
|
39
|
+
give `after` alone: `before` is `asOf`, frozen with the run.
|
|
40
|
+
- **Each message hit of `gatherProjectEvidence` carries the messages next to it** (`around`, default 2 before and 2
|
|
41
|
+
after, at most 5) through the new `neighbours` port; `storedMessageNeighbours(store.messages)` builds it. They
|
|
42
|
+
are cited context, not matches, and their bytes count against `maxReadBytes`. A reply that names nothing was
|
|
43
|
+
out of reach of every search.
|
|
44
|
+
- **The default read budget covers one full round**: one read per search × source × 90-day chunk when that is more
|
|
45
|
+
than 48 (at most 512), so `--source all` with several searches no longer stops before every search ran once.
|
|
46
|
+
- **`ProjectFetchState`, `ProjectUnitState`, `ProjectIndexCatchUp` and `ContextIndex` are exported** from
|
|
47
|
+
`@wirecat/cli-core/services`, so a host can name the result type.
|
|
48
|
+
|
|
49
|
+
### Changed — may break callers
|
|
50
|
+
|
|
51
|
+
- **`feed` and a one-shot command's passive listen keep one operation name in their run records and warnings**:
|
|
52
|
+
`history.feed` for `feed`, `messages.listen` for `listen` and `history.listen` for `listenHistory`, as
|
|
53
|
+
`messages.watch` does for `watch`. Before, the run record said `adapter.feed`, `adapter.listen` or
|
|
54
|
+
`adapter.listenHistory`, so `runs --operation adapter.feed` and `adapter.listen` stop matching new runs.
|
|
55
|
+
- **`parity.json` expects `--qr-file` on `session start` and `setup` in all three CLIs**: max has it since
|
|
56
|
+
max-cli#736, so the rows are `all` instead of planned for max.
|
|
57
|
+
|
|
10
58
|
## 0.348.0 — 19.10.2026
|
|
11
59
|
|
|
12
60
|
### 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
|
-
|
|
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"]);
|
|
@@ -40,7 +40,7 @@ export const observed = (messenger, events) => {
|
|
|
40
40
|
}), () => ({ counts }));
|
|
41
41
|
};
|
|
42
42
|
const mint = messenger.newSendId;
|
|
43
|
-
const { chats, history, contact, around, watch, listen, listenHistory } = messenger;
|
|
43
|
+
const { chats, history, contact, around, watch, feed, listen, listenHistory } = messenger;
|
|
44
44
|
// A method not listed here is timed under its own name, with no ids until a line here names them.
|
|
45
45
|
return throughWrapper(messenger, {
|
|
46
46
|
self: () => messenger.self(),
|
|
@@ -87,14 +87,17 @@ export const observed = (messenger, events) => {
|
|
|
87
87
|
watch: (onEvent, signal, onReady) => counted("messages.watch", onEvent, (counting) => watch.call(messenger, counting, signal, onReady), byEvent),
|
|
88
88
|
}
|
|
89
89
|
: {}),
|
|
90
|
+
...(feed
|
|
91
|
+
? { feed: (onBatch, signal) => timed("history.feed", {}, () => feed.call(messenger, onBatch, signal)) }
|
|
92
|
+
: {}),
|
|
90
93
|
...(listen
|
|
91
94
|
? {
|
|
92
|
-
listen: (onEvent, signal) => counted("
|
|
95
|
+
listen: (onEvent, signal) => counted("messages.listen", onEvent, (counting) => listen.call(messenger, counting, signal), byEvent),
|
|
93
96
|
}
|
|
94
97
|
: {}),
|
|
95
98
|
...(listenHistory
|
|
96
99
|
? {
|
|
97
|
-
listenHistory: (onBatch, signal) => counted("
|
|
100
|
+
listenHistory: (onBatch, signal) => counted("history.listen", onBatch, (counting) => listenHistory.call(messenger, counting, signal), byPart),
|
|
98
101
|
}
|
|
99
102
|
: {}),
|
|
100
103
|
logout: () => timed("session.logout", {}, () => messenger.logout()),
|
|
@@ -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) =>
|
|
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 {
|
|
@@ -53,6 +53,16 @@ export interface ContextEvidencePage {
|
|
|
53
53
|
export interface ContextEvidenceReader {
|
|
54
54
|
read(request: ContextEvidenceRequest): Promise<ContextEvidencePage>;
|
|
55
55
|
}
|
|
56
|
+
/** Brings the word index of stored mail and imported documents up to date, so the reads that follow find new text. */
|
|
57
|
+
export interface ContextIndex {
|
|
58
|
+
catchUp(request: {
|
|
59
|
+
kinds: readonly ContextSource["kind"][];
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
mail: number;
|
|
63
|
+
documents: number;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
56
66
|
export declare const contextCursorScope: (request: Pick<ContextEvidenceRequest, "source" | "query" | "after" | "before">) => string;
|
|
57
67
|
export declare const contextSource: (value: ContextSource) => ContextSource;
|
|
58
68
|
export declare const contextEvidenceRequest: (input: ContextEvidenceRequest) => {
|
package/dist/kit/contract.d.ts
CHANGED
|
@@ -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.
|
package/dist/kit/contract.js
CHANGED
|
@@ -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",
|
package/dist/kit/fake.d.ts
CHANGED
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 {
|
|
@@ -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,5 +5,5 @@ export interface ScopedContextEvidenceReader extends ContextEvidenceReader {
|
|
|
5
5
|
usage(): ContextReadUsage;
|
|
6
6
|
}
|
|
7
7
|
export declare const createContextEvidenceReader: (port: ContextEvidenceReader, allowed: readonly ContextSource[], limits?: ContextReadLimits) => ScopedContextEvidenceReader;
|
|
8
|
-
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextSource, } from "../context/evidence.js";
|
|
8
|
+
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextIndex, ContextSource, } from "../context/evidence.js";
|
|
9
9
|
export type { ContextReadLimits, ContextReadUsage } from "../context/read-budget.js";
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type BotCheckService } from "../botcheck/service.js";
|
|
2
|
-
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextReadLimits, ContextReadUsage, ContextSource, ScopedContextEvidenceReader, } from "./context-evidence.js";
|
|
2
|
+
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextIndex, ContextReadLimits, ContextReadUsage, ContextSource, ScopedContextEvidenceReader, } from "./context-evidence.js";
|
|
3
3
|
export { createContextEvidenceReader } from "./context-evidence.js";
|
|
4
4
|
export { type DownloadedModel, downloadImageModel, downloadTextModel, type ModelDownloadOptions, } from "./model-downloads.js";
|
|
5
|
-
export type { ProjectEvidenceItem, ProjectGathering, ProjectGatheringPorts, ProjectGatheringStop, ProjectSourceFetcher, } from "./project-gathering.js";
|
|
5
|
+
export type { ProjectEvidenceItem, ProjectGathering, ProjectGatheringPorts, ProjectGatheringStop, ProjectIndexCatchUp, ProjectSourceFetcher, } from "./project-gathering.js";
|
|
6
6
|
export { gatherProjectEvidence } from "./project-gathering.js";
|
|
7
|
-
export type {
|
|
7
|
+
export type { ProjectNeighbour, ProjectNeighbourReader } from "./project-gathering-around.js";
|
|
8
|
+
export { storedMessageNeighbours } from "./project-gathering-around.js";
|
|
9
|
+
export type { ProjectFetchState, ProjectGatheringBudgets, ProjectGatheringRequest, ProjectLane, ProjectLaneKind, ProjectUnitState, } from "./project-gathering-request.js";
|
|
8
10
|
import { type AccountService } from "./account.js";
|
|
9
11
|
import { type AdminService } from "./admin.js";
|
|
10
12
|
import { type AdminStatisticsService } from "./admin-statistics.js";
|
package/dist/services/index.js
CHANGED
|
@@ -2,6 +2,7 @@ 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
6
|
import { accountService } from "./account.js";
|
|
6
7
|
import { adminService } from "./admin.js";
|
|
7
8
|
import { adminStatisticsService } from "./admin-statistics.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MessagesStore } from "../store/messages.js";
|
|
2
|
+
export interface ProjectNeighbour {
|
|
3
|
+
ref: string;
|
|
4
|
+
at: number;
|
|
5
|
+
sender: string | null;
|
|
6
|
+
text: string;
|
|
7
|
+
found: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** The stored messages next to a hit in its chat, oldest first, without the hit itself. */
|
|
10
|
+
export interface ProjectNeighbourReader {
|
|
11
|
+
around(ref: string, window: {
|
|
12
|
+
before: number;
|
|
13
|
+
after: number;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
ref: string;
|
|
16
|
+
at: number;
|
|
17
|
+
sender: string | null;
|
|
18
|
+
text: string;
|
|
19
|
+
}[]>;
|
|
20
|
+
}
|
|
21
|
+
export declare const storedMessageNeighbours: (messages: Pick<MessagesStore, "around">) => ProjectNeighbourReader;
|
|
22
|
+
/**
|
|
23
|
+
* Neighbours are context for reading a hit, not matches: they never join `items`, and their text counts against
|
|
24
|
+
* the run's read bytes.
|
|
25
|
+
*/
|
|
26
|
+
export declare const attachNeighbours: (items: {
|
|
27
|
+
ref: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
around?: ProjectNeighbour[] | null;
|
|
30
|
+
aroundIssue?: string | null;
|
|
31
|
+
}[], reader: ProjectNeighbourReader | undefined, window: {
|
|
32
|
+
before: number;
|
|
33
|
+
after: number;
|
|
34
|
+
}, budget: {
|
|
35
|
+
remaining: () => number;
|
|
36
|
+
charge: (bytes: number) => void;
|
|
37
|
+
}, known: (ref: string) => boolean, signal?: AbortSignal) => Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { formatLocator, parseLocator } from "../domain/locator.js";
|
|
3
|
+
import { excerpt } from "./excerpt.js";
|
|
4
|
+
export const storedMessageNeighbours = (messages) => ({
|
|
5
|
+
async around(ref, window) {
|
|
6
|
+
const at = parseLocator(ref);
|
|
7
|
+
const rows = await messages.around({ provider: at.provider, account: at.account }, at.chat, at.message, window);
|
|
8
|
+
return rows
|
|
9
|
+
.filter((row) => !row.anchor)
|
|
10
|
+
.map((row) => ({
|
|
11
|
+
ref: formatLocator({ ...at, message: row.id }),
|
|
12
|
+
at: Date.parse(row.timestamp),
|
|
13
|
+
sender: row.senderName,
|
|
14
|
+
text: row.text ?? "",
|
|
15
|
+
}));
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Neighbours are context for reading a hit, not matches: they never join `items`, and their text counts against
|
|
20
|
+
* the run's read bytes.
|
|
21
|
+
*/
|
|
22
|
+
export const attachNeighbours = async (items, reader, window, budget, known, signal) => {
|
|
23
|
+
if (!reader || window.before + window.after === 0)
|
|
24
|
+
return;
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
if (item.kind !== "message")
|
|
27
|
+
continue;
|
|
28
|
+
if (budget.remaining() <= 0) {
|
|
29
|
+
item.around = null;
|
|
30
|
+
item.aroundIssue = "read-bytes";
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
signal?.throwIfAborted();
|
|
34
|
+
try {
|
|
35
|
+
const rows = await reader.around(item.ref, window);
|
|
36
|
+
const around = [];
|
|
37
|
+
for (const row of rows.slice(0, window.before + window.after)) {
|
|
38
|
+
const text = excerpt(row.text, "", 200);
|
|
39
|
+
const bytes = Buffer.byteLength(text);
|
|
40
|
+
if (bytes > budget.remaining()) {
|
|
41
|
+
item.aroundIssue = "read-bytes";
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
budget.charge(bytes);
|
|
45
|
+
around.push({ ...row, text, found: known(row.ref) });
|
|
46
|
+
}
|
|
47
|
+
item.around = around;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
signal?.throwIfAborted();
|
|
51
|
+
if (!(error instanceof CliError))
|
|
52
|
+
throw error;
|
|
53
|
+
item.around = null;
|
|
54
|
+
item.aroundIssue = error.code;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -2,6 +2,7 @@ import { type ContextSource } from "../context/evidence.js";
|
|
|
2
2
|
export interface ProjectGatheringRequest {
|
|
3
3
|
project: {
|
|
4
4
|
name: string;
|
|
5
|
+
key?: string;
|
|
5
6
|
background?: string;
|
|
6
7
|
aliases?: string[];
|
|
7
8
|
};
|
|
@@ -17,6 +18,11 @@ export interface ProjectGatheringRequest {
|
|
|
17
18
|
before?: number;
|
|
18
19
|
asOf?: number;
|
|
19
20
|
fetch?: "none" | "before-read";
|
|
21
|
+
index?: "update" | "as-is";
|
|
22
|
+
around?: {
|
|
23
|
+
before: number;
|
|
24
|
+
after: number;
|
|
25
|
+
};
|
|
20
26
|
budgets?: ProjectGatheringBudgets;
|
|
21
27
|
runKey?: string;
|
|
22
28
|
checkpoint?: string;
|
|
@@ -29,7 +35,7 @@ export interface ProjectGatheringBudgets {
|
|
|
29
35
|
maxElapsedMs?: number;
|
|
30
36
|
maxItems?: number;
|
|
31
37
|
}
|
|
32
|
-
export type ProjectLaneKind = "project" | "alias" | "keyword" | "person";
|
|
38
|
+
export type ProjectLaneKind = "project" | "key" | "alias" | "keyword" | "person";
|
|
33
39
|
export interface ProjectLane {
|
|
34
40
|
id: string;
|
|
35
41
|
kinds: ProjectLaneKind[];
|
|
@@ -73,6 +79,7 @@ export declare const CONTEXT_CHUNK_DAYS = 90;
|
|
|
73
79
|
export declare const projectGatheringRequest: (input: ProjectGatheringRequest, now: number) => {
|
|
74
80
|
project: {
|
|
75
81
|
name: string;
|
|
82
|
+
key: string | null;
|
|
76
83
|
background: string | null;
|
|
77
84
|
aliases: string[];
|
|
78
85
|
};
|
|
@@ -91,6 +98,11 @@ export declare const projectGatheringRequest: (input: ProjectGatheringRequest, n
|
|
|
91
98
|
asOf: number;
|
|
92
99
|
};
|
|
93
100
|
fetch: "before-read" | "none";
|
|
101
|
+
index: "as-is" | "update";
|
|
102
|
+
around: {
|
|
103
|
+
before: number;
|
|
104
|
+
after: number;
|
|
105
|
+
};
|
|
94
106
|
budgets: Required<ProjectGatheringBudgets>;
|
|
95
107
|
fingerprint: string;
|
|
96
108
|
runKey: string;
|
|
@@ -55,6 +55,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
55
55
|
"before",
|
|
56
56
|
"asOf",
|
|
57
57
|
"fetch",
|
|
58
|
+
"index",
|
|
59
|
+
"around",
|
|
58
60
|
"budgets",
|
|
59
61
|
"runKey",
|
|
60
62
|
"checkpoint",
|
|
@@ -62,9 +64,10 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
62
64
|
], "");
|
|
63
65
|
if (!input.project || typeof input.project !== "object")
|
|
64
66
|
fail("project needs a name", "project");
|
|
65
|
-
known(input.project, ["name", "background", "aliases"], "project.");
|
|
67
|
+
known(input.project, ["name", "key", "background", "aliases"], "project.");
|
|
66
68
|
const project = {
|
|
67
69
|
name: text(input.project.name, "project.name", 512),
|
|
70
|
+
key: input.project.key === undefined ? null : text(input.project.key, "project.key", 64),
|
|
68
71
|
background: input.project.background === undefined ? null : text(input.project.background, "project.background", 8192),
|
|
69
72
|
aliases: list(input.project.aliases, "project.aliases", LIMITS.lanes).map((a, i) => text(a, `project.aliases.${i}`, 512)),
|
|
70
73
|
};
|
|
@@ -104,6 +107,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
104
107
|
found.people.push(person);
|
|
105
108
|
};
|
|
106
109
|
lane("project", laneQuery(project.name, "project.name"));
|
|
110
|
+
if (project.key)
|
|
111
|
+
lane("key", laneQuery(project.key, "project.key"));
|
|
107
112
|
for (const [i, a] of project.aliases.entries())
|
|
108
113
|
lane("alias", laneQuery(a, `project.aliases.${i}`));
|
|
109
114
|
for (const k of keywords)
|
|
@@ -113,19 +118,30 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
113
118
|
if (lanes.length > LIMITS.lanes)
|
|
114
119
|
fail(`at most ${LIMITS.lanes} distinct search lanes`, "keywords");
|
|
115
120
|
const fetch = input.fetch ?? "none";
|
|
121
|
+
const index = input.index ?? "update";
|
|
122
|
+
if (index !== "update" && index !== "as-is")
|
|
123
|
+
fail("index must be update or as-is", "index");
|
|
124
|
+
if (input.around !== undefined && (!input.around || typeof input.around !== "object"))
|
|
125
|
+
fail("around needs before and after", "around");
|
|
126
|
+
if (input.around)
|
|
127
|
+
known(input.around, ["before", "after"], "around.");
|
|
128
|
+
const around = {
|
|
129
|
+
before: whole(input.around?.before ?? 2, "around.before", 0, 5),
|
|
130
|
+
after: whole(input.around?.after ?? 2, "around.after", 0, 5),
|
|
131
|
+
};
|
|
116
132
|
if (fetch !== "none" && fetch !== "before-read")
|
|
117
133
|
fail("fetch must be none or before-read", "fetch");
|
|
118
134
|
const explicit = input.after !== undefined || input.before !== undefined;
|
|
119
135
|
if (explicit && input.lookbackDays !== undefined)
|
|
120
136
|
fail("give lookbackDays or after/before, not both", "lookbackDays");
|
|
121
|
-
if (explicit &&
|
|
122
|
-
fail("an explicit window needs
|
|
137
|
+
if (explicit && input.after === undefined)
|
|
138
|
+
fail("an explicit window needs after; before defaults to asOf", "after");
|
|
123
139
|
const asOf = input.asOf === undefined ? null : whole(input.asOf, "asOf", 1, MAX_TIME);
|
|
124
140
|
const lookbackDays = explicit ? null : whole(input.lookbackDays ?? 60, "lookbackDays", 1, LIMITS.lookbackDays);
|
|
125
141
|
const window = explicit
|
|
126
142
|
? (() => {
|
|
127
143
|
const after = whole(input.after, "after", 0, MAX_TIME);
|
|
128
|
-
const before = whole(input.before, "before", after + 1, MAX_TIME);
|
|
144
|
+
const before = whole(input.before ?? asOf ?? now, "before", after + 1, MAX_TIME);
|
|
129
145
|
if (before - after > LIMITS.lookbackDays * DAY)
|
|
130
146
|
fail(`window must not exceed ${LIMITS.lookbackDays} days`, "after");
|
|
131
147
|
return { after, before, asOf: asOf ?? before };
|
|
@@ -150,7 +166,7 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
150
166
|
sources.map(contextSourceKey),
|
|
151
167
|
input.scope,
|
|
152
168
|
lookbackDays,
|
|
153
|
-
explicit ? [window.after,
|
|
169
|
+
explicit ? [window.after, input.before ?? null] : null,
|
|
154
170
|
asOf,
|
|
155
171
|
fetch,
|
|
156
172
|
]))
|
|
@@ -168,6 +184,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
168
184
|
lookbackDays,
|
|
169
185
|
window,
|
|
170
186
|
fetch,
|
|
187
|
+
index,
|
|
188
|
+
around,
|
|
171
189
|
budgets,
|
|
172
190
|
fingerprint,
|
|
173
191
|
runKey,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ContextEvidenceItem, ContextEvidenceReader, ContextSource } from "../context/evidence.js";
|
|
1
|
+
import type { ContextEvidenceItem, ContextEvidenceReader, ContextIndex, ContextSource } from "../context/evidence.js";
|
|
2
|
+
import { type ProjectNeighbour, type ProjectNeighbourReader } from "./project-gathering-around.js";
|
|
2
3
|
import { type ProjectFetchState, type ProjectGatheringRequest, type ProjectLane } from "./project-gathering-request.js";
|
|
3
4
|
/** A connector's history fetch into the store; the store reads that follow find what it saved. */
|
|
4
5
|
export interface ProjectSourceFetcher {
|
|
@@ -15,8 +16,16 @@ export interface ProjectSourceFetcher {
|
|
|
15
16
|
export interface ProjectGatheringPorts {
|
|
16
17
|
evidence: ContextEvidenceReader;
|
|
17
18
|
fetcher?: ProjectSourceFetcher;
|
|
19
|
+
index?: ContextIndex;
|
|
20
|
+
neighbours?: ProjectNeighbourReader;
|
|
18
21
|
now?: () => number;
|
|
19
22
|
}
|
|
23
|
+
export interface ProjectIndexCatchUp {
|
|
24
|
+
state: "updated" | "as-is" | "unavailable" | "failed";
|
|
25
|
+
mail: number;
|
|
26
|
+
documents: number;
|
|
27
|
+
code: string | null;
|
|
28
|
+
}
|
|
20
29
|
export interface ProjectEvidenceItem extends Omit<ContextEvidenceItem, "text"> {
|
|
21
30
|
kind: ContextSource["kind"];
|
|
22
31
|
source: number;
|
|
@@ -24,6 +33,8 @@ export interface ProjectEvidenceItem extends Omit<ContextEvidenceItem, "text"> {
|
|
|
24
33
|
textTruncated: boolean;
|
|
25
34
|
lanes: string[];
|
|
26
35
|
context: "project" | "person-only";
|
|
36
|
+
around?: ProjectNeighbour[] | null;
|
|
37
|
+
aroundIssue?: string | null;
|
|
27
38
|
}
|
|
28
39
|
export type ProjectGatheringStop = "reads" | "read-bytes" | "elapsed" | "items" | null;
|
|
29
40
|
export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, request: ProjectGatheringRequest) => Promise<{
|
|
@@ -33,6 +44,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
33
44
|
resumed: boolean;
|
|
34
45
|
project: {
|
|
35
46
|
name: string;
|
|
47
|
+
key: string | null;
|
|
36
48
|
background: string | null;
|
|
37
49
|
aliases: string[];
|
|
38
50
|
};
|
|
@@ -55,6 +67,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
55
67
|
code: string | null;
|
|
56
68
|
source: number;
|
|
57
69
|
}[];
|
|
70
|
+
index: ProjectIndexCatchUp;
|
|
58
71
|
units: {
|
|
59
72
|
lane: string;
|
|
60
73
|
source: number;
|
|
@@ -72,6 +85,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
72
85
|
usage: {
|
|
73
86
|
reads: number;
|
|
74
87
|
readBytes: number;
|
|
88
|
+
aroundBytes: number;
|
|
75
89
|
items: number;
|
|
76
90
|
elapsedMs: number;
|
|
77
91
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { createContextEvidenceReader } from "./context-evidence.js";
|
|
3
3
|
import { excerpt } from "./excerpt.js";
|
|
4
|
+
import { attachNeighbours } from "./project-gathering-around.js";
|
|
4
5
|
import { decodeCheckpoint, encodeCheckpoint, projectGatheringRequest, projectUnits, seenKey, } from "./project-gathering-request.js";
|
|
5
6
|
const terminal = new Set(["done", "unavailable", "failed"]);
|
|
6
7
|
export const gatherProjectEvidence = async (ports, request) => {
|
|
@@ -12,6 +13,9 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
12
13
|
const previous = plan.checkpoint === undefined ? null : decodeCheckpoint(plan.checkpoint, plan);
|
|
13
14
|
const window = previous ?? plan.window;
|
|
14
15
|
const units = projectUnits(plan, window);
|
|
16
|
+
// A default that cannot finish one round would leave whole searches or sources unread; an explicit one is kept.
|
|
17
|
+
if (request.budgets?.maxReads === undefined)
|
|
18
|
+
plan.budgets.maxReads = Math.min(512, Math.max(48, units.length));
|
|
15
19
|
if (previous && (previous.units.length !== units.length || previous.fetched.length !== plan.sources.length))
|
|
16
20
|
throw new CliError("validation_error", "invalid project gathering checkpoint", { param: "checkpoint" });
|
|
17
21
|
const progress = previous?.units.map((u) => ({ ...u })) ??
|
|
@@ -43,7 +47,27 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
43
47
|
fetched[index] = { state: "failed", history: null, code: error.code };
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
const
|
|
50
|
+
const indexed = { state: "as-is", mail: 0, documents: 0, code: null };
|
|
51
|
+
const kinds = [...new Set(plan.sources.map((source) => source.kind))].filter((kind) => kind !== "message");
|
|
52
|
+
if (plan.index === "update" && kinds.length) {
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
if (!ports.index || typeof ports.index.catchUp !== "function")
|
|
55
|
+
indexed.state = "unavailable";
|
|
56
|
+
else
|
|
57
|
+
try {
|
|
58
|
+
const done = await ports.index.catchUp({ kinds, signal });
|
|
59
|
+
if (!Number.isSafeInteger(done?.mail) || !Number.isSafeInteger(done?.documents))
|
|
60
|
+
throw new CliError("invalid_response", "index catch-up returned invalid counts");
|
|
61
|
+
Object.assign(indexed, { state: "updated", mail: done.mail, documents: done.documents });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
signal?.throwIfAborted();
|
|
65
|
+
if (!(error instanceof CliError))
|
|
66
|
+
throw error;
|
|
67
|
+
Object.assign(indexed, { state: "failed", code: error.code });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const usage = { reads: 0, readBytes: 0, aroundBytes: 0, items: 0 };
|
|
47
71
|
const items = [];
|
|
48
72
|
const byRef = new Map();
|
|
49
73
|
const matchedAgain = new Map();
|
|
@@ -145,6 +169,12 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
145
169
|
}
|
|
146
170
|
}
|
|
147
171
|
}
|
|
172
|
+
await attachNeighbours(items, ports.neighbours, plan.around, {
|
|
173
|
+
remaining: () => plan.budgets.maxReadBytes - usage.readBytes - usage.aroundBytes,
|
|
174
|
+
charge: (bytes) => {
|
|
175
|
+
usage.aroundBytes += bytes;
|
|
176
|
+
},
|
|
177
|
+
}, (ref) => byRef.has(ref) || seen.has(seenKey(ref)), signal);
|
|
148
178
|
const totals = {
|
|
149
179
|
reads: (previous?.totals.reads ?? 0) + usage.reads,
|
|
150
180
|
readBytes: (previous?.totals.readBytes ?? 0) + usage.readBytes,
|
|
@@ -181,6 +211,7 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
181
211
|
scope: { origin: plan.scope, sources: plan.sources },
|
|
182
212
|
lanes: plan.lanes,
|
|
183
213
|
fetch: fetched.map((f, index) => ({ source: index, ...f })),
|
|
214
|
+
index: indexed,
|
|
184
215
|
units: units.map((unit, index) => ({
|
|
185
216
|
lane: unit.lane.id,
|
|
186
217
|
source: unit.sourceIndex,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { type ContextEvidenceReader } from "../../context/evidence.js";
|
|
1
|
+
import { type ContextEvidenceReader, type ContextIndex } from "../../context/evidence.js";
|
|
2
|
+
import type { Stemmer, Stemmers } from "../../search/stem.js";
|
|
2
3
|
import type { StoreContext } from "./open.js";
|
|
3
4
|
/** No index fills, model loads or record hydration outside the read transaction. */
|
|
4
5
|
export declare const contextEvidenceOver: ({ database }: Pick<StoreContext, "database">) => ContextEvidenceReader;
|
|
6
|
+
/** The same fills a mail search and the notes search run before reading; a message is indexed when it is saved. */
|
|
7
|
+
export declare const contextIndexOver: ({ database }: Pick<StoreContext, "database">, stemmerFor: (stemmers: Stemmers) => Stemmer) => ContextIndex;
|
|
@@ -3,6 +3,8 @@ import { contextCursorScope, contextEvidenceRequest, } from "../../context/evide
|
|
|
3
3
|
import { formatLocator } from "../../domain/locator.js";
|
|
4
4
|
import { NORMALIZER_VERSION, normalize } from "../normalize.js";
|
|
5
5
|
import { contextDocumentTime, contextDocumentTimeKind, contextDocumentUrl } from "./context-document-source.js";
|
|
6
|
+
import { drainEmailIndex } from "./email-index.js";
|
|
7
|
+
import { drainNoteIndex } from "./note-index.js";
|
|
6
8
|
import { read } from "./transaction.js";
|
|
7
9
|
const corpora = {
|
|
8
10
|
message: {
|
|
@@ -163,3 +165,13 @@ export const contextEvidenceOver = ({ database }) => ({
|
|
|
163
165
|
});
|
|
164
166
|
},
|
|
165
167
|
});
|
|
168
|
+
/** The same fills a mail search and the notes search run before reading; a message is indexed when it is saved. */
|
|
169
|
+
export const contextIndexOver = ({ database }, stemmerFor) => ({
|
|
170
|
+
async catchUp({ kinds, signal }) {
|
|
171
|
+
signal?.throwIfAborted();
|
|
172
|
+
const mail = kinds.includes("mail") ? drainEmailIndex(database, stemmerFor) : 0;
|
|
173
|
+
signal?.throwIfAborted();
|
|
174
|
+
const documents = kinds.includes("document") ? drainNoteIndex(database, stemmerFor) : 0;
|
|
175
|
+
return { mail, documents };
|
|
176
|
+
},
|
|
177
|
+
});
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextEvidenceReader } from "../context/evidence.js";
|
|
1
|
+
import type { ContextEvidenceReader, ContextIndex } from "../context/evidence.js";
|
|
2
2
|
import { type AccountStore } from "./account-store.js";
|
|
3
3
|
import { type AccountsStore } from "./accounts.js";
|
|
4
4
|
import { type AttachmentsStore } from "./attachments.js";
|
|
@@ -34,6 +34,7 @@ import type { AccountKey } from "./types.js";
|
|
|
34
34
|
import { type VectorsStore } from "./vectors.js";
|
|
35
35
|
export interface MessageStore {
|
|
36
36
|
readonly contextEvidence?: ContextEvidenceReader;
|
|
37
|
+
readonly contextIndex?: ContextIndex;
|
|
37
38
|
/** Accounts, account groups and which account each app profile is. */
|
|
38
39
|
readonly accounts: AccountsStore;
|
|
39
40
|
/** One account's chats: the list, what left, what is complete, their metadata. */
|
package/dist/store/store.js
CHANGED
|
@@ -16,7 +16,7 @@ import { agentActionsStoreOver } from "./sqlite/agent-actions.js";
|
|
|
16
16
|
import * as attachmentTexts from "./sqlite/attachment-texts.js";
|
|
17
17
|
import { botUpdateStoreOver } from "./sqlite/bot-updates.js";
|
|
18
18
|
import { catalogStoreOver } from "./sqlite/catalog.js";
|
|
19
|
-
import { contextEvidenceOver } from "./sqlite/context-evidence.js";
|
|
19
|
+
import { contextEvidenceOver, contextIndexOver } from "./sqlite/context-evidence.js";
|
|
20
20
|
import { mailStoreOver } from "./sqlite/emails.js";
|
|
21
21
|
import { factsStoreOver } from "./sqlite/facts.js";
|
|
22
22
|
import { involvementStoreOver } from "./sqlite/involvements.js";
|
|
@@ -81,6 +81,7 @@ const storeOver = (context) => {
|
|
|
81
81
|
mentions: areaOf(() => accountMentionsOver(context), (keyed) => mentionsStoreOver(context, keyed)),
|
|
82
82
|
};
|
|
83
83
|
const contextEvidence = once(() => contextEvidenceOver(context));
|
|
84
|
+
const contextIndex = once(() => contextIndexOver(context, stemmerFor));
|
|
84
85
|
const searches = once(() => searchesStoreOver(context));
|
|
85
86
|
const queries = once(() => queriesStoreOver(context, stemmerFor));
|
|
86
87
|
const searchIndex = once(() => searchIndexStoreOver(context));
|
|
@@ -101,6 +102,9 @@ const storeOver = (context) => {
|
|
|
101
102
|
get contextEvidence() {
|
|
102
103
|
return contextEvidence();
|
|
103
104
|
},
|
|
105
|
+
get contextIndex() {
|
|
106
|
+
return contextIndex();
|
|
107
|
+
},
|
|
104
108
|
meetingVectors: meetingVectorsOver(context),
|
|
105
109
|
get accounts() {
|
|
106
110
|
return areas.accounts().whole;
|
|
@@ -19,8 +19,11 @@ export interface LoginQrOptions {
|
|
|
19
19
|
}
|
|
20
20
|
export interface LoginQr {
|
|
21
21
|
readonly path: string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
|
|
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.
|
|
3
|
+
"version": "0.350.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",
|
package/parity.json
CHANGED
|
@@ -4053,12 +4053,7 @@
|
|
|
4053
4053
|
"in": ["tg"],
|
|
4054
4054
|
"reason": "Telegram asks each client for its own app from my.telegram.org; MAX has no such step; WhatsApp has no application registration"
|
|
4055
4055
|
},
|
|
4056
|
-
"--qr-file":
|
|
4057
|
-
"in": ["tg", "wa"],
|
|
4058
|
-
"planned": {
|
|
4059
|
-
"max": "max-cli#736, on the cli-core release that exports loginQr"
|
|
4060
|
-
}
|
|
4061
|
-
},
|
|
4056
|
+
"--qr-file": "all",
|
|
4062
4057
|
"--sms": {
|
|
4063
4058
|
"in": ["tg"],
|
|
4064
4059
|
"reason": "asks Telegram to resend its login code by SMS; MAX has no such choice; WhatsApp links a device by QR or pairing code, never by an SMS code"
|
|
@@ -4074,12 +4069,7 @@
|
|
|
4074
4069
|
"reason": "Telegram requires an application from my.telegram.org; MAX has no application registration step; WhatsApp has no application registration"
|
|
4075
4070
|
},
|
|
4076
4071
|
"--method": "all",
|
|
4077
|
-
"--qr-file":
|
|
4078
|
-
"in": ["tg", "wa"],
|
|
4079
|
-
"planned": {
|
|
4080
|
-
"max": "max-cli#736, on the cli-core release that exports loginQr"
|
|
4081
|
-
}
|
|
4082
|
-
}
|
|
4072
|
+
"--qr-file": "all"
|
|
4083
4073
|
}
|
|
4084
4074
|
},
|
|
4085
4075
|
"skill": {
|