@wirecat/cli-core 0.349.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 +20 -0
- package/dist/cli/messenger/context.js +8 -1
- package/dist/cli/messenger/flooded.js +1 -1
- 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/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/terminal/login-qr.d.ts +5 -2
- package/dist/terminal/login-qr.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,26 @@ 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
|
+
|
|
10
30
|
## 0.349.0 — 19.10.2026
|
|
11
31
|
|
|
12
32
|
### 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"]);
|
|
@@ -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 {
|
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 {
|
|
@@ -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",
|