@wirecat/cli-core 0.740.0 → 0.741.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
|
@@ -5,6 +5,22 @@ 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.741.0 — 24.11.2026
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- `search all` and `deals list` find a CRM record whose Latin name is typed in Cyrillic: `феррара` finds Ferrara
|
|
13
|
+
Design, marked as corrected to `ferrara`, as message search already did (#3285).
|
|
14
|
+
- `search all` and `deals list` find a CRM record whose name is one letter off a query word that matched another
|
|
15
|
+
record: `Ferrara` finds Ferrara Design first and Ferraro Arredamenti after it, marked as a correction. A misspelt
|
|
16
|
+
word was corrected only when it matched nothing, so a near-duplicate hid the record asked for (#3285).
|
|
17
|
+
- **A picture OCR finds no text in is still found by what it shows.** With `picture_search` on and a scan reader
|
|
18
|
+
set, a photo with no text was kept by name only and got no picture vector, and the next sync downloaded and read it
|
|
19
|
+
by OCR again for the missing vector. It now gets its vector as a picture kept by name for its type does. Its reason
|
|
20
|
+
names the reading (`OCR found no text in the file (read by ocr:v1:tesseract@5.3.0:rus+eng)`), so another engine or
|
|
21
|
+
model reads it again, and the same one does not
|
|
22
|
+
([scans and pictures](docs/dev/DOCUMENTS.md#scans-and-pictures)).
|
|
23
|
+
|
|
8
24
|
## 0.740.0 — 24.11.2026
|
|
9
25
|
|
|
10
26
|
### Added
|
|
@@ -18,6 +18,9 @@ const PICTURES = new Set(["image/jpeg", "image/png", "image/webp"]);
|
|
|
18
18
|
const UNAVAILABLE = "scans are not read: ";
|
|
19
19
|
const LATER = "OCR page limit of this sync reached";
|
|
20
20
|
const BUSY = "OCR is unavailable for now";
|
|
21
|
+
const NO_TEXT = "OCR found no text in the file";
|
|
22
|
+
/** The reading that found no text, in the reason: another engine or model may find some, the same one would not. */
|
|
23
|
+
const readBy = (extractor) => ` (read by ${extractor})`;
|
|
21
24
|
/** Errors of a model that pass: the file is read on a later sync, not kept by name for good. */
|
|
22
25
|
const PASSING = new Set(["rate_limited", "timeout", "network_error", "provider_unavailable"]);
|
|
23
26
|
/** A picture OCR reads: what `ocrImage` takes. Other images (TIFF, HEIC) stay by name only. */
|
|
@@ -38,7 +41,8 @@ export const scanRetry = (reader, reason) => reader?.extractor !== undefined &&
|
|
|
38
41
|
(reason.startsWith(NO_TEXT_LAYER) ||
|
|
39
42
|
reason.startsWith(UNAVAILABLE) ||
|
|
40
43
|
reason.startsWith(LATER) ||
|
|
41
|
-
reason.startsWith(BUSY)
|
|
44
|
+
reason.startsWith(BUSY) ||
|
|
45
|
+
(reason.startsWith(NO_TEXT) && !reason.endsWith(readBy(reader.extractor))));
|
|
42
46
|
const refusing = (why) => ({
|
|
43
47
|
read: async () => {
|
|
44
48
|
throw new CliError("validation_error", `${UNAVAILABLE}${why}`, { reason: "document.scan-unread" });
|
|
@@ -56,12 +60,12 @@ const modelPipeline = (choice, deps) => {
|
|
|
56
60
|
: `pictures may not go to ${setting.model} yet; allow them with \`ai set --images\``;
|
|
57
61
|
return reader.pipeline;
|
|
58
62
|
};
|
|
59
|
-
const reasonOf = (status, error) => status === "too-large"
|
|
63
|
+
const reasonOf = (extractor, status, error) => status === "too-large"
|
|
60
64
|
? `scan is over ${SCAN_PAGES_PER_FILE} pages, or a page is too large to read`
|
|
61
65
|
: status === "needs-agent"
|
|
62
66
|
? "picture is too large to read"
|
|
63
67
|
: error === "empty_answer"
|
|
64
|
-
?
|
|
68
|
+
? `${NO_TEXT}${readBy(extractor)}`
|
|
65
69
|
: "OCR could not read the file";
|
|
66
70
|
const later = (why) => new CliError("validation_error", why, { reason: "document.scan-later" });
|
|
67
71
|
/**
|
|
@@ -128,7 +132,7 @@ export const scanReader = async (choice, deps, load = importEngine, pagesPerSync
|
|
|
128
132
|
});
|
|
129
133
|
if (read.status === "unreadable" && (read.error === "rate_limited" || PASSING.has(read.issue?.code ?? "")))
|
|
130
134
|
throw later(`${BUSY}; the next sync tries again`);
|
|
131
|
-
throw new CliError("validation_error", reasonOf(read.status, read.status === "unreadable" ? read.error : undefined), {
|
|
135
|
+
throw new CliError("validation_error", reasonOf(pipeline.extractor, read.status, read.status === "unreadable" ? read.error : undefined), {
|
|
132
136
|
reason: "document.scan-unread",
|
|
133
137
|
});
|
|
134
138
|
},
|
|
@@ -287,8 +287,12 @@ export const syncDocuments = async (options) => {
|
|
|
287
287
|
...(safe.details.text_limit ? { textLimit: limit } : {}),
|
|
288
288
|
...(safe.details.store_refused_in ? { storeRefusedIn: VERSION } : {}),
|
|
289
289
|
};
|
|
290
|
-
|
|
290
|
+
let stop = null;
|
|
291
|
+
if (job.file && safe.code === "validation_error") {
|
|
291
292
|
await saveNamesOnly(job.file, skipped.reason);
|
|
293
|
+
// A picture OCR could not read is still found by what it shows.
|
|
294
|
+
stop = await savePictureOf(job.file);
|
|
295
|
+
}
|
|
292
296
|
else {
|
|
293
297
|
// A 404 or a refusal says the sign-in cannot read it now, not that it is gone: its text stays.
|
|
294
298
|
await index.remove(profile.principal, job.id, "unavailable");
|
|
@@ -298,6 +302,10 @@ export const syncDocuments = async (options) => {
|
|
|
298
302
|
state.skipped = state.skipped.filter((item) => item.id !== job.id);
|
|
299
303
|
state.skipped.push(skipped);
|
|
300
304
|
result.skipped.push({ id: skipped.id, reason: skipped.reason });
|
|
305
|
+
if (stop) {
|
|
306
|
+
result.stopped = stop;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
301
309
|
pending.jobs = pending.jobs.filter((item) => item !== job);
|
|
302
310
|
progress();
|
|
303
311
|
continue;
|
|
@@ -206,7 +206,10 @@ export type DealPart = "title" | "company" | "contact" | "activity";
|
|
|
206
206
|
export interface FoundDeal extends Deal {
|
|
207
207
|
/** Where the query's words were found, in the order of `DealPart`. */
|
|
208
208
|
matched: DealPart[];
|
|
209
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Set when nothing matched as typed, or on a hit found only through a name one letter off a query word that did
|
|
211
|
+
* match elsewhere: each query word that was corrected, and the stored words it became.
|
|
212
|
+
*/
|
|
210
213
|
corrections?: {
|
|
211
214
|
from: string;
|
|
212
215
|
to: string[];
|
|
@@ -4,7 +4,8 @@ import { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, dealLine, STAGE_OUTCOMES, } from
|
|
|
4
4
|
import { dayIn } from "../../domain/moment.js";
|
|
5
5
|
import { currencyOf, formatDecimal, minorUnits, scaleOf } from "../../domain/money.js";
|
|
6
6
|
import { notOverriddenSql } from "../../domain/relations.js";
|
|
7
|
-
import {
|
|
7
|
+
import { editDistance } from "../../search/correct.js";
|
|
8
|
+
import { respelled } from "../../search/respell.js";
|
|
8
9
|
import { clauseIn, probeOf, tokensOf, wordMatches } from "../../search/word-match.js";
|
|
9
10
|
import { fold } from "../normalize.js";
|
|
10
11
|
import { proposedBySql } from "./actors.js";
|
|
@@ -54,6 +55,8 @@ const providerMetadataOf = (metadata) => {
|
|
|
54
55
|
};
|
|
55
56
|
const accountOf = (provider, external) => provider == null ? null : { provider: String(provider), account: String(external) };
|
|
56
57
|
const DEAL_PARTS = ["title", "company", "contact", "activity"];
|
|
58
|
+
/** Below five letters one edit turns too many names into each other (Ivan, Ivas). */
|
|
59
|
+
const NEAR_NAME = 5;
|
|
57
60
|
const listOf = (json) => {
|
|
58
61
|
if (typeof json !== "string")
|
|
59
62
|
return [];
|
|
@@ -520,21 +523,48 @@ export const dealOperationsOver = (context) => {
|
|
|
520
523
|
.flat()
|
|
521
524
|
.filter((probe) => ![...stored.values()].some((word) => wordMatches(probe, word, false)))
|
|
522
525
|
.map(({ literal }) => literal);
|
|
523
|
-
|
|
526
|
+
// A name typed in Cyrillic (феррара) stands for the Latin one the CRM holds (Ferrara), as in messages.
|
|
527
|
+
const fixes = unmatched.length ? await respelled(vocabulary, [...new Set(unmatched)]) : new Map();
|
|
524
528
|
if (fixes.size) {
|
|
525
529
|
corrections = [...fixes].map(([from, to]) => ({ from, to }));
|
|
526
530
|
found = search(queryWith(fixes));
|
|
527
531
|
}
|
|
528
532
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
+
// A name one letter off another that matched (Ferrara, Ferraro) comes after the exact hits, as a correction:
|
|
534
|
+
// the correction above runs only when nothing matched, so a near-duplicate would hide the record asked for.
|
|
535
|
+
let near = [];
|
|
536
|
+
const nearFixes = new Map();
|
|
537
|
+
if (found.length && !exact) {
|
|
538
|
+
const names = new Set();
|
|
539
|
+
for (const { parts } of records)
|
|
540
|
+
for (const { part, words: held } of parts)
|
|
541
|
+
if (part !== "activity")
|
|
542
|
+
for (const word of held)
|
|
543
|
+
if (word.literal.length >= NEAR_NAME)
|
|
544
|
+
names.add(word.literal);
|
|
545
|
+
for (const literal of new Set(probes.flat().map((probe) => probe.literal))) {
|
|
546
|
+
if (literal.length < NEAR_NAME)
|
|
547
|
+
continue;
|
|
548
|
+
const close = [...names].filter((name) => name !== literal && editDistance(literal, name, 1) === 1);
|
|
549
|
+
if (close.length)
|
|
550
|
+
nearFixes.set(literal, close.slice(0, 5));
|
|
551
|
+
}
|
|
552
|
+
if (nearFixes.size) {
|
|
553
|
+
const held = new Set(found.map(({ row }) => row));
|
|
554
|
+
near = search(queryWith(nearFixes)).filter(({ row }) => !held.has(row));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const byScore = (a, b) => b.score - a.score || Number(b.row.updated_at) - Number(a.row.updated_at) || Number(b.row.id) - Number(a.row.id);
|
|
558
|
+
const nearCorrections = [...nearFixes].map(([from, to]) => ({ from, to }));
|
|
559
|
+
const ranked = [
|
|
560
|
+
...found.sort(byScore).map((one) => ({ ...one, fixes: corrections })),
|
|
561
|
+
...near.sort(byScore).map((one) => ({ ...one, fixes: nearCorrections })),
|
|
562
|
+
]
|
|
533
563
|
.slice(offset, offset + most + 1)
|
|
534
|
-
.map(({ kind, row, matched }) => ({
|
|
564
|
+
.map(({ kind, row, matched, fixes }) => ({
|
|
535
565
|
...read(`${kind}:${row.id}`),
|
|
536
566
|
matched,
|
|
537
|
-
...(
|
|
567
|
+
...(fixes ? { corrections: fixes } : {}),
|
|
538
568
|
}));
|
|
539
569
|
return pageOfRows(ranked, most, offset);
|
|
540
570
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.741.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",
|