@wirecat/cli-core 0.749.0 → 0.751.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 +62 -0
- package/dist/attachments/tesseract.d.ts +4 -1
- package/dist/attachments/tesseract.js +13 -4
- package/dist/background/report/render.js +1 -1
- package/dist/cli/documents/library.js +2 -0
- package/dist/crm/cli/index.js +1 -1
- package/dist/crm/source.d.ts +5 -0
- package/dist/crm/sync.d.ts +3 -1
- package/dist/crm/sync.js +31 -3
- package/dist/crm/testing/files-contract.js +5 -2
- package/dist/domain/tracker.d.ts +27 -6
- package/dist/domain/tracker.js +13 -8
- package/dist/errors/reasons.js +11 -0
- package/dist/services/documents/scans.d.ts +2 -0
- package/dist/services/documents/scans.js +3 -0
- package/dist/store/sqlite/crm-activities.d.ts +14 -0
- package/dist/store/sqlite/crm-activities.js +25 -1
- package/dist/store/sqlite/crm.d.ts +3 -5
- package/dist/store/sqlite/crm.js +2 -2
- package/dist/store/sqlite/tracker.d.ts +6 -2
- package/dist/store/sqlite/tracker.js +72 -5
- package/dist/tracker/cli/index.js +21 -8
- package/dist/tracker/manifest/manifest.d.ts +4 -1
- package/dist/tracker/manifest/manifest.js +4 -1
- package/dist/tracker/manifest/map.js +19 -1
- package/dist/tracker/manifest/source.js +5 -1
- package/dist/tracker/sync.d.ts +9 -0
- package/dist/tracker/sync.js +8 -2
- package/dist/tracker/tasks.d.ts +4 -4
- package/dist/tracker/tasks.js +6 -5
- package/dist/tracker/testing/manifest-fake.d.ts +2 -0
- package/dist/tracker/testing/manifest-fake.js +20 -0
- package/dist/tracker/testing/source-contract.d.ts +8 -0
- package/dist/tracker/testing/source-contract.js +28 -2
- package/dist/tracker/testing/source.d.ts +9 -1
- package/dist/tracker/testing/source.js +25 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,68 @@ 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.751.0 — 25.11.2026
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **A note or task deleted in the CRM leaves the copy.** The sync kept every activity it had once stored. It now marks
|
|
13
|
+
deleted the ones a source's page names in `removed`. A source that lists every activity on each run sets
|
|
14
|
+
`listedAll` on its last page, and then a stored activity it did not list is marked deleted too, when the round was
|
|
15
|
+
read whole and no list was refused. A list that would mark most of ten or more is held with
|
|
16
|
+
`crm.activities-unlisted-held` until `sync --rescan`. `sync` counts them in `activities.removed`
|
|
17
|
+
([CRM](docs/dev/CRM.md#activities-changes-and-the-digest)).
|
|
18
|
+
|
|
19
|
+
## 0.750.0 — 24.11.2026
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **A digest's page file names what was left out.** `<run>.report.json` lists in `dropped` the parts the check
|
|
24
|
+
left out, so WireCat Desktop can say how many it does not show.
|
|
25
|
+
- **Trackers copy sprints.** `sprint` is a tracker kind, between `project` and `issue` in `TRACKER_KINDS`: a Linear
|
|
26
|
+
cycle or a Jira sprint, with its `name`, `number`, `team`, `startsAt`, `endsAt` and `completedAt`. An issue names
|
|
27
|
+
its `sprint`. `sprints list` lists them, and `issues list sprint:<id>` (or `sprint:none`) narrows the issues. An
|
|
28
|
+
unnamed sprint, as most Linear cycles are, is titled `Sprint <number>`. A manifest without a sprint kind syncs as
|
|
29
|
+
before ([docs](docs/dev/TRACKER.md#the-domain)).
|
|
30
|
+
- **An issue in the tracker's trash leaves the copy.** A map may read `deleted` (Linear's `trashed`). A row read as
|
|
31
|
+
deleted is marked deleted in the copy, and its `ids` call, which selects the same path, leaves it out, so the daily
|
|
32
|
+
id pass finds it: Linear's trash moves no `updatedAt`, so a plain read of changes never sees it. An issue marked
|
|
33
|
+
deleted takes its comments with it. A row the id pass lists again after it was marked deleted, as an issue restored
|
|
34
|
+
from the trash, is back with its comments. `trackerSourceContract` checks a
|
|
35
|
+
`trash` fault, which `trackerManifestFixture` offers when the map reads `deleted`
|
|
36
|
+
([docs](docs/dev/TRACKER.md#deleted-and-trashed-rows)).
|
|
37
|
+
- **The `duplicate` state type.** Linear's Duplicate state was dropped by the map, so its issues pointed at a state the
|
|
38
|
+
copy did not hold. It is now one of `STATE_TYPES`, closed as `canceled` is: a task from such an issue closes as
|
|
39
|
+
dismissed, `the issue was marked a duplicate in linear`, and `issues list type:duplicate` finds them.
|
|
40
|
+
- **A tracker sync says when it next looks for deletions and what it could not read.** Its answer has
|
|
41
|
+
`deletions: { checked, due }`, when the id pass last ran for every kind and when it is next due. A kind the sign-in
|
|
42
|
+
could not read is named in `meta.issues` (`tracker.kind-unread`) besides `gaps`.
|
|
43
|
+
|
|
44
|
+
### Changed — may break callers
|
|
45
|
+
|
|
46
|
+
- **`synced[].saved` and `progress.saved` count only rows that changed** in the copy: new, different, deleted or back
|
|
47
|
+
again. A row read again as stored is not counted, so a sync with nothing new answers 0 and Desktop shows it up to
|
|
48
|
+
date. `store.tracker.save` answers the same count.
|
|
49
|
+
- **`TrackerRecords` and `TRACKER_KINDS` have `sprint`, and `STATE_TYPES` has `duplicate`.** Code with a value for
|
|
50
|
+
each kind or state type, such as a `Record<TrackerKind, …>` or a `switch` over `StateType`, needs one for the new
|
|
51
|
+
member; `exampleTrackerRows()` has a sprint and a Duplicate state.
|
|
52
|
+
- **`TrackerSyncReport` has a required `deletions`**, so code that builds a report, such as a test's fake, sets it.
|
|
53
|
+
- **A tracker sync whose sign-in could not read a kind answers `meta.complete: false`** on every run, with the kind in
|
|
54
|
+
`meta.issues`; before, only `gaps` named it. The answer's own `complete`, which Desktop reads, stays as the sync made
|
|
55
|
+
it.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- **`crmFilesContract` passes on Windows.** It asserted mode 0600 on a downloaded file and 0700 on the files folder
|
|
60
|
+
there too, and Windows, which has no POSIX modes, reports 0666; bitrix24-cli's 0.27.0 release stopped on it. The
|
|
61
|
+
mode checks now run on Linux and macOS only.
|
|
62
|
+
- **Local OCR turns a page lying on its side.** `read_scans: local` now runs `tesseract` with `--psm 1`, its own page
|
|
63
|
+
orientation detection. On the [OCR benchmark](https://github.com/WireCatLabs/cli-testing/blob/main/performance/documents/ocr-ru-en/README.md)
|
|
64
|
+
a page on its side went from 85% wrong characters to 3%, every other page read the same, and a page took 0.3 s
|
|
65
|
+
longer. The reading's name becomes `ocr:v2:tesseract@…`, so scans read before are read once more. Without
|
|
66
|
+
tesseract's `osd` data (`apt install tesseract-ocr-osd`) it reads as before and the sync's `warnings` carry
|
|
67
|
+
`document.scan-unturned` with the hint; installing the data reads the scans again.
|
|
68
|
+
([docs](docs/dev/DOCUMENTS.md#scans-and-pictures))
|
|
69
|
+
|
|
8
70
|
## 0.749.0 — 24.11.2026
|
|
9
71
|
|
|
10
72
|
### Fixed
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { OcrPipeline } from "./ocr.js";
|
|
2
2
|
export declare const TESSERACT_HINT: string;
|
|
3
|
+
export declare const ORIENTATION_HINT: string;
|
|
3
4
|
/**
|
|
4
5
|
* The OCR of the `tesseract` program on this computer, or why there is none. Nothing leaves the computer and
|
|
5
|
-
* nothing is downloaded: the program and its language data are the owner's own install.
|
|
6
|
+
* nothing is downloaded: the program and its language data are the owner's own install. Without the `osd` data it still
|
|
7
|
+
* reads, with a warning, as pages on their side are then lost.
|
|
6
8
|
*/
|
|
7
9
|
export declare const tesseractPipeline: (env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
8
10
|
pipeline: OcrPipeline;
|
|
11
|
+
warning?: string;
|
|
9
12
|
} | {
|
|
10
13
|
missing: string;
|
|
11
14
|
}>;
|
|
@@ -6,8 +6,12 @@ const LANGUAGES = ["rus", "eng"];
|
|
|
6
6
|
const PAGE_MS = 120_000;
|
|
7
7
|
const PROBE_MS = 10_000;
|
|
8
8
|
const PROBE_BYTES = 64 * 1024;
|
|
9
|
+
/** The data `--psm 1` turns a page with: a page on its side read without it gave 85% wrong characters, with it 3%. */
|
|
10
|
+
const ORIENTATION = "osd";
|
|
9
11
|
export const TESSERACT_HINT = "reading scans on this computer needs the tesseract program with its Russian and English data " +
|
|
10
12
|
"(apt install tesseract-ocr tesseract-ocr-rus, brew install tesseract tesseract-lang); scans are read on the next sync";
|
|
13
|
+
export const ORIENTATION_HINT = "tesseract reads a page turned on its side only with its osd data (apt install tesseract-ocr-osd; " +
|
|
14
|
+
"brew install tesseract ships it); scans are read without turning pages until then";
|
|
11
15
|
const run = (args, env, timeout, { input, signal, errors = false } = {}) => new Promise((resolve, reject) => {
|
|
12
16
|
// The PATH of the run's own environment finds the program, so a test or a moved run picks its own.
|
|
13
17
|
const child = spawn("tesseract", args, {
|
|
@@ -42,7 +46,8 @@ const run = (args, env, timeout, { input, signal, errors = false } = {}) => new
|
|
|
42
46
|
});
|
|
43
47
|
/**
|
|
44
48
|
* The OCR of the `tesseract` program on this computer, or why there is none. Nothing leaves the computer and
|
|
45
|
-
* nothing is downloaded: the program and its language data are the owner's own install.
|
|
49
|
+
* nothing is downloaded: the program and its language data are the owner's own install. Without the `osd` data it still
|
|
50
|
+
* reads, with a warning, as pages on their side are then lost.
|
|
46
51
|
*/
|
|
47
52
|
export const tesseractPipeline = async (env, signal) => {
|
|
48
53
|
let version;
|
|
@@ -60,12 +65,16 @@ export const tesseractPipeline = async (env, signal) => {
|
|
|
60
65
|
if (version.code !== 0 || !number || !languages.length)
|
|
61
66
|
return { missing: TESSERACT_HINT };
|
|
62
67
|
const chosen = languages.join("+");
|
|
68
|
+
const turns = installed.has(ORIENTATION);
|
|
63
69
|
return {
|
|
70
|
+
...(turns ? {} : { warning: ORIENTATION_HINT }),
|
|
64
71
|
pipeline: {
|
|
65
|
-
// The version and the
|
|
66
|
-
|
|
72
|
+
// The version, the languages and the page turning name the reading, so installing Russian or osd data later
|
|
73
|
+
// reads the scans again; v2 is the reading with `--psm 1`.
|
|
74
|
+
extractor: `ocr:${turns ? "v2" : "v1"}:tesseract@${number}:${chosen}`,
|
|
67
75
|
transcribe: async (image) => {
|
|
68
|
-
const
|
|
76
|
+
const args = ["stdin", "stdout", "-l", chosen, ...(turns ? ["--psm", "1"] : [])];
|
|
77
|
+
const read = await run(args, env, PAGE_MS, {
|
|
69
78
|
input: Buffer.from(image.data, "base64"),
|
|
70
79
|
signal,
|
|
71
80
|
}).catch((error) => {
|
|
@@ -378,7 +378,7 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
378
378
|
const shown = withDropped({ telegram: telegram.parts, email: email.text, text: text.text, terminal: terminal.text }, dropped.length ? lineOf(dropped.length) : undefined);
|
|
379
379
|
return {
|
|
380
380
|
...shown,
|
|
381
|
-
document: `${JSON.stringify(reportDocument(parsed.report), null, 2)}\n`,
|
|
381
|
+
document: `${JSON.stringify({ ...reportDocument(parsed.report), ...(dropped.length ? { dropped } : {}) }, null, 2)}\n`,
|
|
382
382
|
subject: title,
|
|
383
383
|
notice: [title, parsed.report.summary].filter(Boolean).join("\n"),
|
|
384
384
|
invalid: false,
|
|
@@ -367,6 +367,8 @@ const libraryOf = (options, withSync) => {
|
|
|
367
367
|
...(keyring ? { keyring } : {}),
|
|
368
368
|
...(signal ? { signal } : {}),
|
|
369
369
|
});
|
|
370
|
+
if (scans?.warning)
|
|
371
|
+
warnings.push({ code: "configuration_error", reason: "document.scan-unturned", message: scans.warning });
|
|
370
372
|
const skipReason = options.skipReason ?? (() => undefined);
|
|
371
373
|
return files().locked((assertHeld) => withStore(true, async (store) => {
|
|
372
374
|
const result = await syncDocuments({
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -107,7 +107,7 @@ const crmSync = v.strictObject({
|
|
|
107
107
|
skipped_owner_rejected: count,
|
|
108
108
|
contacts_removed: v.optional(crmContactsRemoved),
|
|
109
109
|
stage_tasks: count,
|
|
110
|
-
activities: v.optional(v.strictObject({ saved: count, out_of_scope: count, state: v.picklist(["partial", "complete"]) })),
|
|
110
|
+
activities: v.optional(v.strictObject({ saved: count, out_of_scope: count, removed: count, state: v.picklist(["partial", "complete"]) })),
|
|
111
111
|
synced: v.array(v.strictObject({
|
|
112
112
|
kind: v.picklist(CRM_KINDS),
|
|
113
113
|
round: v.picklist(["full", "changes"]),
|
package/dist/crm/source.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export interface CrmPage<T> {
|
|
|
20
20
|
nextCursor?: string;
|
|
21
21
|
/** On the last page: the cursor the next run reads changes after; `null` when the CRM keeps none. */
|
|
22
22
|
cursor?: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* On the last page of activities: the round listed every one the CRM holds, whatever `since` asked (Attio's notes
|
|
25
|
+
* take no time filter), so one stored that it did not list was deleted.
|
|
26
|
+
*/
|
|
27
|
+
listedAll?: boolean;
|
|
23
28
|
}
|
|
24
29
|
/** `reset`: the cursor is dead, and the CRM must be listed in full again. */
|
|
25
30
|
export type CrmChanges<T> = CrmPage<T> | {
|
package/dist/crm/sync.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export interface CrmSyncOptions {
|
|
|
50
50
|
export interface CrmSyncIssue {
|
|
51
51
|
/** `user`: the account's users and departments. */
|
|
52
52
|
kind: CrmKind | "user";
|
|
53
|
-
reason: CrmSkipped["reason"] | CrmRelationIssue["reason"] | "crm.unlisted-held" | "crm.narrowing-held" | "crm.unassigned-dropped" | "crm.not-reported" | "crm.pending-dropped" | "crm.activities-failed" | "crm.stage-history-failed";
|
|
53
|
+
reason: CrmSkipped["reason"] | CrmRelationIssue["reason"] | "crm.unlisted-held" | "crm.narrowing-held" | "crm.unassigned-dropped" | "crm.not-reported" | "crm.pending-dropped" | "crm.activities-failed" | "crm.activities-unlisted-held" | "crm.stage-history-failed";
|
|
54
54
|
message: string;
|
|
55
55
|
externalId?: string;
|
|
56
56
|
}
|
|
@@ -107,6 +107,8 @@ export interface CrmSyncReport {
|
|
|
107
107
|
activities?: {
|
|
108
108
|
saved: number;
|
|
109
109
|
outOfScope: number;
|
|
110
|
+
/** Ones the CRM said it deleted, or a full list no longer named, now marked deleted. */
|
|
111
|
+
removed: number;
|
|
110
112
|
state: "partial" | "complete";
|
|
111
113
|
};
|
|
112
114
|
hint?: string;
|
package/dist/crm/sync.js
CHANGED
|
@@ -169,18 +169,40 @@ const activityCursor = (value) => {
|
|
|
169
169
|
return undefined;
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
+
/** As the id pass of a kind does, a list that would mark most of the stored activities deleted is held. */
|
|
173
|
+
const removeUnlistedActivities = async (run, options, seen) => {
|
|
174
|
+
const { store, account, source } = run;
|
|
175
|
+
const { stored, unlisted } = await store.crm.removeUnlistedActivities(account, seen, { dryRun: true });
|
|
176
|
+
if (unlisted === 0)
|
|
177
|
+
return;
|
|
178
|
+
if (!options.rescan && (seen.length === 0 || (stored >= GUARDED_FROM && unlisted > stored * MOST_UNLISTED))) {
|
|
179
|
+
run.report.issues.push({
|
|
180
|
+
kind: "deal",
|
|
181
|
+
reason: "crm.activities-unlisted-held",
|
|
182
|
+
message: `${source.provider} listed ${seen.length} activities, so ${unlisted} of the ${stored} stored would be marked ` +
|
|
183
|
+
"deleted; nothing was — check the sign-in's rights, then run sync --rescan to let it through",
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const done = await store.crm.removeUnlistedActivities(account, seen);
|
|
188
|
+
if (run.report.activities)
|
|
189
|
+
run.report.activities.removed += done.unlisted;
|
|
190
|
+
};
|
|
172
191
|
/**
|
|
173
192
|
* Activities and tasks changed since the last read, after every deal and lead of the run is stored: each is kept only
|
|
174
193
|
* on the deals and leads this copy holds. Pages go on from where a stopped run left them.
|
|
175
194
|
*/
|
|
176
|
-
const readActivities = async (run) => {
|
|
195
|
+
const readActivities = async (run, options) => {
|
|
177
196
|
const { source, store, account } = run;
|
|
178
197
|
if (!source.activities || !(await store.crm.activitiesOn(account)))
|
|
179
198
|
return null;
|
|
180
|
-
const read = { saved: 0, outOfScope: 0, state: "partial" };
|
|
199
|
+
const read = { saved: 0, outOfScope: 0, removed: 0, state: "partial" };
|
|
181
200
|
run.report.activities = read;
|
|
182
201
|
const saved = activityCursor((await store.sync.syncState(account, ACTIVITIES))?.value);
|
|
183
202
|
const cursor = saved ?? { since: run.now - ACTIVITY_DAYS * DAY, newest: 0 };
|
|
203
|
+
// Only a round read whole in this run, with no list refused, may show what was deleted: a resumed one lost its start.
|
|
204
|
+
const seen = cursor.page === undefined ? new Set() : undefined;
|
|
205
|
+
const gaps = run.gaps.length;
|
|
184
206
|
for (;;) {
|
|
185
207
|
const why = run.budget.take();
|
|
186
208
|
if (why)
|
|
@@ -200,6 +222,10 @@ const readActivities = async (run) => {
|
|
|
200
222
|
const done = await store.crm.saveActivities(account, page.items);
|
|
201
223
|
read.saved += done.saved;
|
|
202
224
|
read.outOfScope += done.outOfScope;
|
|
225
|
+
if (page.removed?.length)
|
|
226
|
+
read.removed += await store.crm.removeActivities(account, page.removed);
|
|
227
|
+
for (const one of page.items)
|
|
228
|
+
seen?.add(one.externalId);
|
|
203
229
|
cursor.newest = Math.max(cursor.newest, ...page.items.map((one) => one.updatedAt));
|
|
204
230
|
run.moved();
|
|
205
231
|
if (page.hasMore && page.nextCursor !== undefined) {
|
|
@@ -209,6 +235,8 @@ const readActivities = async (run) => {
|
|
|
209
235
|
return "cancelled";
|
|
210
236
|
continue;
|
|
211
237
|
}
|
|
238
|
+
if (page.listedAll && seen && run.gaps.length === gaps)
|
|
239
|
+
await removeUnlistedActivities(run, options, [...seen]);
|
|
212
240
|
const next = page.cursor != null ? Number(page.cursor) : cursor.newest || cursor.since;
|
|
213
241
|
await store.sync.setSyncState(account, ACTIVITIES, JSON.stringify({ since: next, newest: 0 }));
|
|
214
242
|
read.state = "complete";
|
|
@@ -635,7 +663,7 @@ export const syncCrm = async (source, store, account, options = {}) => {
|
|
|
635
663
|
const rowsStopped = stopped;
|
|
636
664
|
if (!stopped && kinds.some(isItemKind)) {
|
|
637
665
|
try {
|
|
638
|
-
stopped = await stopping(() => readActivities(run));
|
|
666
|
+
stopped = await stopping(() => readActivities(run, options));
|
|
639
667
|
}
|
|
640
668
|
catch (error) {
|
|
641
669
|
if (options.signal?.aborted)
|
|
@@ -78,10 +78,13 @@ export const crmFilesContract = (make) => [
|
|
|
78
78
|
}));
|
|
79
79
|
assert.ok(rows.some((one) => one.row.text?.toLowerCase().includes(word.toLowerCase())), `a file's text holds ${word}`);
|
|
80
80
|
for (const saved of filesOf(state)) {
|
|
81
|
-
|
|
81
|
+
if (process.platform !== "win32")
|
|
82
|
+
assert.equal(statSync(saved).mode & 0o777, 0o600, `${saved} is the OS user's alone`);
|
|
82
83
|
without(token, saved, readFileSync(saved, "latin1"));
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
+
// Windows has no POSIX modes: a saved file reads 0666 there whatever the code sets.
|
|
86
|
+
if (process.platform !== "win32")
|
|
87
|
+
assert.equal(statSync(join(state, "crm", "files")).mode & 0o777, 0o700);
|
|
85
88
|
const hits = await store.crmFiles.find({ words: [word] });
|
|
86
89
|
assert.ok(hits.items.length > 0, "search finds the text");
|
|
87
90
|
if (found.assignee !== null && run.user !== null) {
|
package/dist/domain/tracker.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
|
|
3
|
-
* states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
-
* projects and issues that name them.
|
|
3
|
+
* states, labels, projects, sprints, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
+
* projects, sprints and issues that name them.
|
|
5
5
|
*/
|
|
6
|
-
export declare const TRACKER_KINDS: readonly ["team", "user", "state", "label", "project", "issue", "comment"];
|
|
6
|
+
export declare const TRACKER_KINDS: readonly ["team", "user", "state", "label", "project", "sprint", "issue", "comment"];
|
|
7
7
|
export type TrackerKind = (typeof TRACKER_KINDS)[number];
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Where an issue in a state stands in its work, whatever the team named the state. `duplicate` is closed as
|
|
10
|
+
* `canceled` is, kept apart because Linear and GitHub both name it and a list may want those alone.
|
|
11
|
+
*/
|
|
12
|
+
export declare const STATE_TYPES: readonly ["triage", "backlog", "unstarted", "started", "completed", "canceled", "duplicate"];
|
|
10
13
|
export type StateType = (typeof STATE_TYPES)[number];
|
|
11
14
|
/** A tracker's 0–4 priority as the family's label: 0 is none, the tracker's 1 urgent is critical. */
|
|
12
15
|
export declare const TRACKER_PRIORITY_LABELS: readonly [null, "critical", "high", "medium", "low"];
|
|
@@ -20,6 +23,11 @@ interface TrackerRecord {
|
|
|
20
23
|
updatedAt?: number | null;
|
|
21
24
|
/** The tracker archived it: it still exists, and a read that asks for archived rows lists it. */
|
|
22
25
|
archivedAt?: number | null;
|
|
26
|
+
/**
|
|
27
|
+
* The tracker still lists it but it is deleted, as an issue in Linear's trash: the copy treats it as gone. Archived
|
|
28
|
+
* alone is not deleted.
|
|
29
|
+
*/
|
|
30
|
+
deleted?: boolean | null;
|
|
23
31
|
}
|
|
24
32
|
export interface TrackerTeam extends TrackerRecord {
|
|
25
33
|
name: string;
|
|
@@ -55,6 +63,17 @@ export interface TrackerProject extends TrackerRecord {
|
|
|
55
63
|
targetDate?: string | null;
|
|
56
64
|
url?: string | null;
|
|
57
65
|
}
|
|
66
|
+
/** A time-boxed run of a team's work: a Linear cycle, a Jira sprint. */
|
|
67
|
+
export interface TrackerSprint extends TrackerRecord {
|
|
68
|
+
/** Linear leaves most cycles unnamed: then the title is `Sprint <number>`. */
|
|
69
|
+
name: string;
|
|
70
|
+
number?: number | null;
|
|
71
|
+
description?: string | null;
|
|
72
|
+
team?: string | null;
|
|
73
|
+
startsAt?: number | null;
|
|
74
|
+
endsAt?: number | null;
|
|
75
|
+
completedAt?: number | null;
|
|
76
|
+
}
|
|
58
77
|
export interface TrackerIssue extends TrackerRecord {
|
|
59
78
|
title: string;
|
|
60
79
|
/** The readable key people say: `ENG-12`. */
|
|
@@ -63,6 +82,7 @@ export interface TrackerIssue extends TrackerRecord {
|
|
|
63
82
|
state?: string | null;
|
|
64
83
|
team?: string | null;
|
|
65
84
|
project?: string | null;
|
|
85
|
+
sprint?: string | null;
|
|
66
86
|
/** Users' ids. */
|
|
67
87
|
assignee?: string | null;
|
|
68
88
|
creator?: string | null;
|
|
@@ -90,6 +110,7 @@ export interface TrackerRecords {
|
|
|
90
110
|
state: TrackerState;
|
|
91
111
|
label: TrackerLabel;
|
|
92
112
|
project: TrackerProject;
|
|
113
|
+
sprint: TrackerSprint;
|
|
93
114
|
issue: TrackerIssue;
|
|
94
115
|
comment: TrackerComment;
|
|
95
116
|
}
|
|
@@ -97,6 +118,6 @@ export interface TrackerRecords {
|
|
|
97
118
|
export declare const trackerTitleOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string;
|
|
98
119
|
/** The record's text that search reads beside its title: a description or a comment's body. */
|
|
99
120
|
export declare const trackerBodyOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
|
|
100
|
-
/** The record its row hangs under: a comment's issue, a state's or a
|
|
121
|
+
/** The record its row hangs under: a comment's issue, a state's, a label's or a sprint's team. */
|
|
101
122
|
export declare const trackerParentOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
|
|
102
123
|
export {};
|
package/dist/domain/tracker.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
|
|
3
|
-
* states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
-
* projects and issues that name them.
|
|
3
|
+
* states, labels, projects, sprints, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
+
* projects, sprints and issues that name them.
|
|
5
5
|
*/
|
|
6
|
-
export const TRACKER_KINDS = ["team", "user", "state", "label", "project", "issue", "comment"];
|
|
7
|
-
/**
|
|
8
|
-
|
|
6
|
+
export const TRACKER_KINDS = ["team", "user", "state", "label", "project", "sprint", "issue", "comment"];
|
|
7
|
+
/**
|
|
8
|
+
* Where an issue in a state stands in its work, whatever the team named the state. `duplicate` is closed as
|
|
9
|
+
* `canceled` is, kept apart because Linear and GitHub both name it and a list may want those alone.
|
|
10
|
+
*/
|
|
11
|
+
export const STATE_TYPES = ["triage", "backlog", "unstarted", "started", "completed", "canceled", "duplicate"];
|
|
9
12
|
/** A tracker's 0–4 priority as the family's label: 0 is none, the tracker's 1 urgent is critical. */
|
|
10
13
|
export const TRACKER_PRIORITY_LABELS = [null, "critical", "high", "medium", "low"];
|
|
11
14
|
/** The record's title in lists and search: an issue's title, a comment's start, anything else's name. */
|
|
@@ -13,17 +16,19 @@ export const trackerTitleOf = (kind, record) => kind === "issue"
|
|
|
13
16
|
? record.title
|
|
14
17
|
: kind === "comment"
|
|
15
18
|
? record.body.split("\n")[0]?.slice(0, 120) || "(comment)"
|
|
16
|
-
: record.name
|
|
19
|
+
: kind === "sprint" && !record.name
|
|
20
|
+
? `Sprint ${record.number ?? ""}`.trim()
|
|
21
|
+
: record.name;
|
|
17
22
|
/** The record's text that search reads beside its title: a description or a comment's body. */
|
|
18
23
|
export const trackerBodyOf = (kind, record) => kind === "comment"
|
|
19
24
|
? record.body
|
|
20
25
|
: kind === "issue" || kind === "project"
|
|
21
26
|
? record.description
|
|
22
27
|
: null;
|
|
23
|
-
/** The record its row hangs under: a comment's issue, a state's or a
|
|
28
|
+
/** The record its row hangs under: a comment's issue, a state's, a label's or a sprint's team. */
|
|
24
29
|
export const trackerParentOf = (kind, record) => kind === "comment"
|
|
25
30
|
? record.issue
|
|
26
|
-
: kind === "state" || kind === "label"
|
|
31
|
+
: kind === "state" || kind === "label" || kind === "sprint"
|
|
27
32
|
? record.team
|
|
28
33
|
: kind === "issue"
|
|
29
34
|
? record.team
|
package/dist/errors/reasons.js
CHANGED
|
@@ -230,6 +230,11 @@ const OTHERS = [
|
|
|
230
230
|
validation("document.needs-ocr", "the PDF has no text layer; a documents sync reads it with OCR (read_scans)"),
|
|
231
231
|
validation("document.scan-unread", "OCR could not read the scan or picture; a sync tries again once the file changes"),
|
|
232
232
|
validation("document.scan-later", "OCR stopped at its page limit or a busy model; the next sync goes on"),
|
|
233
|
+
[
|
|
234
|
+
"document.scan-unturned",
|
|
235
|
+
"configuration_error",
|
|
236
|
+
"tesseract has no osd data, so a page on its side is read as it lies; install it to read scans again",
|
|
237
|
+
],
|
|
233
238
|
["document.not-imported", "not_found", "the document is not imported in this source account"],
|
|
234
239
|
["document.version-missing", "not_found", "the local copy holds no such version of the document"],
|
|
235
240
|
["document.not-found", "not_found", "no listed document has that reference"],
|
|
@@ -575,6 +580,11 @@ const OTHERS = [
|
|
|
575
580
|
validation("tracker.reference", "a team, state, label, project or user no single row of the copy has by that name"),
|
|
576
581
|
validation("tracker.team-required", "a new issue needs its team: name one, or sync a copy that holds one"),
|
|
577
582
|
["tracker.no-record", "invalid_response", "the tracker answered a write with no record and no error; sync and look"],
|
|
583
|
+
[
|
|
584
|
+
"tracker.kind-unread",
|
|
585
|
+
"permission_error",
|
|
586
|
+
"the sign-in cannot read this kind of the tracker; the copy has none of it",
|
|
587
|
+
],
|
|
578
588
|
validation("content.unlisted-held", "a content id list would mark too much deleted, the sign-in read only part, or the site moved; nothing was"),
|
|
579
589
|
validation("content.conflict", "the post changed at the source since the last sync; sync, then write again"),
|
|
580
590
|
validation("content.lossy-body", "the post's text holds blocks or embeds Markdown does not keep; --replace-body"),
|
|
@@ -589,6 +599,7 @@ const OTHERS = [
|
|
|
589
599
|
validation("crm.reference-unknown", "a CRM row names a contact, company or user the store does not hold; that link was not made"),
|
|
590
600
|
validation("crm.pending-dropped", "relationships waited too long for an end that never came; they were dropped"),
|
|
591
601
|
validation("crm.activities-failed", "the activities and tasks could not be read; the deals and leads were synced"),
|
|
602
|
+
validation("crm.activities-unlisted-held", "a full list would mark most activities deleted; held until --rescan"),
|
|
592
603
|
validation("crm.stage-history-failed", "the CRM's stage history could not be read; stage tasks wait for the next sync"),
|
|
593
604
|
validation("crm.email-ambiguous", "a CRM contact's email belongs to more than one person; the owner decides"),
|
|
594
605
|
validation("crm.own-unknown", "no own company of the CRM account is stored, so its users are no one's employees yet"),
|
|
@@ -30,6 +30,8 @@ export interface ScanReader {
|
|
|
30
30
|
name: string;
|
|
31
31
|
mime: string;
|
|
32
32
|
}): Promise<string>;
|
|
33
|
+
/** Why this reader reads worse than it could, for the sync's answer: tesseract without its osd data. */
|
|
34
|
+
warning?: string;
|
|
33
35
|
}
|
|
34
36
|
/** A skip this reader would now read: a scan an earlier sync could not, or one this sync's page limit held back. */
|
|
35
37
|
export declare const scanRetry: (reader: ScanReader | undefined, reason: string) => boolean;
|
|
@@ -76,11 +76,13 @@ export const scanReader = async (choice, deps, load = importEngine, pagesPerSync
|
|
|
76
76
|
if (choice === "off")
|
|
77
77
|
return undefined;
|
|
78
78
|
let pipeline;
|
|
79
|
+
let warning;
|
|
79
80
|
if (choice === "local") {
|
|
80
81
|
const local = await tesseractPipeline(deps.env, deps.signal);
|
|
81
82
|
if ("missing" in local)
|
|
82
83
|
return refusing(local.missing);
|
|
83
84
|
pipeline = local.pipeline;
|
|
85
|
+
warning = local.warning;
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
88
|
const model = modelPipeline(choice, deps);
|
|
@@ -108,6 +110,7 @@ export const scanReader = async (choice, deps, load = importEngine, pagesPerSync
|
|
|
108
110
|
};
|
|
109
111
|
return {
|
|
110
112
|
extractor: pipeline.extractor,
|
|
113
|
+
...(warning ? { warning } : {}),
|
|
111
114
|
full: () => pages >= pagesPerSync,
|
|
112
115
|
read: async (bytes, file) => {
|
|
113
116
|
if (pages >= pagesPerSync)
|
|
@@ -60,6 +60,19 @@ export interface ListedActivity extends StoredActivity {
|
|
|
60
60
|
}
|
|
61
61
|
/** The subjects and texts of the activities on each deal or lead of a kind, by `<account id>\u0000<external id>`. */
|
|
62
62
|
export declare const activityTexts: (database: StoreContext["database"], kind: DealKind) => Map<string, string[]>;
|
|
63
|
+
export interface CrmActivityWrites {
|
|
64
|
+
/** Activities and tasks, each on the kept deals and leads it names; one on none of them is not stored. */
|
|
65
|
+
saveActivities(key: AccountKey, activities: readonly CrmActivity[]): Promise<CrmActivitiesSaved>;
|
|
66
|
+
/** Marks deleted the stored activities the CRM says it deleted; answers how many. */
|
|
67
|
+
removeActivities(key: AccountKey, externalIds: readonly string[]): Promise<number>;
|
|
68
|
+
/** The stored ones a list of every activity did not name, marked deleted; `dryRun` only counts them. */
|
|
69
|
+
removeUnlistedActivities(key: AccountKey, seen: readonly string[], options?: {
|
|
70
|
+
dryRun?: boolean;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
stored: number;
|
|
73
|
+
unlisted: number;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
63
76
|
export interface CrmActivitiesSaved {
|
|
64
77
|
saved: number;
|
|
65
78
|
/** On no deal, lead, contact or company this copy keeps, so not stored. */
|
|
@@ -67,6 +80,7 @@ export interface CrmActivitiesSaved {
|
|
|
67
80
|
}
|
|
68
81
|
export declare const crmActivitiesOver: (context: StoreContext) => {
|
|
69
82
|
save: (key: AccountKey, activities: readonly CrmActivity[]) => CrmActivitiesSaved;
|
|
83
|
+
writes: CrmActivityWrites;
|
|
70
84
|
of: (key: AccountKey, kind: DealKind, externalId: string, limit: number) => StoredActivity[];
|
|
71
85
|
list: (key: AccountKey, filter: ActivityFilter) => {
|
|
72
86
|
items: ListedActivity[];
|
|
@@ -143,6 +143,25 @@ export const crmActivitiesOver = (context) => {
|
|
|
143
143
|
}
|
|
144
144
|
return { saved, outOfScope };
|
|
145
145
|
});
|
|
146
|
+
const remove = (key, externalIds) => write(database, () => {
|
|
147
|
+
const forgotten = database
|
|
148
|
+
.prepare("UPDATE records SET deleted_at = ? WHERE account_id = ? AND type = ? AND deleted_at IS NULL " +
|
|
149
|
+
"AND external_id IN (SELECT value FROM json_each(?)) RETURNING id")
|
|
150
|
+
.all(now(), accountPk(context, key), ACTIVITY_RECORD, JSON.stringify(externalIds))
|
|
151
|
+
.map(({ id }) => Number(id));
|
|
152
|
+
dropCrmActivityChunks(database, forgotten);
|
|
153
|
+
return forgotten.length;
|
|
154
|
+
});
|
|
155
|
+
const removeUnlisted = (key, seen, { dryRun = false } = {}) => {
|
|
156
|
+
const accountId = accountPk(context, key);
|
|
157
|
+
const live = "account_id = ? AND type = ? AND deleted_at IS NULL";
|
|
158
|
+
const stored = Number(database.prepare(`SELECT count(*) AS n FROM records WHERE ${live}`).get(accountId, ACTIVITY_RECORD)?.n ?? 0);
|
|
159
|
+
const ids = database
|
|
160
|
+
.prepare(`SELECT external_id FROM records WHERE ${live} AND external_id NOT IN (SELECT value FROM json_each(?))`)
|
|
161
|
+
.all(accountId, ACTIVITY_RECORD, JSON.stringify(seen))
|
|
162
|
+
.map(({ external_id }) => String(external_id));
|
|
163
|
+
return { stored, unlisted: dryRun || ids.length === 0 ? ids.length : remove(key, ids) };
|
|
164
|
+
};
|
|
146
165
|
/** The activities on one deal or lead: open ones first by due time, then the rest, newest first. */
|
|
147
166
|
const of = (key, kind, externalId, limit) => {
|
|
148
167
|
const accountId = findAccountPk(context, key);
|
|
@@ -282,7 +301,12 @@ export const crmActivitiesOver = (context) => {
|
|
|
282
301
|
where.map(({ sql }) => `AND ${sql}`).join(" "))
|
|
283
302
|
.get(accountId, ACTIVITY_RECORD, ...where.flatMap(({ params }) => params))?.n ?? 0);
|
|
284
303
|
};
|
|
285
|
-
|
|
304
|
+
const writes = {
|
|
305
|
+
saveActivities: async (key, activities) => save(key, activities),
|
|
306
|
+
removeActivities: async (key, externalIds) => remove(key, externalIds),
|
|
307
|
+
removeUnlistedActivities: async (key, seen, options) => removeUnlisted(key, seen, options),
|
|
308
|
+
};
|
|
309
|
+
return { save, writes, of, list, count };
|
|
286
310
|
};
|
|
287
311
|
/** An activity a viewer may read: on one of its deals or leads, or on contacts alone and assigned to it. */
|
|
288
312
|
const seenSql = (viewer) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmScopeSetting, type CrmStageEntry, type CrmUser } from "../../domain/crm.js";
|
|
2
2
|
import { type DealKind } from "../../domain/deals.js";
|
|
3
3
|
import type { AccountPeople } from "../people.js";
|
|
4
4
|
import type { AccountKey } from "../types.js";
|
|
5
|
-
import { type
|
|
5
|
+
import { type CrmActivityWrites, type StoredActivity } from "./crm-activities.js";
|
|
6
6
|
import { type CrmActivityChunks } from "./crm-activity-chunks.js";
|
|
7
7
|
import { type CrmReads } from "./crm-changes.js";
|
|
8
8
|
import { type CrmContactsRemoved } from "./crm-contacts.js";
|
|
@@ -37,7 +37,7 @@ export interface CrmSaved {
|
|
|
37
37
|
* nothing is ever matched by name (WC-DATA-6). Rows the CRM no longer has are marked deleted, never removed
|
|
38
38
|
* (WC-DATA-7). Every write is one transaction per call.
|
|
39
39
|
*/
|
|
40
|
-
export interface CrmCopies extends CrmReads {
|
|
40
|
+
export interface CrmCopies extends CrmReads, CrmActivityWrites {
|
|
41
41
|
/** One kind's pipelines and their stages, by the CRM's ids. A stage the CRM dropped stays: deals may stand in it. */
|
|
42
42
|
savePipelines(key: AccountKey, kind: DealKind, pipelines: CrmPipeline[]): Promise<CrmSaved>;
|
|
43
43
|
/** Deals or leads; one whose stage is not stored, or whose fields the store refuses, is skipped and named. */
|
|
@@ -113,8 +113,6 @@ export interface CrmCopies extends CrmReads {
|
|
|
113
113
|
expireStageEntries(key: AccountKey): Promise<number>;
|
|
114
114
|
/** Whether the owner turned on reading activities and tasks (`activities` setting). */
|
|
115
115
|
activitiesOn(key: AccountKey): Promise<boolean>;
|
|
116
|
-
/** Activities and tasks, each on the kept deals and leads it names; one on none of them is not stored. */
|
|
117
|
-
saveActivities(key: AccountKey, activities: readonly CrmActivity[]): Promise<CrmActivitiesSaved>;
|
|
118
116
|
/** One deal's or lead's activities, open ones first. */
|
|
119
117
|
activitiesOf(key: AccountKey, kind: DealKind, externalId: string, limit: number): Promise<StoredActivity[]>;
|
|
120
118
|
/** The activities' pieces searched by meaning, as `embedCrmActivities` and `search all` read them. */
|
package/dist/store/sqlite/crm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DEAL_ROLES } from "../../domain/deals.js";
|
|
|
4
4
|
import { recordFingerprint } from "../../domain/records.js";
|
|
5
5
|
import { accountPk, findAccountPk } from "./accounts.js";
|
|
6
6
|
import { suggestBaseStages } from "./base-suggest.js";
|
|
7
|
-
import { crmActivitiesOver, forgetActivitiesOn
|
|
7
|
+
import { crmActivitiesOver, forgetActivitiesOn } from "./crm-activities.js";
|
|
8
8
|
import { crmActivityChunksOver } from "./crm-activity-chunks.js";
|
|
9
9
|
import { crmReadsOver } from "./crm-changes.js";
|
|
10
10
|
import { removeCrmContacts } from "./crm-contacts.js";
|
|
@@ -670,7 +670,7 @@ export const crmCopiesOver = (context, people) => {
|
|
|
670
670
|
handleStageEntries: async (ids) => stageEntryStore.handled(ids),
|
|
671
671
|
expireStageEntries: async (key) => stageEntryStore.expire(key),
|
|
672
672
|
activitiesOn: async (key) => crmActivitiesOn(database, key),
|
|
673
|
-
|
|
673
|
+
...activityStore.writes,
|
|
674
674
|
activitiesOf: async (key, kind, externalId, limit) => activityStore.of(key, kind, externalId, limit),
|
|
675
675
|
activityChunks: crmActivityChunksOver(context),
|
|
676
676
|
...crmReadsOver(context),
|
|
@@ -21,6 +21,8 @@ export interface TrackerFilter {
|
|
|
21
21
|
/** Issues whose state is of one of these types. */
|
|
22
22
|
stateTypes?: readonly StateType[];
|
|
23
23
|
label?: string;
|
|
24
|
+
/** Issues only; `null`, the issues in no sprint. */
|
|
25
|
+
sprint?: string | null;
|
|
24
26
|
/** Archived rows too; absent, only the live ones. */
|
|
25
27
|
archived?: boolean;
|
|
26
28
|
limit?: number;
|
|
@@ -56,12 +58,14 @@ export interface TrackerPerson {
|
|
|
56
58
|
export interface TrackerStore {
|
|
57
59
|
/**
|
|
58
60
|
* Upserts records of one kind; a field a record leaves out keeps its stored value, and a record listed again after
|
|
59
|
-
* the tracker stopped listing it comes back.
|
|
61
|
+
* the tracker stopped listing it comes back. A record the tracker calls `deleted` is marked deleted, and an issue
|
|
62
|
+
* takes its comments with it. Answers how many changed: a row read again as it was stored is not counted.
|
|
60
63
|
*/
|
|
61
64
|
save<K extends TrackerKind>(key: AccountKey, kind: K, records: readonly TrackerRecords[K][], now: number): Promise<number>;
|
|
62
65
|
/**
|
|
63
66
|
* After a complete list of the kind's ids: marks deleted every stored one the list lacks that has not been synced
|
|
64
|
-
* since `before`, so a row saved while the list was read is never taken for a deleted one
|
|
67
|
+
* since `before`, so a row saved while the list was read is never taken for a deleted one, and the comments of an
|
|
68
|
+
* issue it marks. Answers how many of the kind.
|
|
65
69
|
*/
|
|
66
70
|
removeUnlisted(key: AccountKey, kind: TrackerKind, listed: readonly string[], before: number, now: number, options?: {
|
|
67
71
|
dryRun?: boolean;
|