@wirecat/cli-core 0.637.0 → 0.638.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 +17 -0
- package/dist/search/lucene/registry.js +10 -0
- package/dist/sends/pace.js +21 -13
- package/dist/store/sqlite/lucene-fields.js +15 -0
- package/dist/store/sqlite/mail-findings.js +24 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.638.0 — 11.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`participants_count` in the query language.** `participants_count<10` matches messages in chats of fewer than ten
|
|
13
|
+
people, as the messenger last reported the size; a chat whose size was never reported matches no value. So
|
|
14
|
+
`stats messages show 'kind:private OR (kind:group participants_count<10)'` counts personal conversations and leaves
|
|
15
|
+
big groups out.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **A new contact from mail needs a name the mail's text adds.** A `new_contact` finding whose name only repeats what the store has from the sender line is refused (`new-contact.sender-line`), and so is one whose name is not in the text of the mail it cites (`new-contact.not-in-text`). A name copied from a header is metadata, not something for the owner to review. Batches already waiting stay as they are until decided.
|
|
20
|
+
- **A clock stepped back no longer leaves a profile waiting for hours.** The request pace now keeps when it wrote its
|
|
21
|
+
file, and corrects a wait written "in the future" by the size of the step: a computer that booted with its clock three hours ahead refused
|
|
22
|
+
every sync for three hours once NTP corrected it. The refusal also stops saying the messenger asked for the wait,
|
|
23
|
+
which it could not know.
|
|
24
|
+
|
|
8
25
|
## 0.637.0 — 11.11.2026
|
|
9
26
|
|
|
10
27
|
### Fixed
|
|
@@ -200,6 +200,16 @@ export const QUERY_FIELDS = [
|
|
|
200
200
|
support: "A1",
|
|
201
201
|
values: ["true", "false"],
|
|
202
202
|
},
|
|
203
|
+
{
|
|
204
|
+
name: "participants_count",
|
|
205
|
+
example: "participants_count<10",
|
|
206
|
+
index: "chats.participants_count",
|
|
207
|
+
aliases: [],
|
|
208
|
+
type: "num",
|
|
209
|
+
operators: [...terms, "range"],
|
|
210
|
+
normalization: "a whole number; a chat whose size the messenger never told matches no value",
|
|
211
|
+
support: "A1",
|
|
212
|
+
},
|
|
203
213
|
{
|
|
204
214
|
name: "has",
|
|
205
215
|
example: "has:file",
|
package/dist/sends/pace.js
CHANGED
|
@@ -25,12 +25,13 @@ export class Pacer {
|
|
|
25
25
|
}
|
|
26
26
|
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
27
27
|
async reserve() {
|
|
28
|
-
const now = this.now();
|
|
29
28
|
if (this.interval === 0)
|
|
30
|
-
return now;
|
|
29
|
+
return this.now();
|
|
31
30
|
return withFileLockAsync(this.path, "the request pace", () => {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// Inside the lock: read earlier, another process's write would look like a clock step.
|
|
32
|
+
const now = this.now();
|
|
33
|
+
const tat = Math.max(this.read(now), now);
|
|
34
|
+
this.write(tat + this.interval, now);
|
|
34
35
|
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -39,26 +40,33 @@ export class Pacer {
|
|
|
39
40
|
if (this.interval === 0)
|
|
40
41
|
return;
|
|
41
42
|
await withFileLockAsync(this.path, "the request pace", () => {
|
|
42
|
-
const
|
|
43
|
-
this.
|
|
43
|
+
const now = this.now();
|
|
44
|
+
const hold = now + waitMs + this.rate.burst * this.interval;
|
|
45
|
+
this.write(Math.max(this.read(now), hold), now);
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
/** The owner's `flood clear`: every process may go again at once. */
|
|
47
49
|
async reset() {
|
|
48
|
-
await withFileLockAsync(this.path, "the request pace", () => this.write(0));
|
|
50
|
+
await withFileLockAsync(this.path, "the request pace", () => this.write(0, this.now()));
|
|
49
51
|
}
|
|
50
|
-
read() {
|
|
52
|
+
read(now) {
|
|
51
53
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
+
const file = JSON.parse(readFileSync(this.path, "utf8"));
|
|
55
|
+
const tat = Number(file.tat);
|
|
56
|
+
if (!Number.isFinite(tat))
|
|
57
|
+
return 0;
|
|
58
|
+
const at = Number(file.at);
|
|
59
|
+
// Written "in the future" means the clock went back since, as when a machine boots ahead and NTP steps it. What
|
|
60
|
+
// was left of the wait still holds; the absolute time, hours off, does not.
|
|
61
|
+
return Number.isFinite(at) && at > now ? now + Math.max(0, tat - at) : tat;
|
|
54
62
|
}
|
|
55
63
|
catch {
|
|
56
64
|
return 0;
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
|
-
write(tat) {
|
|
67
|
+
write(tat, at) {
|
|
60
68
|
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
61
|
-
writeFileSync(temporary, JSON.stringify({ tat }), { mode: 0o600 });
|
|
69
|
+
writeFileSync(temporary, JSON.stringify({ tat, at }), { mode: 0o600 });
|
|
62
70
|
renameSync(temporary, this.path);
|
|
63
71
|
}
|
|
64
72
|
}
|
|
@@ -89,7 +97,7 @@ export const waitForTurn = async (pacer, options) => {
|
|
|
89
97
|
if (waitMs <= 0)
|
|
90
98
|
return;
|
|
91
99
|
if (waitMs > LONGEST_PACE_WAIT_MS)
|
|
92
|
-
throw new CliError("rate_limited",
|
|
100
|
+
throw new CliError("rate_limited", `this profile's next request to ${name} has to wait ${Math.ceil(waitMs / 1000)} s more — nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
93
101
|
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
94
102
|
const seconds = Math.ceil(waitMs / 1000);
|
|
95
103
|
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
|
@@ -347,6 +347,20 @@ const topic = messengerOnly(({ value }) => always(bound("m.thread_external_id =
|
|
|
347
347
|
/** What `kind:` matches for a chat aliased `c`: private, saved, bot, service, group, channel or unknown. */
|
|
348
348
|
export const PEER_KIND = "CASE WHEN json_extract(c.metadata,'$.peerKind') IN ('private','saved','bot','service','group','channel','unknown') THEN json_extract(c.metadata,'$.peerKind') WHEN c.kind='dialog' AND json_extract(c.metadata,'$.isBot')=1 THEN 'bot' WHEN c.kind='dialog' THEN 'private' ELSE c.kind END";
|
|
349
349
|
const kind = messengerOnly(({ value }) => always(bound(`${PEER_KIND} = ?`, value.toLowerCase())));
|
|
350
|
+
/** How many people a chat has, as the messenger last said; a chat with no known size matches no value. */
|
|
351
|
+
const participantsCount = messengerOnly((node) => {
|
|
352
|
+
const { operator, value, upper } = node;
|
|
353
|
+
const column = "c.participants_count";
|
|
354
|
+
if (operator !== "range")
|
|
355
|
+
return always(bound(`${column} = ?`, Number(value)));
|
|
356
|
+
const conditions = [
|
|
357
|
+
...(value === "*" ? [] : [bound(`${column} ${node.lower_inclusive ? ">=" : ">"} ?`, Number(value))]),
|
|
358
|
+
...(upper === undefined || upper === "*"
|
|
359
|
+
? []
|
|
360
|
+
: [bound(`${column} ${node.upper_inclusive ? "<=" : "<"} ?`, Number(upper))]),
|
|
361
|
+
];
|
|
362
|
+
return always(combine(conditions, "AND"));
|
|
363
|
+
});
|
|
350
364
|
/** A chat the owner muted, until its mute runs out; a chat whose messenger keeps no mute is not muted. */
|
|
351
365
|
const muted = messengerOnly(({ value }) => always(bound(`${value.toLowerCase() === "true" ? "" : "NOT "}(coalesce(c.muted, 0) = 1 AND (c.muted_until IS NULL OR c.muted_until > ?))`, Date.now())));
|
|
352
366
|
const has = ({ value }, { corpus, mail }) => {
|
|
@@ -443,6 +457,7 @@ export const FIELD_COMPILERS = {
|
|
|
443
457
|
topic,
|
|
444
458
|
kind,
|
|
445
459
|
muted,
|
|
460
|
+
participants_count: participantsCount,
|
|
446
461
|
has,
|
|
447
462
|
in: inSourceField,
|
|
448
463
|
to: recipient,
|
|
@@ -28,6 +28,9 @@ const invalid = (message, reason) => {
|
|
|
28
28
|
throw new CliError("validation_error", message, reason ? { reason } : undefined);
|
|
29
29
|
};
|
|
30
30
|
const TEXT_BUDGET = 262144;
|
|
31
|
+
const wordsOf = (text) => fold(text)
|
|
32
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
33
|
+
.filter(Boolean);
|
|
31
34
|
const EMAIL = `SELECT e.id, e.account_id, e.subject, coalesce(e.body_text, '') AS body,
|
|
32
35
|
json_extract(e.metadata, '$.partial') IS NOT NULL AS partial, lower(e.from_address) AS sender,
|
|
33
36
|
coalesce(e.outgoing, lower(e.from_address) = lower(a.external_id)) AS outgoing
|
|
@@ -227,6 +230,26 @@ export const mailFindingsStoreOver = (context) => {
|
|
|
227
230
|
`SELECT 1 FROM email_recipients WHERE email_id IN (${marks}) AND lower(address) = ? LIMIT 1`)
|
|
228
231
|
.get(...ids, address, ...ids, address));
|
|
229
232
|
};
|
|
233
|
+
/** Every name the store already has for `address`: the sender and recipient lines of any mail, its identity, its person. */
|
|
234
|
+
const namesOnRecord = (address) => database
|
|
235
|
+
.prepare("SELECT from_name AS name FROM emails WHERE lower(from_address) = ? AND from_name IS NOT NULL UNION " +
|
|
236
|
+
"SELECT name FROM email_recipients WHERE lower(address) = ? AND name IS NOT NULL UNION " +
|
|
237
|
+
"SELECT i.name FROM identities i WHERE i.provider = 'email' AND lower(i.external_id) = ? AND i.name IS NOT NULL UNION " +
|
|
238
|
+
"SELECT p.name FROM identities i JOIN identity_links l ON l.identity_id = i.id JOIN persons p ON p.id = l.person_id " +
|
|
239
|
+
"WHERE i.provider = 'email' AND lower(i.external_id) = ? AND p.name IS NOT NULL")
|
|
240
|
+
.all(address, address, address, address)
|
|
241
|
+
.map((row) => String(row.name));
|
|
242
|
+
/** The owner ruled a name copied from a sender line is metadata: only one the mail's own text adds is worth asking. */
|
|
243
|
+
const requireBetterName = (finding, read) => {
|
|
244
|
+
const name = wordsOf(finding.name);
|
|
245
|
+
const known = new Set(namesOnRecord(finding.address).flatMap(wordsOf));
|
|
246
|
+
if (name.every((word) => known.has(word)))
|
|
247
|
+
return invalid(`the name of new contact ${finding.address} adds nothing to the name the store has from its mail; leave it out`, "new-contact.sender-line");
|
|
248
|
+
const wanted = ` ${name.join(" ")} `;
|
|
249
|
+
const inText = finding.evidence.some(({ reference }) => ` ${wordsOf(String(read.get(reference)?.body)).join(" ")} `.includes(wanted));
|
|
250
|
+
if (!inText)
|
|
251
|
+
return invalid(`the name of new contact ${finding.address} is not in the text of the mail it cites; leave it out`, "new-contact.not-in-text");
|
|
252
|
+
};
|
|
230
253
|
/** A proposed findings batch that already holds this shop's order with this number. */
|
|
231
254
|
const proposedOrder = (supplierName, number) => {
|
|
232
255
|
const shop = fold(supplierName).trim();
|
|
@@ -289,6 +312,7 @@ export const mailFindingsStoreOver = (context) => {
|
|
|
289
312
|
return invalid(`${finding.address} neither sent nor received the mail finding ${finding.id} cites`);
|
|
290
313
|
if (!identityOfAddress(finding.address))
|
|
291
314
|
throw new CliError("not_found", `no stored contact ${finding.address}`);
|
|
315
|
+
requireBetterName(finding, read);
|
|
292
316
|
return;
|
|
293
317
|
}
|
|
294
318
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.638.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",
|