@wirecat/cli-core 0.748.0 → 0.750.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 +63 -0
- package/dist/attachments/tesseract.d.ts +4 -1
- package/dist/attachments/tesseract.js +13 -4
- package/dist/background/report/render.d.ts +3 -0
- package/dist/background/report/render.js +32 -6
- package/dist/background/report/schema.d.ts +3 -2
- package/dist/background/report/schema.js +25 -10
- package/dist/cli/documents/library.js +2 -0
- 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 +10 -0
- package/dist/services/documents/scans.d.ts +2 -0
- package/dist/services/documents/scans.js +3 -0
- 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,69 @@ 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.750.0 — 24.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A digest's page file names what was left out.** `<run>.report.json` lists in `dropped` the parts the check
|
|
13
|
+
left out, so WireCat Desktop can say how many it does not show.
|
|
14
|
+
- **Trackers copy sprints.** `sprint` is a tracker kind, between `project` and `issue` in `TRACKER_KINDS`: a Linear
|
|
15
|
+
cycle or a Jira sprint, with its `name`, `number`, `team`, `startsAt`, `endsAt` and `completedAt`. An issue names
|
|
16
|
+
its `sprint`. `sprints list` lists them, and `issues list sprint:<id>` (or `sprint:none`) narrows the issues. An
|
|
17
|
+
unnamed sprint, as most Linear cycles are, is titled `Sprint <number>`. A manifest without a sprint kind syncs as
|
|
18
|
+
before ([docs](docs/dev/TRACKER.md#the-domain)).
|
|
19
|
+
- **An issue in the tracker's trash leaves the copy.** A map may read `deleted` (Linear's `trashed`). A row read as
|
|
20
|
+
deleted is marked deleted in the copy, and its `ids` call, which selects the same path, leaves it out, so the daily
|
|
21
|
+
id pass finds it: Linear's trash moves no `updatedAt`, so a plain read of changes never sees it. An issue marked
|
|
22
|
+
deleted takes its comments with it. A row the id pass lists again after it was marked deleted, as an issue restored
|
|
23
|
+
from the trash, is back with its comments. `trackerSourceContract` checks a
|
|
24
|
+
`trash` fault, which `trackerManifestFixture` offers when the map reads `deleted`
|
|
25
|
+
([docs](docs/dev/TRACKER.md#deleted-and-trashed-rows)).
|
|
26
|
+
- **The `duplicate` state type.** Linear's Duplicate state was dropped by the map, so its issues pointed at a state the
|
|
27
|
+
copy did not hold. It is now one of `STATE_TYPES`, closed as `canceled` is: a task from such an issue closes as
|
|
28
|
+
dismissed, `the issue was marked a duplicate in linear`, and `issues list type:duplicate` finds them.
|
|
29
|
+
- **A tracker sync says when it next looks for deletions and what it could not read.** Its answer has
|
|
30
|
+
`deletions: { checked, due }`, when the id pass last ran for every kind and when it is next due. A kind the sign-in
|
|
31
|
+
could not read is named in `meta.issues` (`tracker.kind-unread`) besides `gaps`.
|
|
32
|
+
|
|
33
|
+
### Changed — may break callers
|
|
34
|
+
|
|
35
|
+
- **`synced[].saved` and `progress.saved` count only rows that changed** in the copy: new, different, deleted or back
|
|
36
|
+
again. A row read again as stored is not counted, so a sync with nothing new answers 0 and Desktop shows it up to
|
|
37
|
+
date. `store.tracker.save` answers the same count.
|
|
38
|
+
- **`TrackerRecords` and `TRACKER_KINDS` have `sprint`, and `STATE_TYPES` has `duplicate`.** Code with a value for
|
|
39
|
+
each kind or state type, such as a `Record<TrackerKind, …>` or a `switch` over `StateType`, needs one for the new
|
|
40
|
+
member; `exampleTrackerRows()` has a sprint and a Duplicate state.
|
|
41
|
+
- **`TrackerSyncReport` has a required `deletions`**, so code that builds a report, such as a test's fake, sets it.
|
|
42
|
+
- **A tracker sync whose sign-in could not read a kind answers `meta.complete: false`** on every run, with the kind in
|
|
43
|
+
`meta.issues`; before, only `gaps` named it. The answer's own `complete`, which Desktop reads, stays as the sync made
|
|
44
|
+
it.
|
|
45
|
+
|
|
46
|
+
### Fixed
|
|
47
|
+
|
|
48
|
+
- **`crmFilesContract` passes on Windows.** It asserted mode 0600 on a downloaded file and 0700 on the files folder
|
|
49
|
+
there too, and Windows, which has no POSIX modes, reports 0666; bitrix24-cli's 0.27.0 release stopped on it. The
|
|
50
|
+
mode checks now run on Linux and macOS only.
|
|
51
|
+
- **Local OCR turns a page lying on its side.** `read_scans: local` now runs `tesseract` with `--psm 1`, its own page
|
|
52
|
+
orientation detection. On the [OCR benchmark](https://github.com/WireCatLabs/cli-testing/blob/main/performance/documents/ocr-ru-en/README.md)
|
|
53
|
+
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
|
|
54
|
+
longer. The reading's name becomes `ocr:v2:tesseract@…`, so scans read before are read once more. Without
|
|
55
|
+
tesseract's `osd` data (`apt install tesseract-ocr-osd`) it reads as before and the sync's `warnings` carry
|
|
56
|
+
`document.scan-unturned` with the hint; installing the data reads the scans again.
|
|
57
|
+
([docs](docs/dev/DOCUMENTS.md#scans-and-pictures))
|
|
58
|
+
|
|
59
|
+
## 0.749.0 — 24.11.2026
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- **One bad part no longer costs the whole report.** A section, item or health entry that fails the check is left
|
|
64
|
+
out, and the rest is delivered with a last line saying how many were left out ("⚠️ Не показано из-за ошибки
|
|
65
|
+
формата: 2"). `last.json` names them under `report.dropped`, with the reason `report.items-dropped`. Only the
|
|
66
|
+
document's own fields (the JSON, `kind`, `date`, the `sections` list, `tasks`, `scope`) still refuse it. The owner's
|
|
67
|
+
morning digest was lost whole on 2026-11-17 (two meetings) and 2026-11-21..24 (one reply).
|
|
68
|
+
- **A time without an offset is read as local time.** An agent writes a meeting's hour as `2026-11-17T10:00:00`; that
|
|
69
|
+
was refused.
|
|
70
|
+
|
|
8
71
|
## 0.748.0 — 24.11.2026
|
|
9
72
|
|
|
10
73
|
### Added
|
|
@@ -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) => {
|
|
@@ -7,6 +7,7 @@ export type ReportChannel = (typeof REPORT_CHANNELS)[number];
|
|
|
7
7
|
export type MessageView = ReportView | GapsView | NoticeView;
|
|
8
8
|
export declare const REPORT_REASONS: {
|
|
9
9
|
readonly invalid: "delivery.report-invalid";
|
|
10
|
+
readonly dropped: "report.items-dropped";
|
|
10
11
|
readonly templateFailed: "report.template-failed";
|
|
11
12
|
readonly templateTags: "report.template-tags";
|
|
12
13
|
};
|
|
@@ -58,6 +59,8 @@ export interface ReportRun {
|
|
|
58
59
|
leaks: number;
|
|
59
60
|
/** The path of the first field that failed the check; nothing was shown. */
|
|
60
61
|
invalid?: string;
|
|
62
|
+
/** The sections, items and health entries left out because they failed the check; the rest was shown. */
|
|
63
|
+
dropped?: string[];
|
|
61
64
|
reasons?: string[];
|
|
62
65
|
}
|
|
63
66
|
export interface PreparedReport {
|
|
@@ -10,6 +10,7 @@ const DEFAULT_LANGUAGE = "en";
|
|
|
10
10
|
const LIMITS = { parse: 65_536, memory: 4_000_000, milliseconds: 1_000 };
|
|
11
11
|
export const REPORT_REASONS = {
|
|
12
12
|
invalid: "delivery.report-invalid",
|
|
13
|
+
dropped: "report.items-dropped",
|
|
13
14
|
templateFailed: "report.template-failed",
|
|
14
15
|
templateTags: "report.template-tags",
|
|
15
16
|
};
|
|
@@ -307,6 +308,24 @@ const INVALID_LINES = {
|
|
|
307
308
|
ru: "Сводка не собралась: ошибка формата. Подробности в WireCat.",
|
|
308
309
|
en: "The report could not be built: format error. Details in WireCat.",
|
|
309
310
|
};
|
|
311
|
+
const DROPPED_LINES = {
|
|
312
|
+
ru: (count) => `⚠️ Не показано из-за ошибки формата: ${count}. Подробности в WireCat.`,
|
|
313
|
+
en: (count) => `⚠️ Left out for a format error: ${count}. Details in WireCat.`,
|
|
314
|
+
};
|
|
315
|
+
/** The line after a report that lost parts to the check, so a short digest is never read as a whole one. */
|
|
316
|
+
const withDropped = (rendered, line) => {
|
|
317
|
+
if (!line)
|
|
318
|
+
return rendered;
|
|
319
|
+
const last = rendered.telegram.at(-1) ?? "";
|
|
320
|
+
const note = escapeHtml(line);
|
|
321
|
+
const joined = last ? `${last}\n\n${note}` : note;
|
|
322
|
+
const telegram = fits(joined) ? [...rendered.telegram.slice(0, -1), joined] : [...rendered.telegram, note];
|
|
323
|
+
const paragraph = `<p>${note}</p>`;
|
|
324
|
+
const email = rendered.email.trimEnd().endsWith("</div>")
|
|
325
|
+
? rendered.email.replace(/<\/div>\s*$/, `${paragraph}\n</div>`)
|
|
326
|
+
: `${rendered.email}${paragraph}`;
|
|
327
|
+
return { telegram, email, text: `${rendered.text}\n\n${line}`, terminal: `${rendered.terminal}\n\n${line}` };
|
|
328
|
+
};
|
|
310
329
|
/**
|
|
311
330
|
* A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
|
|
312
331
|
* line in the owner's language and is never shown raw.
|
|
@@ -352,16 +371,23 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
|
|
|
352
371
|
...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
|
|
353
372
|
];
|
|
354
373
|
const title = text.text.split("\n")[0] ?? "";
|
|
374
|
+
const { dropped } = parsed;
|
|
375
|
+
if (dropped.length)
|
|
376
|
+
reasons.push(REPORT_REASONS.dropped);
|
|
377
|
+
const lineOf = DROPPED_LINES[shipped] ?? DROPPED_LINES[DEFAULT_LANGUAGE];
|
|
378
|
+
const shown = withDropped({ telegram: telegram.parts, email: email.text, text: text.text, terminal: terminal.text }, dropped.length ? lineOf(dropped.length) : undefined);
|
|
355
379
|
return {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
text: text.text,
|
|
359
|
-
terminal: terminal.text,
|
|
360
|
-
document: `${JSON.stringify(reportDocument(parsed.report), null, 2)}\n`,
|
|
380
|
+
...shown,
|
|
381
|
+
document: `${JSON.stringify({ ...reportDocument(parsed.report), ...(dropped.length ? { dropped } : {}) }, null, 2)}\n`,
|
|
361
382
|
subject: title,
|
|
362
383
|
notice: [title, parsed.report.summary].filter(Boolean).join("\n"),
|
|
363
384
|
invalid: false,
|
|
364
|
-
run: {
|
|
385
|
+
run: {
|
|
386
|
+
language: shipped,
|
|
387
|
+
leaks: parsed.leaks,
|
|
388
|
+
...(dropped.length ? { dropped } : {}),
|
|
389
|
+
...(reasons.length ? { reasons } : {}),
|
|
390
|
+
},
|
|
365
391
|
};
|
|
366
392
|
};
|
|
367
393
|
const templateOf = (templates, channel) => {
|
|
@@ -100,13 +100,14 @@ export declare const isReportAnswer: (answer: string) => boolean;
|
|
|
100
100
|
export type ParsedReport = {
|
|
101
101
|
report: Report;
|
|
102
102
|
leaks: number;
|
|
103
|
+
dropped: string[];
|
|
103
104
|
} | {
|
|
104
105
|
invalid: string;
|
|
105
106
|
};
|
|
106
107
|
/**
|
|
107
108
|
* A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
|
|
108
|
-
* report (`undefined`) and keeps the Markdown path; a JSON answer
|
|
109
|
-
* of the first field that failed, and is never shown
|
|
109
|
+
* report (`undefined`) and keeps the Markdown path; a JSON answer whose own fields fail the check is `invalid`, with
|
|
110
|
+
* the path of the first field that failed, and is never shown; a part that fails is left out and named in `dropped`. `trusted` is a document a command built from the store: its
|
|
110
111
|
* strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
|
|
111
112
|
*/
|
|
112
113
|
export declare const parseReport: (answer: string, trusted?: boolean) => ParsedReport | undefined;
|
|
@@ -46,7 +46,8 @@ export const withoutLeaks = (text) => {
|
|
|
46
46
|
class Invalid extends Error {
|
|
47
47
|
}
|
|
48
48
|
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
49
|
-
|
|
49
|
+
// No offset is the machine's local time, as `Date.parse` reads it: agents write a meeting's "10:00" that way.
|
|
50
|
+
const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
50
51
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51
52
|
const oneOf = (values, value, at) => {
|
|
52
53
|
if (!values.includes(value))
|
|
@@ -139,10 +140,26 @@ const tasksOf = (value) => {
|
|
|
139
140
|
const cut = (text, limit) => (text.length <= limit ? text : `${text.slice(0, limit - 1).trimEnd()}…`);
|
|
140
141
|
/**
|
|
141
142
|
* Checks a parsed document and keeps what the renderers may show. Any agent string loses what `withoutLeaks` finds
|
|
142
|
-
* and is cut to its limit; a required field left empty by that
|
|
143
|
+
* and is cut to its limit; a required field left empty by that fails its item, as a missing one does. A section,
|
|
144
|
+
* item or health entry that fails is left out and named in `dropped`: one undated reply must not cost the whole
|
|
145
|
+
* digest. Only the document's own fields (format, kind, date, the sections list, tasks, scope) refuse it.
|
|
143
146
|
*/
|
|
144
147
|
const checked = (document, trusted) => {
|
|
145
148
|
let leaks = 0;
|
|
149
|
+
const dropped = [];
|
|
150
|
+
const kept = (list, at, check) => list.flatMap((one, index) => {
|
|
151
|
+
const before = leaks;
|
|
152
|
+
try {
|
|
153
|
+
return [check(one, at(index))];
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (!(error instanceof Invalid))
|
|
157
|
+
throw error;
|
|
158
|
+
leaks = before;
|
|
159
|
+
dropped.push(error.message);
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
146
163
|
const text = (value, field, at) => {
|
|
147
164
|
if (value === undefined || value === null)
|
|
148
165
|
return null;
|
|
@@ -163,15 +180,13 @@ const checked = (document, trusted) => {
|
|
|
163
180
|
throw new Invalid("date");
|
|
164
181
|
if (!Array.isArray(document.sections))
|
|
165
182
|
throw new Invalid("sections");
|
|
166
|
-
const sections = document.sections
|
|
167
|
-
const at = `sections[${s}]`;
|
|
183
|
+
const sections = kept(document.sections, (s) => `sections[${s}]`, (section, at) => {
|
|
168
184
|
if (!isObject(section) || !Array.isArray(section.items))
|
|
169
185
|
throw new Invalid(at);
|
|
170
186
|
return {
|
|
171
187
|
kind: oneOf(SECTION_KINDS, section.kind, `${at}.kind`),
|
|
172
188
|
more: section.more === undefined || section.more === null ? 0 : whole(section.more, `${at}.more`),
|
|
173
|
-
items: section.items.
|
|
174
|
-
const where = `${at}.items[${i}]`;
|
|
189
|
+
items: kept(section.items, (i) => `${at}.items[${i}]`, (item, where) => {
|
|
175
190
|
if (!isObject(item))
|
|
176
191
|
throw new Invalid(where);
|
|
177
192
|
const type = oneOf(ITEM_TYPES, item.type, `${where}.type`);
|
|
@@ -211,8 +226,7 @@ const checked = (document, trusted) => {
|
|
|
211
226
|
date: document.date,
|
|
212
227
|
summary: text(document.summary, "summary", "summary"),
|
|
213
228
|
sections,
|
|
214
|
-
health: health
|
|
215
|
-
const at = `health[${h}]`;
|
|
229
|
+
health: kept(health, (h) => `health[${h}]`, (entry, at) => {
|
|
216
230
|
if (!isObject(entry))
|
|
217
231
|
throw new Invalid(at);
|
|
218
232
|
const reason = entry.reason === undefined || entry.reason === null
|
|
@@ -238,6 +252,7 @@ const checked = (document, trusted) => {
|
|
|
238
252
|
tasks: tasksOf(document.tasks),
|
|
239
253
|
},
|
|
240
254
|
leaks,
|
|
255
|
+
dropped,
|
|
241
256
|
};
|
|
242
257
|
};
|
|
243
258
|
/**
|
|
@@ -282,8 +297,8 @@ export const isReportAnswer = (answer) => {
|
|
|
282
297
|
};
|
|
283
298
|
/**
|
|
284
299
|
* A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
|
|
285
|
-
* report (`undefined`) and keeps the Markdown path; a JSON answer
|
|
286
|
-
* of the first field that failed, and is never shown
|
|
300
|
+
* report (`undefined`) and keeps the Markdown path; a JSON answer whose own fields fail the check is `invalid`, with
|
|
301
|
+
* the path of the first field that failed, and is never shown; a part that fails is left out and named in `dropped`. `trusted` is a document a command built from the store: its
|
|
287
302
|
* strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
|
|
288
303
|
*/
|
|
289
304
|
export const parseReport = (answer, trusted = 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({
|
|
@@ -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"),
|
|
@@ -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)
|
|
@@ -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;
|
|
@@ -39,7 +39,21 @@ export const resetTrackerItemWords = (database) => {
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
const keyOf = (data) => data == null ? undefined : JSON.parse(String(data)).key;
|
|
42
|
-
const ISSUE_FIELDS = { assignee: "assignee", project: "project", state: "state" };
|
|
42
|
+
const ISSUE_FIELDS = { assignee: "assignee", project: "project", state: "state", sprint: "sprint" };
|
|
43
|
+
/**
|
|
44
|
+
* Marks the live comments of these issues deleted with them; a comment of a trashed issue is only archived in Linear,
|
|
45
|
+
* and would stay found under an issue that is gone.
|
|
46
|
+
*/
|
|
47
|
+
const deleteComments = (database, accountId, issues, now) => {
|
|
48
|
+
if (!issues.length)
|
|
49
|
+
return;
|
|
50
|
+
const ids = database
|
|
51
|
+
.prepare("UPDATE tracker_items SET deleted_at = ? WHERE account_id = ? AND kind = 'comment' AND deleted_at IS NULL " +
|
|
52
|
+
"AND parent_id IN (SELECT value FROM json_each(?)) RETURNING id")
|
|
53
|
+
.all(now, accountId, JSON.stringify(issues))
|
|
54
|
+
.map((row) => Number(row.id));
|
|
55
|
+
dropTrackerChunks(database, ids);
|
|
56
|
+
};
|
|
43
57
|
/**
|
|
44
58
|
* The words as clauses for `clauseIn`, and the index expression that finds the rows they could match: a word, a word
|
|
45
59
|
* it begins, or a word that begins with its stem. A Snowball stem begins its word, but for the English `y` it turns to
|
|
@@ -77,6 +91,10 @@ export const trackerStoreOver = (context) => {
|
|
|
77
91
|
const save = (key, kind, records, now) => write(database, () => {
|
|
78
92
|
const accountId = accountPk(context, key);
|
|
79
93
|
const stored = database.prepare("SELECT data, title, body, deleted_at FROM tracker_items WHERE account_id = ? AND kind = ? AND external_id = ?");
|
|
94
|
+
const issueDeletedAt = database.prepare("SELECT deleted_at FROM tracker_items WHERE account_id = ? AND kind = 'issue' AND external_id = ?");
|
|
95
|
+
const reviveComments = database.prepare("UPDATE tracker_items SET deleted_at = NULL WHERE account_id = ? AND kind = 'comment' AND parent_id = ? " +
|
|
96
|
+
"AND deleted_at = ?");
|
|
97
|
+
let changed = 0;
|
|
80
98
|
const scope = database.prepare("SELECT scope FROM accounts WHERE id = ?").get(accountId)?.scope;
|
|
81
99
|
const chunked = isChunkedTrackerKind(kind);
|
|
82
100
|
const chunk = trackerChunkWriter(database);
|
|
@@ -85,12 +103,14 @@ export const trackerStoreOver = (context) => {
|
|
|
85
103
|
"WHERE account_id = ? AND kind = 'comment' AND parent_id = ? AND deleted_at IS NULL");
|
|
86
104
|
const upsert = database.prepare("INSERT INTO tracker_items (account_id, kind, external_id, parent_id, title, title_folded, body, " +
|
|
87
105
|
"normalized_text, data, source_created_at, source_updated_at, archived_at, deleted_at, synced_at) " +
|
|
88
|
-
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
106
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " +
|
|
89
107
|
"ON CONFLICT (account_id, kind, external_id) DO UPDATE SET parent_id = excluded.parent_id, " +
|
|
90
108
|
"title = excluded.title, title_folded = excluded.title_folded, body = excluded.body, " +
|
|
91
109
|
"normalized_text = excluded.normalized_text, data = excluded.data, " +
|
|
92
110
|
"source_created_at = excluded.source_created_at, source_updated_at = excluded.source_updated_at, " +
|
|
93
|
-
"archived_at = excluded.archived_at, deleted_at =
|
|
111
|
+
"archived_at = excluded.archived_at, deleted_at = CASE WHEN excluded.deleted_at IS NULL THEN NULL " +
|
|
112
|
+
"ELSE coalesce(tracker_items.deleted_at, excluded.deleted_at) END, synced_at = excluded.synced_at " +
|
|
113
|
+
"RETURNING id, deleted_at");
|
|
94
114
|
for (const record of records) {
|
|
95
115
|
const before = stored.get(accountId, kind, record.externalId);
|
|
96
116
|
// A field the tracker left out of this read keeps what the store knew: a read never erases by omission.
|
|
@@ -100,7 +120,27 @@ export const trackerStoreOver = (context) => {
|
|
|
100
120
|
};
|
|
101
121
|
const title = trackerTitleOf(kind, merged);
|
|
102
122
|
const body = trackerBodyOf(kind, merged) ?? null;
|
|
103
|
-
const
|
|
123
|
+
const data = JSON.stringify(merged);
|
|
124
|
+
// A comment saved under a deleted issue goes with it: Linear lists it as archived, not deleted.
|
|
125
|
+
const parentGone = kind === "comment"
|
|
126
|
+
? issueDeletedAt.get(accountId, merged.issue ?? null)?.deleted_at
|
|
127
|
+
: undefined;
|
|
128
|
+
const deletedAt = merged.deleted === true ? now : parentGone == null ? null : Number(parentGone);
|
|
129
|
+
const saved = upsert.get(accountId, kind, merged.externalId, trackerParentOf(kind, merged) ?? null, title, fold(title), body, normalize([title, body].filter(Boolean).join("\n")), data, merged.createdAt ?? null, merged.updatedAt ?? null, merged.archivedAt ?? null, deletedAt, now);
|
|
130
|
+
const gone = saved?.deleted_at != null;
|
|
131
|
+
if (!before || before.data !== data || (before.deleted_at != null) !== gone)
|
|
132
|
+
changed += 1;
|
|
133
|
+
if (gone) {
|
|
134
|
+
if (before?.deleted_at == null) {
|
|
135
|
+
if (chunked)
|
|
136
|
+
dropTrackerChunks(database, [Number(saved?.id)]);
|
|
137
|
+
if (kind === "issue")
|
|
138
|
+
deleteComments(database, accountId, [merged.externalId], Number(saved?.deleted_at));
|
|
139
|
+
}
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (kind === "issue" && before?.deleted_at != null)
|
|
143
|
+
reviveComments.run(accountId, merged.externalId, Number(before.deleted_at));
|
|
104
144
|
// Most rows of a sync come back with the text they had; their chunks stay, and only a revived row needs new.
|
|
105
145
|
const same = before?.deleted_at == null && before?.title === title && (before?.body ?? null) === body;
|
|
106
146
|
// A comment is embedded after its issue's key and title, so a new, revived, renamed or moved issue cuts its
|
|
@@ -139,8 +179,29 @@ export const trackerStoreOver = (context) => {
|
|
|
139
179
|
released.push(hash);
|
|
140
180
|
}
|
|
141
181
|
dropUnusedVectors(database, released);
|
|
142
|
-
return
|
|
182
|
+
return changed;
|
|
143
183
|
});
|
|
184
|
+
/**
|
|
185
|
+
* Linear moves no `updatedAt` when an issue leaves the trash, so the id pass listing a deleted row again is the
|
|
186
|
+
* only sign it is back. A comment stays deleted while its issue is: Linear lists a trashed issue's comments.
|
|
187
|
+
*/
|
|
188
|
+
const restoreListed = (accountId, kind, listed) => {
|
|
189
|
+
const found = database
|
|
190
|
+
.prepare("SELECT t.id, t.external_id, t.deleted_at FROM tracker_items t WHERE t.account_id = ? AND t.kind = ? " +
|
|
191
|
+
"AND t.deleted_at IS NOT NULL AND t.external_id IN (SELECT value FROM json_each(?)) " +
|
|
192
|
+
"AND (t.kind <> 'comment' OR NOT EXISTS (SELECT 1 FROM tracker_items i WHERE i.account_id = t.account_id " +
|
|
193
|
+
"AND i.kind = 'issue' AND i.external_id = t.parent_id AND i.deleted_at IS NOT NULL))")
|
|
194
|
+
.all(accountId, kind, JSON.stringify(listed));
|
|
195
|
+
const restore = database.prepare("UPDATE tracker_items SET deleted_at = NULL, data = CASE WHEN json_extract(data, '$.deleted') IS NULL " +
|
|
196
|
+
"THEN data ELSE json_set(data, '$.deleted', json('false')) END WHERE id = ?");
|
|
197
|
+
const comments = database.prepare("UPDATE tracker_items SET deleted_at = NULL WHERE account_id = ? AND kind = 'comment' AND parent_id = ? " +
|
|
198
|
+
"AND deleted_at = ?");
|
|
199
|
+
for (const row of found) {
|
|
200
|
+
restore.run(Number(row.id));
|
|
201
|
+
if (kind === "issue")
|
|
202
|
+
comments.run(accountId, String(row.external_id), Number(row.deleted_at));
|
|
203
|
+
}
|
|
204
|
+
};
|
|
144
205
|
const removeUnlisted = (key, kind, listed, before, now, { dryRun = false } = {}) => {
|
|
145
206
|
const accountId = findAccountPk(context, key);
|
|
146
207
|
if (accountId === undefined)
|
|
@@ -150,6 +211,7 @@ export const trackerStoreOver = (context) => {
|
|
|
150
211
|
const mark = database.prepare("UPDATE tracker_items SET deleted_at = ? WHERE id = ?");
|
|
151
212
|
let removed = 0;
|
|
152
213
|
const marked = [];
|
|
214
|
+
const issues = [];
|
|
153
215
|
for (const row of database
|
|
154
216
|
.prepare("SELECT id, external_id FROM tracker_items WHERE account_id = ? AND kind = ? AND deleted_at IS NULL " +
|
|
155
217
|
"AND synced_at < ?")
|
|
@@ -159,11 +221,16 @@ export const trackerStoreOver = (context) => {
|
|
|
159
221
|
if (!dryRun) {
|
|
160
222
|
mark.run(now, Number(row.id));
|
|
161
223
|
marked.push(Number(row.id));
|
|
224
|
+
if (kind === "issue")
|
|
225
|
+
issues.push(String(row.external_id));
|
|
162
226
|
}
|
|
163
227
|
removed += 1;
|
|
164
228
|
}
|
|
165
229
|
if (isChunkedTrackerKind(kind))
|
|
166
230
|
dropTrackerChunks(database, marked);
|
|
231
|
+
deleteComments(database, accountId, issues, now);
|
|
232
|
+
if (!dryRun)
|
|
233
|
+
restoreListed(accountId, kind, listed);
|
|
167
234
|
return removed;
|
|
168
235
|
});
|
|
169
236
|
};
|
|
@@ -45,10 +45,11 @@ const ISSUES_QUERY = {
|
|
|
45
45
|
termField("state", "kw", "state:state-1", { relation: "the state's id, as states list shows it" }),
|
|
46
46
|
termField("type", "enum", "type:started", { values: [...STATE_TYPES], relation: "repeat for any of several" }),
|
|
47
47
|
termField("label", "kw", "label:label-1", { relation: "the label's id, as labels list shows it" }),
|
|
48
|
+
termField("sprint", "kw", "sprint:sprint-1", { relation: "the sprint's id, as sprints list shows it, or none" }),
|
|
48
49
|
ARCHIVED,
|
|
49
50
|
],
|
|
50
51
|
};
|
|
51
|
-
const TIMES = new Set(["createdAt", "updatedAt", "archivedAt", "completedAt", "canceledAt"]);
|
|
52
|
+
const TIMES = new Set(["createdAt", "updatedAt", "archivedAt", "completedAt", "canceledAt", "startsAt", "endsAt"]);
|
|
52
53
|
const snake = (name) => name.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
53
54
|
/** A tracker's text is someone else's: an agent reads these fields as data, never as instructions. */
|
|
54
55
|
const UNTRUSTED = {
|
|
@@ -57,6 +58,7 @@ const UNTRUSTED = {
|
|
|
57
58
|
state: ["name"],
|
|
58
59
|
label: ["name"],
|
|
59
60
|
project: ["name", "description", "status"],
|
|
61
|
+
sprint: ["name", "description"],
|
|
60
62
|
issue: ["title", "description", "state_name", "labels_names"],
|
|
61
63
|
comment: ["body"],
|
|
62
64
|
};
|
|
@@ -90,6 +92,7 @@ const trackerSync = v.strictObject({
|
|
|
90
92
|
})),
|
|
91
93
|
gaps: v.array(v.strictObject({ kind: v.picklist(TRACKER_KINDS), message: text, scope: v.optional(text) })),
|
|
92
94
|
progress: v.strictObject({ requests: count, saved: count, steps: count }),
|
|
95
|
+
deletions: v.strictObject({ checked: v.nullable(text), due: text }),
|
|
93
96
|
tasks: v.optional(v.union([
|
|
94
97
|
v.strictObject({ opened: count, closed: count, reopened: count, renamed: count }),
|
|
95
98
|
v.strictObject({ skipped: text }),
|
|
@@ -129,7 +132,10 @@ const resumeStep = (opts, why, extra = {}) => ({
|
|
|
129
132
|
why,
|
|
130
133
|
safe_to_auto_execute: true,
|
|
131
134
|
});
|
|
135
|
+
// Not a failure of the run: a key without the scope lacks it on every sync, so it must not mark the sync partial.
|
|
136
|
+
const UNREAD = "tracker.kind-unread";
|
|
132
137
|
const trackerIssues = (report) => [
|
|
138
|
+
...report.gaps.map((gap) => ({ code: "permission_error", reason: UNREAD, source: `tracker:${gap.kind}` })),
|
|
133
139
|
...report.synced
|
|
134
140
|
.filter((one) => one.error !== undefined)
|
|
135
141
|
.map((one) => ({ code: "provider_error", reason: "sync.partial", source: `tracker:${one.kind}` })),
|
|
@@ -194,7 +200,10 @@ const combinedAnswer = (tracker, documents, opts, embedError) => {
|
|
|
194
200
|
...(outcome?.meta.issues ?? []),
|
|
195
201
|
...(documentsError ? [failed("documents", documentsError)] : []),
|
|
196
202
|
];
|
|
197
|
-
const complete = report?.state === "complete" &&
|
|
203
|
+
const complete = report?.state === "complete" &&
|
|
204
|
+
outcome !== undefined &&
|
|
205
|
+
outcome.meta.complete !== false &&
|
|
206
|
+
issues.every((one) => one.reason === UNREAD);
|
|
198
207
|
const [trackerStep] = report ? trackerNext(report, opts) : [];
|
|
199
208
|
const resume = trackerStep !== undefined || outcome?.next.some(({ step }) => step === "sync.run");
|
|
200
209
|
const next = [
|
|
@@ -212,7 +221,7 @@ const combinedAnswer = (tracker, documents, opts, embedError) => {
|
|
|
212
221
|
? { ...report, complete, documents: documentsPart }
|
|
213
222
|
: { complete: false, synced: [], error: trackerError, documents: documentsPart };
|
|
214
223
|
return itemOf(item, {
|
|
215
|
-
...(complete ? {} : { meta: { complete: false, ...(issues.length ? { issues } : {}) } }),
|
|
224
|
+
...(complete && !issues.length ? {} : { meta: { complete: false, ...(issues.length ? { issues } : {}) } }),
|
|
216
225
|
...(next.length ? { next } : {}),
|
|
217
226
|
});
|
|
218
227
|
};
|
|
@@ -305,10 +314,10 @@ const addTrackerCommandsDefinition = (program, options) => {
|
|
|
305
314
|
}
|
|
306
315
|
});
|
|
307
316
|
const { documents } = options;
|
|
308
|
-
const sync = example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), documents ? "tracker_documents_sync" : "tracker_sync", documents ? trackerDocumentsSync : trackerSync).description("bring the tracker's copy in the local store up to date: teams, users, states, labels, projects,
|
|
309
|
-
"comments that changed since the last sync, or everything with --rescan; once a day it also finds
|
|
310
|
-
"tracker deleted. Open issues assigned to you become your tasks,
|
|
311
|
-
"canceled, deleted or goes to someone else. " +
|
|
317
|
+
const sync = example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), documents ? "tracker_documents_sync" : "tracker_sync", documents ? trackerDocumentsSync : trackerSync).description("bring the tracker's copy in the local store up to date: teams, users, states, labels, projects, sprints, " +
|
|
318
|
+
"issues and comments that changed since the last sync, or everything with --rescan; once a day it also finds " +
|
|
319
|
+
"what the tracker deleted, and says when it next will. Open issues assigned to you become your tasks, " +
|
|
320
|
+
"and close when the issue is done, canceled, a duplicate, deleted or goes to someone else. " +
|
|
312
321
|
(documents
|
|
313
322
|
? "It also imports what changed in the chosen document folders, answered under documents; a part that " +
|
|
314
323
|
"fails leaves the other's answer. "
|
|
@@ -407,7 +416,9 @@ const addTrackerCommandsDefinition = (program, options) => {
|
|
|
407
416
|
throw new InvalidArgumentError("issues list takes field:value terms, each one whole value");
|
|
408
417
|
const types = (lists.get("type") ?? []).map((one) => one.value.toLowerCase());
|
|
409
418
|
const terms = new Map([...lists].filter(([field]) => field !== "type").map(([field, [one]]) => [field, one?.value]));
|
|
410
|
-
const
|
|
419
|
+
const noneOr = (field) => (terms.get(field)?.toLowerCase() === "none" ? "none" : terms.get(field));
|
|
420
|
+
const assignee = noneOr("assignee");
|
|
421
|
+
const sprint = noneOr("sprint");
|
|
411
422
|
await within(command, true, async (run) => {
|
|
412
423
|
const filter = {
|
|
413
424
|
...(terms.has("team") ? { parent: terms.get("team") } : {}),
|
|
@@ -416,6 +427,7 @@ const addTrackerCommandsDefinition = (program, options) => {
|
|
|
416
427
|
...(terms.has("state") ? { state: terms.get("state") } : {}),
|
|
417
428
|
...(types.length ? { stateTypes: types } : {}),
|
|
418
429
|
...(terms.has("label") ? { label: terms.get("label") } : {}),
|
|
430
|
+
...(sprint !== undefined ? { sprint: sprint === "none" ? null : sprint } : {}),
|
|
419
431
|
...(terms.has("archived") ? { archived: true } : {}),
|
|
420
432
|
limit: opts.limit,
|
|
421
433
|
offset: (opts.page - 1) * opts.limit,
|
|
@@ -487,6 +499,7 @@ const addTrackerCommandsDefinition = (program, options) => {
|
|
|
487
499
|
});
|
|
488
500
|
for (const [kind, plural, what] of [
|
|
489
501
|
["project", "projects", "the tracker's projects: status, lead, teams and target date"],
|
|
502
|
+
["sprint", "sprints", "each team's sprints (Linear's cycles): number, start, end and when completed"],
|
|
490
503
|
["team", "teams", "the tracker's teams"],
|
|
491
504
|
["user", "users", "the tracker's users, each with the person the store knows by the same e-mail"],
|
|
492
505
|
["state", "states", "each team's workflow states and their type"],
|
|
@@ -26,7 +26,10 @@ export interface TrackerManifestEntity<K extends TrackerKind = TrackerKind> {
|
|
|
26
26
|
list: TrackerOperationCall;
|
|
27
27
|
/** Rows changed since `{since}`, the last cursor less the overlap; absent, every sync lists in full. */
|
|
28
28
|
changes?: TrackerChangesCall;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Every id, archived ones too, to find deletions; absent, `list`. Give one that selects only the id, and what the
|
|
31
|
+
* map's `deleted` reads: a row the tracker lists but calls deleted is left out, so the pass marks it deleted.
|
|
32
|
+
*/
|
|
30
33
|
ids?: TrackerOperationCall;
|
|
31
34
|
map: {
|
|
32
35
|
readonly [F in keyof TrackerRecords[K]]?: CrmRule;
|
|
@@ -141,7 +141,10 @@ export const parseTrackerManifest = (input, api) => {
|
|
|
141
141
|
throw invalid(`entities.${kind}.changes`, 'no "{since}" in its variables');
|
|
142
142
|
}
|
|
143
143
|
if (one.ids)
|
|
144
|
-
checkCall(`entities.${kind}.ids`, one.ids, {
|
|
144
|
+
checkCall(`entities.${kind}.ids`, one.ids, {
|
|
145
|
+
externalId: one.map.externalId,
|
|
146
|
+
...(one.map.deleted === undefined ? {} : { deleted: one.map.deleted }),
|
|
147
|
+
});
|
|
145
148
|
}
|
|
146
149
|
for (const [kind, one] of Object.entries(manifest.entities))
|
|
147
150
|
if (one && !manifest.kinds.includes(kind))
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { crmValues } from "../../crm/index.js";
|
|
2
2
|
import { convert, mapFields, rulePaths } from "../../crm/manifest/map.js";
|
|
3
3
|
import { STATE_TYPES } from "../../domain/tracker.js";
|
|
4
|
-
const TIMES = {
|
|
4
|
+
const TIMES = {
|
|
5
|
+
externalId: "id",
|
|
6
|
+
createdAt: "epoch",
|
|
7
|
+
updatedAt: "epoch",
|
|
8
|
+
archivedAt: "epoch",
|
|
9
|
+
deleted: "bool",
|
|
10
|
+
};
|
|
5
11
|
// A literal after `key:` reads as a permission key to src/cli/permission-keys.test.ts.
|
|
6
12
|
const KEY = "text";
|
|
7
13
|
/** Each of our fields and how a value the tracker sent becomes it. */
|
|
@@ -20,6 +26,16 @@ export const TRACKER_FIELDS = {
|
|
|
20
26
|
targetDate: "day",
|
|
21
27
|
url: "text",
|
|
22
28
|
},
|
|
29
|
+
sprint: {
|
|
30
|
+
...TIMES,
|
|
31
|
+
name: "text",
|
|
32
|
+
number: "number",
|
|
33
|
+
description: "text",
|
|
34
|
+
team: "id",
|
|
35
|
+
startsAt: "epoch",
|
|
36
|
+
endsAt: "epoch",
|
|
37
|
+
completedAt: "epoch",
|
|
38
|
+
},
|
|
23
39
|
issue: {
|
|
24
40
|
...TIMES,
|
|
25
41
|
title: "text",
|
|
@@ -28,6 +44,7 @@ export const TRACKER_FIELDS = {
|
|
|
28
44
|
state: "id",
|
|
29
45
|
team: "id",
|
|
30
46
|
project: "id",
|
|
47
|
+
sprint: "id",
|
|
31
48
|
assignee: "id",
|
|
32
49
|
creator: "id",
|
|
33
50
|
labels: "ids",
|
|
@@ -47,6 +64,7 @@ const REQUIRED = {
|
|
|
47
64
|
state: { name: "" },
|
|
48
65
|
label: { name: "" },
|
|
49
66
|
project: { name: "" },
|
|
67
|
+
sprint: { name: "" },
|
|
50
68
|
issue: { title: "" },
|
|
51
69
|
comment: { body: "" },
|
|
52
70
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
2
2
|
import { nextPage, parameterValue, withValue } from "../../cli/service-api-manifest.js";
|
|
3
3
|
import { crmValues } from "../../crm/index.js";
|
|
4
|
-
import { at, evaluate, MISSING } from "../../crm/manifest/map.js";
|
|
4
|
+
import { at, convert, evaluate, MISSING } from "../../crm/manifest/map.js";
|
|
5
5
|
import { parseTrackerManifest, } from "./manifest.js";
|
|
6
6
|
import { mapTrackerRecord } from "./map.js";
|
|
7
7
|
const OVERLAP_MS = 10 * 60_000;
|
|
@@ -130,7 +130,11 @@ export const trackerSourceFromManifest = (input, options) => {
|
|
|
130
130
|
const entity = entityOf(kind);
|
|
131
131
|
const { rows, next } = await readPage(entity.ids ?? entity.list, undefined, page, metered(context));
|
|
132
132
|
const rule = entity.map.externalId;
|
|
133
|
+
const { deleted } = entity.map;
|
|
133
134
|
const items = rows.flatMap((raw) => {
|
|
135
|
+
// Linear's trash moves no updatedAt, so only this pass sees a trashed row: leaving it out marks it deleted.
|
|
136
|
+
if (deleted !== undefined && convert("bool", evaluate(deleted, raw)) === true)
|
|
137
|
+
return [];
|
|
134
138
|
const found = evaluate(rule, raw);
|
|
135
139
|
const externalId = found === MISSING ? null : crmValues.id(found);
|
|
136
140
|
return externalId === null ? [] : [externalId];
|
package/dist/tracker/sync.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface TrackerSyncResult {
|
|
|
22
22
|
/** The cursor was dead, so the round became a full one. */
|
|
23
23
|
reset: boolean;
|
|
24
24
|
state: "partial" | "complete";
|
|
25
|
+
/** Rows that changed in the copy: new, different, or deleted or back again. A row read again as it was is not. */
|
|
25
26
|
saved: number;
|
|
26
27
|
/** Rows a complete id pass did not list, now marked deleted. */
|
|
27
28
|
unlisted: number;
|
|
@@ -50,6 +51,14 @@ export interface TrackerSyncReport {
|
|
|
50
51
|
saved: number;
|
|
51
52
|
steps: number;
|
|
52
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* When the id pass that finds deleted rows last ran for every kind (`null` before the first) and when it is next due:
|
|
56
|
+
* a sync between them finds no deletion.
|
|
57
|
+
*/
|
|
58
|
+
deletions: {
|
|
59
|
+
checked: string | null;
|
|
60
|
+
due: string;
|
|
61
|
+
};
|
|
53
62
|
/**
|
|
54
63
|
* The owner's tasks from issues assigned to the signed-in user, brought in line with the copy. Absent when the
|
|
55
64
|
* tracker cannot name its user or the run was cancelled; `skipped` says why they were left as they were.
|
package/dist/tracker/sync.js
CHANGED
|
@@ -65,8 +65,9 @@ const syncChanges = async (run, kind, result, mode) => {
|
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
67
|
if (page.items.length) {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const changed = await store.tracker.save(account, kind, page.items, run.now);
|
|
69
|
+
result.saved += changed;
|
|
70
|
+
run.report.progress.saved += changed;
|
|
70
71
|
}
|
|
71
72
|
run.report.progress.steps += 1;
|
|
72
73
|
if (!page.hasMore) {
|
|
@@ -172,6 +173,7 @@ export const syncTracker = async (source, store, account, options = {}) => {
|
|
|
172
173
|
complete: true,
|
|
173
174
|
state: "complete",
|
|
174
175
|
progress: { requests: 0, saved: 0, steps: 0 },
|
|
176
|
+
deletions: { checked: null, due: new Date(now).toISOString() },
|
|
175
177
|
};
|
|
176
178
|
const said = new Set();
|
|
177
179
|
const run = {
|
|
@@ -243,6 +245,10 @@ export const syncTracker = async (source, store, account, options = {}) => {
|
|
|
243
245
|
}
|
|
244
246
|
await store.sync.setSyncState(account, RESUME, report.stopped ? JSON.stringify({ v: 1, done: [...done], ...(mode.full ? { rescan: true } : {}) }) : "null");
|
|
245
247
|
await store.sync.setSyncState(account, GAPS, JSON.stringify(report.gaps));
|
|
248
|
+
const passes = await Promise.all(kinds.map(async (kind) => parsed((await store.sync.syncState(account, trackerCursorName(kind)))?.value)?.passAt ?? 0));
|
|
249
|
+
const checked = passes.reduce((least, one) => Math.min(least, one), passes[0] ?? 0);
|
|
250
|
+
if (checked > 0)
|
|
251
|
+
report.deletions = { checked: new Date(checked).toISOString(), due: new Date(checked + passEvery).toISOString() };
|
|
246
252
|
if (source.self && source.traits.kinds.includes("issue") && report.stopped !== "cancelled")
|
|
247
253
|
report.tasks = await ownTasks(run, source.self.bind(source));
|
|
248
254
|
return report;
|
package/dist/tracker/tasks.d.ts
CHANGED
|
@@ -28,10 +28,10 @@ export interface TrackerTaskChanges {
|
|
|
28
28
|
/**
|
|
29
29
|
* Brings the owner's tasks in line with the tracker's copy, after a sync: each live issue assigned to `self` whose
|
|
30
30
|
* state is open work becomes a task, and every task from an issue takes the issue's current title. A task closes when
|
|
31
|
-
* its issue is completed, canceled, archived or deleted, and a task the sync made also when the issue goes
|
|
32
|
-
* else; `issues assign` picks an issue whoever holds it. A task the sync closed opens again once its issue
|
|
33
|
-
* work again (and, for one the sync made, assigned to `self` again); one the owner closed stays closed, as a
|
|
34
|
-
* task does. Nothing is written to the tracker.
|
|
31
|
+
* its issue is completed, canceled, a duplicate, archived or deleted, and a task the sync made also when the issue goes
|
|
32
|
+
* to someone else; `issues assign` picks an issue whoever holds it. A task the sync closed opens again once its issue
|
|
33
|
+
* is open work again (and, for one the sync made, assigned to `self` again); one the owner closed stays closed, as a
|
|
34
|
+
* dismissed task does. Nothing is written to the tracker.
|
|
35
35
|
*/
|
|
36
36
|
export declare const syncTrackerTasks: (store: MessageStore, account: AccountKey, self: string, { now }?: {
|
|
37
37
|
now?: number;
|
package/dist/tracker/tasks.js
CHANGED
|
@@ -54,6 +54,7 @@ export const trackerIssueTask = async (store, account, issue, { dueAt, now = Dat
|
|
|
54
54
|
const closing = {
|
|
55
55
|
completed: { as: "done", reason: (provider) => `the issue was completed in ${provider}` },
|
|
56
56
|
canceled: { as: "dismissed", reason: (provider) => `the issue was canceled in ${provider}` },
|
|
57
|
+
duplicate: { as: "dismissed", reason: (provider) => `the issue was marked a duplicate in ${provider}` },
|
|
57
58
|
deleted: { as: "dismissed", reason: (provider) => `the issue was deleted in ${provider}` },
|
|
58
59
|
archived: { as: "dismissed", reason: (provider) => `the issue was archived in ${provider}` },
|
|
59
60
|
reassigned: { as: "dismissed", reason: (provider) => `the issue was assigned to someone else in ${provider}` },
|
|
@@ -84,10 +85,10 @@ const lastClose = async (store, id) => {
|
|
|
84
85
|
/**
|
|
85
86
|
* Brings the owner's tasks in line with the tracker's copy, after a sync: each live issue assigned to `self` whose
|
|
86
87
|
* state is open work becomes a task, and every task from an issue takes the issue's current title. A task closes when
|
|
87
|
-
* its issue is completed, canceled, archived or deleted, and a task the sync made also when the issue goes
|
|
88
|
-
* else; `issues assign` picks an issue whoever holds it. A task the sync closed opens again once its issue
|
|
89
|
-
* work again (and, for one the sync made, assigned to `self` again); one the owner closed stays closed, as a
|
|
90
|
-
* task does. Nothing is written to the tracker.
|
|
88
|
+
* its issue is completed, canceled, a duplicate, archived or deleted, and a task the sync made also when the issue goes
|
|
89
|
+
* to someone else; `issues assign` picks an issue whoever holds it. A task the sync closed opens again once its issue
|
|
90
|
+
* is open work again (and, for one the sync made, assigned to `self` again); one the owner closed stays closed, as a
|
|
91
|
+
* dismissed task does. Nothing is written to the tracker.
|
|
91
92
|
*/
|
|
92
93
|
export const syncTrackerTasks = async (store, account, self, { now = Date.now() } = {}) => {
|
|
93
94
|
const changes = { opened: 0, closed: 0, reopened: 0, renamed: 0 };
|
|
@@ -132,7 +133,7 @@ export const syncTrackerTasks = async (store, account, self, { now = Date.now()
|
|
|
132
133
|
? "deleted"
|
|
133
134
|
: issue?.archivedAt
|
|
134
135
|
? "archived"
|
|
135
|
-
: type === "completed" || type === "canceled"
|
|
136
|
+
: type === "completed" || type === "canceled" || type === "duplicate"
|
|
136
137
|
? type
|
|
137
138
|
: task.origin === "rule" && !picked.has(task.id) && issue?.assignee !== self
|
|
138
139
|
? issue?.assignee
|
|
@@ -23,6 +23,8 @@ export interface TrackerManifestFake extends GraphqlFake {
|
|
|
23
23
|
archive(kind: TrackerKind, id: string): void;
|
|
24
24
|
/** Deletes one row outright. */
|
|
25
25
|
remove(kind: TrackerKind, id: string): void;
|
|
26
|
+
/** Moves one row to the trash, as Linear does: archived now and `deleted`, its change time as it was. */
|
|
27
|
+
trash(kind: TrackerKind, id: string): void;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* A GraphQL tracker in memory, built from a source manifest and the generated API it names: cli-base's strict
|
|
@@ -25,6 +25,7 @@ const TARGETS = {
|
|
|
25
25
|
label: "label",
|
|
26
26
|
labels: "label",
|
|
27
27
|
project: "project",
|
|
28
|
+
sprint: "sprint",
|
|
28
29
|
lead: "user",
|
|
29
30
|
assignee: "user",
|
|
30
31
|
creator: "user",
|
|
@@ -148,6 +149,8 @@ export const trackerManifestFake = (input, options) => {
|
|
|
148
149
|
// A state of a type outside STATE_TYPES is dropped by the map, and its issues with it.
|
|
149
150
|
if (kind === "state" && field === "type")
|
|
150
151
|
return STATE_TYPES[n % STATE_TYPES.length];
|
|
152
|
+
if (field === "deleted")
|
|
153
|
+
return false;
|
|
151
154
|
switch (type) {
|
|
152
155
|
case "epoch":
|
|
153
156
|
return field === "createdAt" || field === "updatedAt" ? { ms: SEEDED + n * 60_000 } : null;
|
|
@@ -451,6 +454,14 @@ export const trackerManifestFake = (input, options) => {
|
|
|
451
454
|
const row = find(kind, id);
|
|
452
455
|
rows[kind]?.splice(rows[kind].indexOf(row), 1);
|
|
453
456
|
},
|
|
457
|
+
trash(kind, id) {
|
|
458
|
+
const row = find(kind, id);
|
|
459
|
+
const path = timePath(kind, "deleted");
|
|
460
|
+
if (path === undefined)
|
|
461
|
+
throw new Error(`${kind}: map deleted to a path, so the fake can trash a row`);
|
|
462
|
+
stamp(kind, row, "archivedAt");
|
|
463
|
+
write(row, items.get(kind), path, true);
|
|
464
|
+
},
|
|
454
465
|
};
|
|
455
466
|
};
|
|
456
467
|
const externalIdOf = (manifest, kind, row) => {
|
|
@@ -484,6 +495,7 @@ export const trackerManifestFixture = (manifest, options) => {
|
|
|
484
495
|
// no other row points at.
|
|
485
496
|
const changed = ["issue", ...[...parsed.kinds].reverse()].find((kind) => parsed.kinds.includes(kind) && parsed.entities[kind]?.changes);
|
|
486
497
|
const archivable = changed && parsed.entities[changed]?.map.archivedAt !== undefined;
|
|
498
|
+
const trashable = archivable && parsed.entities[changed]?.map.deleted !== undefined;
|
|
487
499
|
const first = (kind) => held[kind]?.[0];
|
|
488
500
|
const last = (kind) => held[kind]?.at(-1);
|
|
489
501
|
return {
|
|
@@ -514,6 +526,14 @@ export const trackerManifestFixture = (manifest, options) => {
|
|
|
514
526
|
},
|
|
515
527
|
}
|
|
516
528
|
: {}),
|
|
529
|
+
...(changed && trashable
|
|
530
|
+
? {
|
|
531
|
+
trash: () => {
|
|
532
|
+
fake.trash(changed, last(changed));
|
|
533
|
+
return { kind: changed, id: last(changed) };
|
|
534
|
+
},
|
|
535
|
+
}
|
|
536
|
+
: {}),
|
|
517
537
|
},
|
|
518
538
|
};
|
|
519
539
|
};
|
|
@@ -29,6 +29,14 @@ export interface TrackerSourceFaults {
|
|
|
29
29
|
kind: TrackerKind;
|
|
30
30
|
id: string;
|
|
31
31
|
}>;
|
|
32
|
+
/** Moves one row to the tracker's trash, where it is still listed but deleted, as Linear's trash keeps an issue. */
|
|
33
|
+
trash?(): {
|
|
34
|
+
kind: TrackerKind;
|
|
35
|
+
id: string;
|
|
36
|
+
} | Promise<{
|
|
37
|
+
kind: TrackerKind;
|
|
38
|
+
id: string;
|
|
39
|
+
}>;
|
|
32
40
|
}
|
|
33
41
|
/** One adapter over recorded or faked answers, fresh for each case. Every kind its traits name lists at least one row. */
|
|
34
42
|
export interface TrackerSourceFixture {
|
|
@@ -49,7 +49,7 @@ const optionalTime = (value) => value === undefined || value === null || (typeof
|
|
|
49
49
|
const checkShape = (kind, record) => {
|
|
50
50
|
const at = `${kind} ${String(record.externalId)}`;
|
|
51
51
|
assert.ok(typeof record.externalId === "string" && record.externalId.trim(), `${kind}: a record has an id`);
|
|
52
|
-
for (const field of ["createdAt", "updatedAt", "archivedAt", "completedAt", "canceledAt"])
|
|
52
|
+
for (const field of ["createdAt", "updatedAt", "archivedAt", "completedAt", "canceledAt", "startsAt", "endsAt"])
|
|
53
53
|
assert.ok(optionalTime(record[field]), `${at}: ${field} is epoch ms or null`);
|
|
54
54
|
const named = kind === "issue" ? "title" : kind === "comment" ? "body" : "name";
|
|
55
55
|
assert.ok(typeof record[named] === "string", `${at} has its ${named}`);
|
|
@@ -57,8 +57,22 @@ const checkShape = (kind, record) => {
|
|
|
57
57
|
assert.ok(STATE_TYPES.includes(String(record.type)), `${at}: type is one of ${STATE_TYPES}`);
|
|
58
58
|
if (kind === "comment")
|
|
59
59
|
assert.ok(typeof record.issue === "string", `${at} names its issue`);
|
|
60
|
-
for (const field of [
|
|
60
|
+
for (const field of [
|
|
61
|
+
"team",
|
|
62
|
+
"state",
|
|
63
|
+
"project",
|
|
64
|
+
"sprint",
|
|
65
|
+
"assignee",
|
|
66
|
+
"creator",
|
|
67
|
+
"lead",
|
|
68
|
+
"author",
|
|
69
|
+
"parent",
|
|
70
|
+
"key",
|
|
71
|
+
"email",
|
|
72
|
+
])
|
|
61
73
|
assert.ok(optionalText(record[field]), `${at}: ${field} is an id or text, or null`);
|
|
74
|
+
if (record.deleted !== undefined && record.deleted !== null)
|
|
75
|
+
assert.equal(typeof record.deleted, "boolean", `${at}: deleted is true, false or null`);
|
|
62
76
|
for (const field of ["labels", "teams"])
|
|
63
77
|
if (record[field] !== undefined)
|
|
64
78
|
assert.ok(Array.isArray(record[field]) && record[field].every((one) => typeof one === "string"), `${at}: ${field} is a list of ids`);
|
|
@@ -205,6 +219,18 @@ export const trackerSourceContract = (make) => [
|
|
|
205
219
|
assert.ok(!(await allIds(source, kind)).has(id), `${kind} ${id}: a deleted row is not in ids()`);
|
|
206
220
|
},
|
|
207
221
|
},
|
|
222
|
+
{
|
|
223
|
+
name: "faults: a trashed row is a deleted one: a full list calls it deleted, and ids() leaves it out",
|
|
224
|
+
async run() {
|
|
225
|
+
const { source, faults } = await make();
|
|
226
|
+
if (!faults?.trash)
|
|
227
|
+
return;
|
|
228
|
+
const { kind, id } = await faults.trash();
|
|
229
|
+
const found = (await listAll(source, kind, null)).items.find((one) => one.externalId === id);
|
|
230
|
+
assert.ok(found?.deleted === true, `${kind} ${id}: a full list carries deleted: true`);
|
|
231
|
+
assert.ok(!(await allIds(source, kind)).has(id), `${kind} ${id}: a trashed row is not in ids()`);
|
|
232
|
+
},
|
|
233
|
+
},
|
|
208
234
|
{
|
|
209
235
|
name: "faults: a full list cut after its first page goes on from that page in a new run, nothing lost or repeated",
|
|
210
236
|
async run() {
|
|
@@ -28,6 +28,11 @@ export interface FakeTrackerSource extends TrackerSource, TrackerWriter {
|
|
|
28
28
|
archive(kind: TrackerKind, externalId: string): void;
|
|
29
29
|
/** Deletes one row outright, as only an id pass finds. */
|
|
30
30
|
remove(kind: TrackerKind, externalId: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Moves one row to the trash, as Linear does: still listed, archived and `deleted`, with its `updatedAt` as it was,
|
|
33
|
+
* so a change read misses it and only a full list or an id pass, which leaves it out, finds it.
|
|
34
|
+
*/
|
|
35
|
+
trash(kind: TrackerKind, externalId: string): void;
|
|
31
36
|
/** The same tracker, read from a computer whose clock is `ms` off. */
|
|
32
37
|
skewed(ms: number): FakeTrackerSource;
|
|
33
38
|
}
|
|
@@ -37,5 +42,8 @@ export interface FakeTrackerSource extends TrackerSource, TrackerWriter {
|
|
|
37
42
|
* page, so it never spends from the run's budget itself.
|
|
38
43
|
*/
|
|
39
44
|
export declare const fakeTrackerSource: (options: FakeTrackerSourceOptions) => FakeTrackerSource;
|
|
40
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* A small Linear-like workspace: one team, two users, the seven state types, a label, a project, a sprint, three
|
|
47
|
+
* issues.
|
|
48
|
+
*/
|
|
41
49
|
export declare const exampleTrackerRows: () => Required<FakeTrackerRows>;
|
|
@@ -59,7 +59,9 @@ export const fakeTrackerSource = (options) => {
|
|
|
59
59
|
},
|
|
60
60
|
async ids(kind, page, _context) {
|
|
61
61
|
const offset = page === undefined ? 0 : Number(page);
|
|
62
|
-
const all = listOf(kind)
|
|
62
|
+
const all = listOf(kind)
|
|
63
|
+
.filter((one) => one.deleted !== true)
|
|
64
|
+
.map((one) => one.externalId);
|
|
63
65
|
const items = all.slice(offset, offset + size);
|
|
64
66
|
return offset + size < all.length
|
|
65
67
|
? { items, hasMore: true, nextCursor: String(offset + size) }
|
|
@@ -73,6 +75,11 @@ export const fakeTrackerSource = (options) => {
|
|
|
73
75
|
found.archivedAt = clock();
|
|
74
76
|
found.updatedAt = found.archivedAt;
|
|
75
77
|
},
|
|
78
|
+
trash(kind, externalId) {
|
|
79
|
+
const found = find(kind, externalId);
|
|
80
|
+
found.archivedAt = clock();
|
|
81
|
+
found.deleted = true;
|
|
82
|
+
},
|
|
76
83
|
remove(kind, externalId) {
|
|
77
84
|
const list = rows[kind];
|
|
78
85
|
const at = list?.findIndex((one) => one.externalId === externalId) ?? -1;
|
|
@@ -131,7 +138,10 @@ export const fakeTrackerSource = (options) => {
|
|
|
131
138
|
return make(options.skew ?? 0);
|
|
132
139
|
};
|
|
133
140
|
const T0 = Date.UTC(2026, 10, 1);
|
|
134
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* A small Linear-like workspace: one team, two users, the seven state types, a label, a project, a sprint, three
|
|
143
|
+
* issues.
|
|
144
|
+
*/
|
|
135
145
|
export const exampleTrackerRows = () => ({
|
|
136
146
|
team: [{ externalId: "team-1", key: "ENG", name: "Engineering", updatedAt: T0 }],
|
|
137
147
|
user: [
|
|
@@ -145,6 +155,7 @@ export const exampleTrackerRows = () => ({
|
|
|
145
155
|
{ externalId: "state-doing", name: "In Progress", type: "started", team: "team-1", position: 3, updatedAt: T0 },
|
|
146
156
|
{ externalId: "state-done", name: "Done", type: "completed", team: "team-1", position: 4, updatedAt: T0 },
|
|
147
157
|
{ externalId: "state-gone", name: "Canceled", type: "canceled", team: "team-1", position: 5, updatedAt: T0 },
|
|
158
|
+
{ externalId: "state-twin", name: "Duplicate", type: "duplicate", team: "team-1", position: 6, updatedAt: T0 },
|
|
148
159
|
],
|
|
149
160
|
label: [{ externalId: "label-bug", name: "Bug", team: "team-1", updatedAt: T0 }],
|
|
150
161
|
project: [
|
|
@@ -158,6 +169,17 @@ export const exampleTrackerRows = () => ({
|
|
|
158
169
|
updatedAt: T0,
|
|
159
170
|
},
|
|
160
171
|
],
|
|
172
|
+
sprint: [
|
|
173
|
+
{
|
|
174
|
+
externalId: "sprint-1",
|
|
175
|
+
name: "",
|
|
176
|
+
number: 1,
|
|
177
|
+
team: "team-1",
|
|
178
|
+
startsAt: T0,
|
|
179
|
+
endsAt: T0 + 14 * 86_400_000,
|
|
180
|
+
updatedAt: T0,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
161
183
|
issue: [
|
|
162
184
|
{
|
|
163
185
|
externalId: "issue-1",
|
|
@@ -167,6 +189,7 @@ export const exampleTrackerRows = () => ({
|
|
|
167
189
|
state: "state-doing",
|
|
168
190
|
team: "team-1",
|
|
169
191
|
project: "project-1",
|
|
192
|
+
sprint: "sprint-1",
|
|
170
193
|
assignee: "user-1",
|
|
171
194
|
labels: ["label-bug"],
|
|
172
195
|
priority: 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.750.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",
|