@wirecat/cli-core 0.738.0 → 0.740.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 +59 -0
- package/dist/attachments/ocr.d.ts +2 -0
- package/dist/attachments/ocr.js +2 -1
- package/dist/attachments/tesseract.d.ts +11 -0
- package/dist/attachments/tesseract.js +82 -0
- package/dist/cli/documents/file-edit.js +79 -34
- package/dist/cli/documents/file-update.d.ts +5 -0
- package/dist/cli/documents/index.d.ts +2 -1
- package/dist/cli/documents/index.js +2 -1
- package/dist/cli/documents/library.d.ts +12 -0
- package/dist/cli/documents/library.js +33 -3
- package/dist/cli/documents/manifest/manifest.d.ts +10 -0
- package/dist/cli/documents/manifest/manifest.js +9 -1
- package/dist/cli/documents/manifest/source.d.ts +4 -1
- package/dist/cli/documents/manifest/source.js +67 -1
- package/dist/cli/documents/rekey.d.ts +22 -0
- package/dist/cli/documents/rekey.js +25 -0
- package/dist/documents/file-mirror-model.d.ts +4 -1
- package/dist/documents/index.d.ts +1 -0
- package/dist/documents/index.js +1 -0
- package/dist/documents/model.d.ts +8 -0
- package/dist/errors/reasons.js +6 -15
- package/dist/errors/sftp-reasons.d.ts +5 -0
- package/dist/errors/sftp-reasons.js +15 -0
- package/dist/office/create.d.ts +38 -7
- package/dist/office/create.js +84 -20
- package/dist/office/index.d.ts +1 -1
- package/dist/services/documents/file-text.d.ts +6 -1
- package/dist/services/documents/file-text.js +29 -11
- package/dist/services/documents/ingestion.d.ts +5 -0
- package/dist/services/documents/ingestion.js +21 -1
- package/dist/services/documents/plan.js +151 -102
- package/dist/services/documents/ports.d.ts +3 -0
- package/dist/services/documents/scans.d.ts +42 -0
- package/dist/services/documents/scans.js +136 -0
- package/dist/services/documents/sync.js +57 -4
- package/dist/services/files/guarded-write.d.ts +6 -0
- package/dist/services/files/guarded-write.js +7 -1
- package/dist/services/files/mirror.js +2 -3
- package/dist/store/sqlite/file-note-rekey.d.ts +8 -0
- package/dist/store/sqlite/file-note-rekey.js +47 -0
- package/dist/store/sqlite/notes.d.ts +7 -2
- package/dist/store/sqlite/notes.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,65 @@ 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.740.0 — 24.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A documents source from a manifest reads a deletions feed in every round of changes.** `deletions` names a call
|
|
13
|
+
that lists the documents deleted since a time (Linear's audit log, where its trash leaves `updatedAt` as it was),
|
|
14
|
+
and each id it names leaves the local copy as `deleted` in the next `sync`, not only after `sync --rescan`. A
|
|
15
|
+
provider that refuses the feed (`permission_error`) does not fail the sync: its answer warns
|
|
16
|
+
`source.deletions-unchecked`, which says `sync --rescan` finds them. A source with `deletions` passes the run's
|
|
17
|
+
`warn` to `documentSourceFromManifest`, or it is refused when built
|
|
18
|
+
([a deletions feed](docs/dev/DOCUMENTS.md#a-deletions-feed)).
|
|
19
|
+
- **A documents sync reads the text of scans and pictures.** A PDF with no text layer and a JPEG, PNG or WebP picture
|
|
20
|
+
are read by OCR, chosen by the profile's `read_scans`: `local` by default (the `tesseract` program on this
|
|
21
|
+
computer, Russian and English, nothing downloaded), `anthropic` or `openai` (the `ai set` model at that provider's
|
|
22
|
+
own address, with pictures allowed), or `off`. At most 20 pages a file and 100 a sync. A scan an earlier sync kept
|
|
23
|
+
by name is read on the next sync, and a sync with no reader says how to install one. A CLI adds
|
|
24
|
+
`DOCUMENT_SCAN_SETTINGS` to `settingsFor` for its config file to take `read_scans`
|
|
25
|
+
([scans and pictures](docs/dev/DOCUMENTS.md#scans-and-pictures)).
|
|
26
|
+
|
|
27
|
+
## 0.739.0 — 24.11.2026
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **A documents sync reads every format cli-core's readers read.** `readableFile` now takes Word 97–2003 (`.doc`),
|
|
32
|
+
RTF, HTML, OpenDocument (`.odt`, `.ods`, `.odp`), PowerPoint (`.pptx`) and EPUB beside PDF, docx, xlsx, CSV, TSV,
|
|
33
|
+
plain text and Markdown, so Yandex Disk and other CLIs built on it no longer keep them by name only. Images and
|
|
34
|
+
scans stay by name only.
|
|
35
|
+
- **A documents sync lists several folders at once on a source that sets `parallelListings`** (a whole number up to
|
|
36
|
+
8). A source whose one listing takes seconds (Yandex Disk) can set it, for example to 4, so a sync of many folders
|
|
37
|
+
can take less time. Each listing takes its own request from the run's budget, and the walk files the same
|
|
38
|
+
documents, though the order they are saved in may differ. A call cut short or a failed listing loses nothing: the
|
|
39
|
+
folder stays on the saved walk and is listed again in the next sync. Unset, a sync lists one folder at a time as
|
|
40
|
+
before.
|
|
41
|
+
- **`addFileEditCommands` takes `creates: false`** for a provider that names a file by an id it gives, as Google
|
|
42
|
+
Drive does. `sheets create` and `documents create` are then left out, since a path the user types can't name a
|
|
43
|
+
new file there. The edits, `history` and `restore` stay.
|
|
44
|
+
- **`sheets create` makes several sheets, formulas and bold cells.** `--values` also takes
|
|
45
|
+
`[{"name": "Budget", "header": true, "rows": [...]}]` for several sheets, and a cell may be
|
|
46
|
+
`{"formula": "SUM(B2:B3)"}` or `{"value": "Total", "bold": true}`. Excel and LibreOffice compute the formulas when
|
|
47
|
+
the file opens. A text that starts with `=` still stays text, so data from elsewhere never becomes a formula. Today's
|
|
48
|
+
rows keep working. `createXlsx` takes the same cells and a sheet's `header` ([Editing Office files](docs/office.md#new-files)).
|
|
49
|
+
- **`documents create` makes bold and italic text and tables.** `--payload` also takes `{"text", "bold", "italic"}`,
|
|
50
|
+
`{"runs": [{"text": "grew", "bold": true}]}` and `{"table": [["Item", "Cost"], ["Rent", "950"]], "header": true}`.
|
|
51
|
+
Today's `[{"text", "style"}]` keeps working, and `createDocx` takes the same entries.
|
|
52
|
+
- **`rekeySyncedDocument`** (`@wirecat/cli-core/documents/cli`) moves a synced document to the new id a provider gave
|
|
53
|
+
the file after a replace, so the owner's tags, the notes about it and its links follow the file. A sync that ran in
|
|
54
|
+
between and filed the file anew is folded into the old document; a failure only warns. Behind it, the documents
|
|
55
|
+
ingestion's `rekey` and `renameFileNote(…, { fold: true })`
|
|
56
|
+
([DOCUMENTS](docs/dev/DOCUMENTS.md#write-one-file-at-the-hash-read)).
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- **A file an older version kept by name as `unsupported type: …` is read on the next sync** once its type is
|
|
61
|
+
readable, even when the file did not change. A file whose read failed (damaged, no text layer) is not read again.
|
|
62
|
+
- **A target's own conflict keeps its words.** `guardedFileWrite` and a mirror's sync replaced every `conflict` from
|
|
63
|
+
`upload` with "changed since it was read; nothing was written", even when the target had done something and said
|
|
64
|
+
so. A conflict with a reason other than `mirror.remote-changed`, such as the new `upload.replace-interrupted`, now
|
|
65
|
+
reaches the caller unchanged.
|
|
66
|
+
|
|
8
67
|
## 0.738.0 — 24.11.2026
|
|
9
68
|
|
|
10
69
|
### Added
|
|
@@ -4,5 +4,7 @@ export interface OcrPipeline {
|
|
|
4
4
|
extractor: string;
|
|
5
5
|
transcribe: (image: ModelImage) => Promise<string>;
|
|
6
6
|
}
|
|
7
|
+
/** Pages one PDF may have to be read by OCR; a longer one answers `too-large`. */
|
|
8
|
+
export declare const MAX_PAGES = 20;
|
|
7
9
|
export declare const ocrImage: (bytes: Uint8Array, pipeline: OcrPipeline, signal?: AbortSignal) => Promise<Extraction>;
|
|
8
10
|
export declare const ocrPdf: (bytes: Uint8Array, pipeline: OcrPipeline, load: LoadEngine, signal?: AbortSignal) => Promise<Extraction>;
|
package/dist/attachments/ocr.js
CHANGED
|
@@ -4,7 +4,8 @@ import { withRecovery } from "../domain/recovery.js";
|
|
|
4
4
|
import { isCliFailure } from "../errors/failures.js";
|
|
5
5
|
import { MAX_MODEL_IMAGE_BYTES } from "../models/types.js";
|
|
6
6
|
import { MAX_TEXT_CHARS } from "./extract.js";
|
|
7
|
-
|
|
7
|
+
/** Pages one PDF may have to be read by OCR; a longer one answers `too-large`. */
|
|
8
|
+
export const MAX_PAGES = 20;
|
|
8
9
|
const MAX_PIXELS = 20_000_000;
|
|
9
10
|
const cancelled = (signal) => {
|
|
10
11
|
if (signal?.aborted)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OcrPipeline } from "./ocr.js";
|
|
2
|
+
export declare const TESSERACT_HINT: string;
|
|
3
|
+
/**
|
|
4
|
+
* 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
|
+
*/
|
|
7
|
+
export declare const tesseractPipeline: (env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
8
|
+
pipeline: OcrPipeline;
|
|
9
|
+
} | {
|
|
10
|
+
missing: string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { MAX_TEXT_CHARS } from "./limits.js";
|
|
4
|
+
/** Russian first: an owner's scans are more often Russian, and the order only breaks ties. */
|
|
5
|
+
const LANGUAGES = ["rus", "eng"];
|
|
6
|
+
const PAGE_MS = 120_000;
|
|
7
|
+
const PROBE_MS = 10_000;
|
|
8
|
+
const PROBE_BYTES = 64 * 1024;
|
|
9
|
+
export const TESSERACT_HINT = "reading scans on this computer needs the tesseract program with its Russian and English data " +
|
|
10
|
+
"(apt install tesseract-ocr tesseract-ocr-rus, brew install tesseract tesseract-lang); scans are read on the next sync";
|
|
11
|
+
const run = (args, env, timeout, { input, signal, errors = false } = {}) => new Promise((resolve, reject) => {
|
|
12
|
+
// The PATH of the run's own environment finds the program, so a test or a moved run picks its own.
|
|
13
|
+
const child = spawn("tesseract", args, {
|
|
14
|
+
env,
|
|
15
|
+
shell: false,
|
|
16
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
17
|
+
timeout,
|
|
18
|
+
windowsHide: true,
|
|
19
|
+
...(signal ? { signal } : {}),
|
|
20
|
+
});
|
|
21
|
+
const chunks = [];
|
|
22
|
+
let size = 0;
|
|
23
|
+
child.stdout.on("data", (chunk) => {
|
|
24
|
+
size += chunk.length;
|
|
25
|
+
// Four bytes a character at most: more than that is never text the store keeps.
|
|
26
|
+
if (size > MAX_TEXT_CHARS * 4)
|
|
27
|
+
child.kill();
|
|
28
|
+
else
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
});
|
|
31
|
+
// Tesseract 3 printed its version and languages to stderr, so a probe reads both; a page's warnings are dropped.
|
|
32
|
+
child.stderr.on("data", (chunk) => {
|
|
33
|
+
if (errors && size < PROBE_BYTES)
|
|
34
|
+
chunks.push(chunk);
|
|
35
|
+
if (errors)
|
|
36
|
+
size += chunk.length;
|
|
37
|
+
});
|
|
38
|
+
child.on("error", reject);
|
|
39
|
+
child.on("close", (code) => resolve({ code, stdout: Buffer.concat(chunks).toString("utf8") }));
|
|
40
|
+
child.stdin.on("error", () => { });
|
|
41
|
+
child.stdin.end(input ?? new Uint8Array());
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* 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.
|
|
46
|
+
*/
|
|
47
|
+
export const tesseractPipeline = async (env, signal) => {
|
|
48
|
+
let version;
|
|
49
|
+
let listed;
|
|
50
|
+
try {
|
|
51
|
+
version = await run(["--version"], env, PROBE_MS, { errors: true });
|
|
52
|
+
listed = await run(["--list-langs"], env, PROBE_MS, { errors: true });
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return { missing: TESSERACT_HINT };
|
|
56
|
+
}
|
|
57
|
+
const number = /tesseract\s+v?(\d+(?:\.\d+)*)/iu.exec(version.stdout)?.[1];
|
|
58
|
+
const installed = new Set(listed.stdout.split(/\r?\n/u).map((line) => line.trim()));
|
|
59
|
+
const languages = LANGUAGES.filter((language) => installed.has(language));
|
|
60
|
+
if (version.code !== 0 || !number || !languages.length)
|
|
61
|
+
return { missing: TESSERACT_HINT };
|
|
62
|
+
const chosen = languages.join("+");
|
|
63
|
+
return {
|
|
64
|
+
pipeline: {
|
|
65
|
+
// The version and the languages name the reading, so installing Russian data later reads the scans again.
|
|
66
|
+
extractor: `ocr:v1:tesseract@${number}:${chosen}`,
|
|
67
|
+
transcribe: async (image) => {
|
|
68
|
+
const read = await run(["stdin", "stdout", "-l", chosen], env, PAGE_MS, {
|
|
69
|
+
input: Buffer.from(image.data, "base64"),
|
|
70
|
+
signal,
|
|
71
|
+
}).catch((error) => {
|
|
72
|
+
if (signal?.aborted)
|
|
73
|
+
throw new CliError("cancelled", "OCR cancelled");
|
|
74
|
+
throw error;
|
|
75
|
+
});
|
|
76
|
+
if (read.code !== 0)
|
|
77
|
+
throw new Error("tesseract failed");
|
|
78
|
+
return read.stdout.trim();
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -113,8 +113,35 @@ const docxEditsOf = (payload) => payload.map((edit) => {
|
|
|
113
113
|
};
|
|
114
114
|
return edit;
|
|
115
115
|
});
|
|
116
|
-
const
|
|
117
|
-
const
|
|
116
|
+
const SCALAR = v.union([v.string(), v.number(), v.boolean(), v.null()]);
|
|
117
|
+
const BOLD = v.optional(v.boolean());
|
|
118
|
+
const NEW_ROWS = v.array(v.array(v.union([
|
|
119
|
+
SCALAR,
|
|
120
|
+
v.strictObject({ formula: v.string(), bold: BOLD }),
|
|
121
|
+
v.strictObject({ value: SCALAR, bold: BOLD }),
|
|
122
|
+
])));
|
|
123
|
+
const NEW_VALUES = v.union([
|
|
124
|
+
v.pipe(NEW_ROWS, v.minLength(1)),
|
|
125
|
+
v.pipe(v.array(v.strictObject({ name: v.string(), rows: NEW_ROWS, header: v.optional(v.boolean()) })), v.minLength(1)),
|
|
126
|
+
]);
|
|
127
|
+
const isRows = (values) => values.every(Array.isArray);
|
|
128
|
+
const NEW_VALUES_SHAPE = 'rows of cells as JSON, such as [["Item", "Cost"], ["Rent", 950], ["Total", {"formula": "SUM(B2)"}]], or sheets ' +
|
|
129
|
+
'as [{"name": "Budget", "rows": [...], "header": true}]; a cell is a text, number, boolean, null, ' +
|
|
130
|
+
'{"formula": "…"} or {"value": …, "bold": true}';
|
|
131
|
+
const STYLE = v.optional(v.picklist(NEW_PARAGRAPH_STYLES));
|
|
132
|
+
const NEW_PARAGRAPHS = v.pipe(v.array(v.union([
|
|
133
|
+
v.strictObject({ text: v.string(), style: STYLE, bold: BOLD, italic: BOLD }),
|
|
134
|
+
v.strictObject({
|
|
135
|
+
runs: v.pipe(v.array(v.strictObject({ text: v.string(), bold: BOLD, italic: BOLD })), v.minLength(1)),
|
|
136
|
+
style: STYLE,
|
|
137
|
+
}),
|
|
138
|
+
v.strictObject({
|
|
139
|
+
table: v.array(v.array(v.pipe(v.union([v.string(), v.number()]), v.toString()))),
|
|
140
|
+
header: v.optional(v.boolean()),
|
|
141
|
+
}),
|
|
142
|
+
])), v.minLength(1));
|
|
143
|
+
const NEW_PARAGRAPHS_SHAPE = 'paragraphs and tables as JSON: [{"text": "…", "style": "Heading1"}, {"runs": [{"text": "…", "bold": true}]}, ' +
|
|
144
|
+
`{"table": [["Item", "Cost"], ["Rent", "950"]], "header": true}]; a style is one of ${NEW_PARAGRAPH_STYLES.join(", ")}`;
|
|
118
145
|
const addFileEditCommandsDefinition = (files, helpers) => {
|
|
119
146
|
const { prefix, place } = wordsOf(helpers.words);
|
|
120
147
|
const group = files.name();
|
|
@@ -268,22 +295,35 @@ const addFileEditCommandsDefinition = (files, helpers) => {
|
|
|
268
295
|
}
|
|
269
296
|
});
|
|
270
297
|
});
|
|
271
|
-
|
|
272
|
-
.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
298
|
+
if (helpers.creates !== false)
|
|
299
|
+
examples(annotate(sheets.command("create"), { effects: REMOTE_WRITE, offline: false })
|
|
300
|
+
.summary("create a new workbook from rows of values and formulas")
|
|
301
|
+
.description(`create a new .xlsx on ${place} from rows from A1: one sheet, or several given as [{name, rows, header?}]. ` +
|
|
302
|
+
"Numbers and booleans are typed, a text stays text, even one that starts with =. A formula is only " +
|
|
303
|
+
'{"formula": "SUM(B2:B3)"}, computed when the file opens; {"value": "Total", "bold": true} is a bold cell ' +
|
|
304
|
+
"and header: true makes a sheet's first row bold. A file already there is refused: change it with sheets update")
|
|
305
|
+
.argument("<path>", `the new .xlsx file on ${place}`)
|
|
306
|
+
.option("--values <json>", 'the rows as JSON, or [{"name", "rows", "header"?}] for several sheets; a cell is a text, number, ' +
|
|
307
|
+
'boolean, null (empty), {"formula": "…", "bold"?} or {"value": …, "bold"?}')
|
|
308
|
+
.option("--name <name>", "the sheet's name when --values is rows; Sheet1 without it"), [
|
|
309
|
+
`${prefix} ${group} sheets create /budget.xlsx --values '[["Item", "Cost"], ["Rent", 950]]' --name Budget`,
|
|
310
|
+
`${prefix} ${group} sheets create /budget.xlsx --values '[{"name": "Budget", "header": true, "rows": [["Item", "Cost"], ["Rent", 950], ["Food", 300], [{"value": "Total", "bold": true}, {"formula": "SUM(B2:B3)"}]]}]'`,
|
|
311
|
+
]).action(async function (input, args) {
|
|
312
|
+
if (args.values === undefined)
|
|
313
|
+
throw new CliError("validation_error", `give the rows with --values: ${NEW_VALUES_SHAPE}`, {
|
|
314
|
+
param: "--values",
|
|
315
|
+
});
|
|
316
|
+
const values = jsonOf(args.values, "--values", NEW_VALUES, NEW_VALUES_SHAPE);
|
|
317
|
+
const sheets = isRows(values) ? [{ name: args.name ?? "Sheet1", rows: values }] : values;
|
|
318
|
+
if (args.name !== undefined && !isRows(values))
|
|
319
|
+
throw new CliError("validation_error", "--name names the one sheet of rows; with sheets, each has its name", {
|
|
320
|
+
param: "--name",
|
|
321
|
+
});
|
|
322
|
+
await createNew(this, "sheets", input, ".xlsx", {
|
|
323
|
+
bytes: createXlsx({ sheets }),
|
|
324
|
+
answer: { sheets: sheets.map(({ name, rows }) => ({ name, rows: rows.length })) },
|
|
325
|
+
});
|
|
285
326
|
});
|
|
286
|
-
});
|
|
287
327
|
const documents = annotate(files.command("documents"), { effects: REMOTE_READ }).description(`the paragraphs of a Word document (.docx) on ${place}, read and changed in place`);
|
|
288
328
|
examples(marksUntrusted(annotate(documents.command("show"), { effects: REMOTE_READ, offline: false }), ["paragraphs.text"])
|
|
289
329
|
.summary("show a document's paragraphs and the sha256 to edit them at")
|
|
@@ -328,25 +368,30 @@ const addFileEditCommandsDefinition = (files, helpers) => {
|
|
|
328
368
|
};
|
|
329
369
|
});
|
|
330
370
|
});
|
|
331
|
-
|
|
332
|
-
.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
371
|
+
if (helpers.creates !== false)
|
|
372
|
+
examples(annotate(documents.command("create"), { effects: REMOTE_WRITE, offline: false })
|
|
373
|
+
.summary("create a new Word document from paragraphs and tables")
|
|
374
|
+
.description(`create a new .docx on ${place} with these paragraphs, each in a style: ${NEW_PARAGRAPH_STYLES.join(", ")} ` +
|
|
375
|
+
"(Normal without one; ListBullet is a bullet list), and tables. A paragraph is bold or italic as a whole, " +
|
|
376
|
+
"or made of runs that each are; a table is rows of cell texts, its first row bold with header: true. A " +
|
|
377
|
+
"file already there is refused: change it with documents update")
|
|
378
|
+
.argument("<path>", `the new .docx file on ${place}`)
|
|
379
|
+
.option("--payload <json>", "the body as JSON, in order: [{text, style?, bold?, italic?}, {runs: [{text, bold?, italic?}], style?}, " +
|
|
380
|
+
"{table: [[cell, …], …], header?}]"), [
|
|
381
|
+
`${prefix} ${group} documents create /report.docx --payload '[{"text": "Report", "style": "Title"}, {"text": "Revenue grew 12%."}]'`,
|
|
382
|
+
`${prefix} ${group} documents create /report.docx --payload '[{"runs": [{"text": "Revenue "}, {"text": "grew 12%", "bold": true}]}, {"table": [["Item", "Cost"], ["Rent", "950"]], "header": true}]'`,
|
|
383
|
+
]).action(async function (input, args) {
|
|
384
|
+
if (args.payload === undefined)
|
|
385
|
+
throw new CliError("validation_error", `give the paragraphs with --payload: ${NEW_PARAGRAPHS_SHAPE}`, {
|
|
386
|
+
param: "--payload",
|
|
387
|
+
});
|
|
388
|
+
const paragraphs = jsonOf(args.payload, "--payload", NEW_PARAGRAPHS, NEW_PARAGRAPHS_SHAPE);
|
|
389
|
+
const tables = paragraphs.filter((block) => "table" in block).length;
|
|
390
|
+
await createNew(this, "documents", input, ".docx", {
|
|
391
|
+
bytes: createDocx({ paragraphs }),
|
|
392
|
+
answer: { paragraphs: paragraphs.length - tables, ...(tables ? { tables } : {}) },
|
|
343
393
|
});
|
|
344
|
-
const paragraphs = jsonOf(args.payload, "--payload", NEW_PARAGRAPHS, NEW_PARAGRAPHS_SHAPE);
|
|
345
|
-
await createNew(this, "documents", input, ".docx", {
|
|
346
|
-
bytes: createDocx({ paragraphs }),
|
|
347
|
-
answer: { paragraphs: paragraphs.length },
|
|
348
394
|
});
|
|
349
|
-
});
|
|
350
395
|
examples(annotate(files.command("history"), { effects: REMOTE_READ, offline: false })
|
|
351
396
|
.summary("list the earlier versions of a file kept on this computer")
|
|
352
397
|
.description("list what the writes and syncs of this profile replaced in a file, newest last. Each entry's version is the " +
|
|
@@ -28,6 +28,11 @@ export interface FileUpdateCommands {
|
|
|
28
28
|
write(extra: readonly string[], act: (port: FileUpdatePort) => Promise<object>, command: Command): Promise<object>;
|
|
29
29
|
/** The key an overwrite also asks; `files.delete` when absent. */
|
|
30
30
|
deleteKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* False where the provider names a file by an id it gives, so a path the user types can't name a new file:
|
|
33
|
+
* `sheets create` and `documents create` are left out.
|
|
34
|
+
*/
|
|
35
|
+
creates?: boolean;
|
|
31
36
|
}
|
|
32
37
|
/** A sha256 the user typed, in lower case; `flag` names it in the refusal. */
|
|
33
38
|
export declare const sha256Of: (input: string | undefined, flag?: string) => string | undefined;
|
|
@@ -20,6 +20,7 @@ export { addDocumentHistoryCommands, DOCUMENT_HISTORY_SETTINGS, type DocumentHis
|
|
|
20
20
|
export { addDocumentKnowledgeCommands, type DocumentKnowledgeCommands, type DocumentKnowledgePort, } from "./knowledge.js";
|
|
21
21
|
export { addDocumentMirrorCommands, type DocumentMirrorCommands, type DocumentMirrorConnection } from "./mirrors.js";
|
|
22
22
|
export { documentQueries, FACT_QUERY, factItem, folderRow, IDENTITY_ROLES, identityRow, linkRow, MEMORY_QUERY, MEMORY_SEARCH_QUERY, memoryItem, memorySearch, mirrorRow, tagRow, } from "./queries.js";
|
|
23
|
+
export { rekeySyncedDocument, type SyncedDocumentRekey } from "./rekey.js";
|
|
23
24
|
export { addDocumentSearchCommand, type DocumentSearchCommands, type DocumentSearchOptions } from "./search.js";
|
|
24
25
|
export { addDocumentSyncCommands, type DocumentSyncArgs, type DocumentSyncCommands } from "./sync.js";
|
|
25
26
|
export { ageOf, type CopyAge, type DocumentTexts, type DocumentWords, staleCopy } from "./words.js";
|
|
@@ -43,6 +44,6 @@ export interface DocumentCommands<S> {
|
|
|
43
44
|
* `search`, `catalog`, the knowledge groups and, when given, `mirrors`, in that order. Answers the `documents` group, for the CLI's live subcommands.
|
|
44
45
|
*/
|
|
45
46
|
export declare const addDocumentCommands: <S>(program: Command, options: DocumentCommands<S>) => Command;
|
|
46
|
-
export { claimDocumentAccount, type DocumentLibraryOptions, type DocumentLibraryTools, type DocumentSourceRun, type DocumentSyncOutcome, type DocumentSyncStep, type DocumentWarning, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
47
|
+
export { claimDocumentAccount, DOCUMENT_SCAN_SETTINGS, type DocumentLibraryOptions, type DocumentLibraryTools, type DocumentSourceRun, type DocumentSyncOutcome, type DocumentSyncStep, type DocumentWarning, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
47
48
|
export { type DocumentCall, type DocumentFileMap, type DocumentManifest, parseDocumentManifest, } from "./manifest/manifest.js";
|
|
48
49
|
export { type DocumentManifestSourceOptions, type DocumentManifestTools, type DocumentSlots, documentSourceFromManifest, type ManifestDocumentSource, } from "./manifest/source.js";
|
|
@@ -18,6 +18,7 @@ export { addDocumentHistoryCommands, DOCUMENT_HISTORY_SETTINGS, keepVersionsForD
|
|
|
18
18
|
export { addDocumentKnowledgeCommands, } from "./knowledge.js";
|
|
19
19
|
export { addDocumentMirrorCommands } from "./mirrors.js";
|
|
20
20
|
export { documentQueries, FACT_QUERY, factItem, folderRow, IDENTITY_ROLES, identityRow, linkRow, MEMORY_QUERY, MEMORY_SEARCH_QUERY, memoryItem, memorySearch, mirrorRow, tagRow, } from "./queries.js";
|
|
21
|
+
export { rekeySyncedDocument } from "./rekey.js";
|
|
21
22
|
export { addDocumentSearchCommand } from "./search.js";
|
|
22
23
|
export { addDocumentSyncCommands } from "./sync.js";
|
|
23
24
|
export { ageOf, staleCopy } from "./words.js";
|
|
@@ -39,6 +40,6 @@ export const addDocumentCommands = (program, options) => {
|
|
|
39
40
|
addDocumentMirrorCommands(program, { ...shared, ...options.mirrors });
|
|
40
41
|
return documents;
|
|
41
42
|
};
|
|
42
|
-
export { claimDocumentAccount, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
43
|
+
export { claimDocumentAccount, DOCUMENT_SCAN_SETTINGS, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
43
44
|
export { parseDocumentManifest, } from "./manifest/manifest.js";
|
|
44
45
|
export { documentSourceFromManifest, } from "./manifest/source.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ErrorCode } from "@wirecat/cli-base";
|
|
2
2
|
import type { NextStep } from "@wirecat/cli-base/standards";
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
+
import * as v from "valibot";
|
|
4
5
|
import type { Deadline, RunBudget } from "../../background/budget.js";
|
|
5
6
|
import { type documentIngestion, type FeedlessDocumentSource, type SourceContent, type SourceFile, type SourceStatePort } from "../../documents.js";
|
|
6
7
|
import type { ProviderEntry } from "../../domain/providers.js";
|
|
@@ -13,6 +14,17 @@ import { ProfileTokenStore } from "../profile-token.js";
|
|
|
13
14
|
import type { DocumentKnowledgePort } from "./knowledge.js";
|
|
14
15
|
import { type DocumentSyncAnswer } from "./sync.js";
|
|
15
16
|
import { type DocumentWords } from "./words.js";
|
|
17
|
+
/** `read_scans`: a documents CLI adds it to `settingsFor`; left out, scans are read on this computer. */
|
|
18
|
+
export declare const DOCUMENT_SCAN_SETTINGS: {
|
|
19
|
+
profile: {
|
|
20
|
+
read_scans: v.OptionalSchema<v.PicklistSchema<readonly ["local", "anthropic", "openai", "off"], `has to be one of ${string}`>, undefined>;
|
|
21
|
+
};
|
|
22
|
+
settings: {
|
|
23
|
+
key: string;
|
|
24
|
+
default: string;
|
|
25
|
+
description: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
16
28
|
type Resolve = Parameters<typeof baseContext>[1];
|
|
17
29
|
type Ingestion<M extends SourceFile> = ReturnType<typeof documentIngestion<M>>;
|
|
18
30
|
/** Something a source met on its way and went on past: one per file, gathered into the answer's issues. */
|
|
@@ -4,9 +4,10 @@ import { join } from "node:path";
|
|
|
4
4
|
import { CliError, isCliError, resolvePaths, writeSecurely } from "@wirecat/cli-base";
|
|
5
5
|
import { annotate, metaOf } from "@wirecat/cli-base/commands";
|
|
6
6
|
import { Command } from "commander";
|
|
7
|
+
import * as v from "valibot";
|
|
7
8
|
import { resolveAISettings } from "../../analysis/settings.js";
|
|
8
9
|
import { progressOf } from "../../background/checkpoints.js";
|
|
9
|
-
import { catalogFiles, documentKnowledge, syncDocuments, } from "../../documents.js";
|
|
10
|
+
import { catalogFiles, documentKnowledge, SCAN_READERS, scanReader, scanRetry, scanSkipReason, syncDocuments, } from "../../documents.js";
|
|
10
11
|
import { acquireLock } from "../../files/lock.js";
|
|
11
12
|
import { modelGateway } from "../../models/index.js";
|
|
12
13
|
import { modelTarget } from "../../models/settings.js";
|
|
@@ -19,6 +20,7 @@ import { writesOwnerFiles } from "../effects.js";
|
|
|
19
20
|
import { renderAnswer } from "../envelope.js";
|
|
20
21
|
import { accountFileFor, profilesHere, rememberAccount } from "../messenger/accounts.js";
|
|
21
22
|
import { ProfileTokenStore } from "../profile-token.js";
|
|
23
|
+
import { fromFile } from "../settings.js";
|
|
22
24
|
import { DOCUMENT_UNTRUSTED, marksUntrusted } from "../untrusted-marks.js";
|
|
23
25
|
import { addDocumentCatalogCommands } from "./catalog.js";
|
|
24
26
|
import { addLocalDocumentCommands } from "./documents.js";
|
|
@@ -29,6 +31,21 @@ import { factItem, memoryItem } from "./queries.js";
|
|
|
29
31
|
import { addDocumentSearchCommand } from "./search.js";
|
|
30
32
|
import { addDocumentSyncCommands, DOCUMENT_SYNC_LIMIT, documentSyncPart, } from "./sync.js";
|
|
31
33
|
import { wordsOf } from "./words.js";
|
|
34
|
+
/** `read_scans`: a documents CLI adds it to `settingsFor`; left out, scans are read on this computer. */
|
|
35
|
+
export const DOCUMENT_SCAN_SETTINGS = {
|
|
36
|
+
profile: {
|
|
37
|
+
read_scans: v.optional(v.picklist(SCAN_READERS, `has to be one of ${SCAN_READERS.join(", ")}`)),
|
|
38
|
+
},
|
|
39
|
+
settings: [
|
|
40
|
+
{
|
|
41
|
+
key: "read_scans",
|
|
42
|
+
default: "local",
|
|
43
|
+
description: "who reads the text of scans and pictures: local (the tesseract program), anthropic or openai " +
|
|
44
|
+
"(the AI model `ai set` chose, with pictures allowed), or off",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
const readScans = (settings) => fromFile(settings, "read_scans", "local").value;
|
|
32
49
|
const readJson = (path) => {
|
|
33
50
|
try {
|
|
34
51
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -341,6 +358,16 @@ const libraryOf = (options, withSync) => {
|
|
|
341
358
|
throw new CliError("configuration_error", `the documents are signed in as ${options.service} account ${live}, not ${expected}, the account the ` +
|
|
342
359
|
`rest of this sync read; sign in again with one account (\`${app.command} ${name} session start\`)`, { reason: "documents.other-account" });
|
|
343
360
|
claimDocumentAccount(app, env(), name, live, tokens());
|
|
361
|
+
const { keyring, settings } = context();
|
|
362
|
+
const signal = environmentOf(command()).signal;
|
|
363
|
+
const scans = await scanReader(readScans(settings), {
|
|
364
|
+
app,
|
|
365
|
+
env: env(),
|
|
366
|
+
command: app.command,
|
|
367
|
+
...(keyring ? { keyring } : {}),
|
|
368
|
+
...(signal ? { signal } : {}),
|
|
369
|
+
});
|
|
370
|
+
const skipReason = options.skipReason ?? (() => undefined);
|
|
344
371
|
return files().locked((assertHeld) => withStore(true, async (store) => {
|
|
345
372
|
const result = await syncDocuments({
|
|
346
373
|
source,
|
|
@@ -359,8 +386,11 @@ const libraryOf = (options, withSync) => {
|
|
|
359
386
|
maxEntries: options.maxEntries,
|
|
360
387
|
isFolder: options.isFolder,
|
|
361
388
|
...(options.isDocument ? { isDocument: options.isDocument } : {}),
|
|
362
|
-
skipReason:
|
|
363
|
-
|
|
389
|
+
skipReason: (file) => scanSkipReason(scans, file, skipReason(file)),
|
|
390
|
+
// A file an older version kept by name for its type is read once a newer one reads that type; the
|
|
391
|
+
// planner asks only when `skipReason` no longer gives a reason. The words are the CLIs' own.
|
|
392
|
+
retryable: (skip) => skip.reason.startsWith("unsupported type: ") || scanRetry(scans, skip.reason),
|
|
393
|
+
...(scans ? { scans } : {}),
|
|
364
394
|
errorOf,
|
|
365
395
|
assertHeld,
|
|
366
396
|
storeVersion: app.version,
|
|
@@ -61,6 +61,16 @@ export interface DocumentManifest {
|
|
|
61
61
|
overlapMs?: number;
|
|
62
62
|
map?: DocumentFileMap;
|
|
63
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* The documents deleted since a time, for a provider whose `changes` misses them (Linear's trash leaves `updatedAt`
|
|
66
|
+
* as it was): the id of each at `id`. Read in every round of changes from the same time: needs `"{since}"`.
|
|
67
|
+
*/
|
|
68
|
+
deletions?: DocumentCall & {
|
|
69
|
+
since: "iso" | "ms" | "seconds";
|
|
70
|
+
time: string;
|
|
71
|
+
id: string;
|
|
72
|
+
overlapMs?: number;
|
|
73
|
+
};
|
|
64
74
|
/** A document's text as Markdown, at `markdown` in the answer: needs `"{id}"`. */
|
|
65
75
|
content?: DocumentCall & {
|
|
66
76
|
markdown: string;
|
|
@@ -39,11 +39,18 @@ const schema = v.strictObject({
|
|
|
39
39
|
overlapMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))),
|
|
40
40
|
map: v.optional(fileMap),
|
|
41
41
|
})),
|
|
42
|
+
deletions: v.optional(v.strictObject({
|
|
43
|
+
...callEntries,
|
|
44
|
+
since: v.picklist(["iso", "ms", "seconds"]),
|
|
45
|
+
time: dotPath,
|
|
46
|
+
id: dotPath,
|
|
47
|
+
overlapMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))),
|
|
48
|
+
})),
|
|
42
49
|
content: v.optional(v.strictObject({ ...callEntries, markdown: dotPath })),
|
|
43
50
|
reread: v.optional(v.strictObject({ missing: dotPath })),
|
|
44
51
|
reads: v.optional(v.record(v.pipe(v.string(), v.regex(/^[a-z][A-Za-z0-9]*$/, "a camelCase name")), v.strictObject(callEntries))),
|
|
45
52
|
});
|
|
46
|
-
const BUILT_IN = ["identity", "get", "children", "changes", "content"];
|
|
53
|
+
const BUILT_IN = ["identity", "get", "children", "changes", "deletions", "content"];
|
|
47
54
|
const invalid = (where, message) => new CliError("configuration_error", `source manifest: ${where}: ${message}`, { reason: "manifest.invalid" });
|
|
48
55
|
const nearest = (wanted, known) => known
|
|
49
56
|
.map((one) => ({ one, edits: editDistance(wanted, one, 2) }))
|
|
@@ -82,6 +89,7 @@ export const parseDocumentManifest = (input, api) => {
|
|
|
82
89
|
check("get", manifest.get, "{id}");
|
|
83
90
|
check("children", manifest.children, "{id}");
|
|
84
91
|
check("changes", manifest.changes, "{since}");
|
|
92
|
+
check("deletions", manifest.deletions, "{since}");
|
|
85
93
|
check("content", manifest.content, "{id}");
|
|
86
94
|
for (const [name, call] of Object.entries(manifest.reads ?? {})) {
|
|
87
95
|
// A hook sends a named call and a manifest call by the same name; one would hide the other.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DocumentSource, FeedlessDocumentSource, SourceFile } from "../../../documents.js";
|
|
2
2
|
import type { ServiceApiCall } from "../../service-api-call.js";
|
|
3
3
|
import { type ServiceApiManifest } from "../../service-api-manifest.js";
|
|
4
|
+
import type { DocumentWarning } from "../library.js";
|
|
4
5
|
import { type DocumentManifest } from "./manifest.js";
|
|
5
6
|
/** What a slot in a call is filled with; one left without a value is left out of the request. */
|
|
6
7
|
export interface DocumentSlots {
|
|
@@ -13,7 +14,7 @@ export type ManifestDocumentSource<M extends SourceFile = SourceFile> = Feedless
|
|
|
13
14
|
/** What a hook builds on: the manifest's own calls, and the source the manifest alone describes. */
|
|
14
15
|
export interface DocumentManifestTools<M extends SourceFile = SourceFile> {
|
|
15
16
|
manifest: DocumentManifest;
|
|
16
|
-
/** Sends one named call of `reads`, or `identity`, `get`, `children`, `changes`, `content`. */
|
|
17
|
+
/** Sends one named call of `reads`, or `identity`, `get`, `children`, `changes`, `deletions`, `content`. */
|
|
17
18
|
read(name: string, slots?: DocumentSlots, body?: unknown): Promise<unknown>;
|
|
18
19
|
/** One row of an answer as a file, by `get.map` (or the named call's own map). */
|
|
19
20
|
file(row: unknown, from?: "get" | "children" | "changes"): M;
|
|
@@ -23,6 +24,8 @@ export interface DocumentManifestSourceOptions<M extends SourceFile = SourceFile
|
|
|
23
24
|
api: ServiceApiManifest;
|
|
24
25
|
call: ServiceApiCall;
|
|
25
26
|
now?: () => number;
|
|
27
|
+
/** The run's `warn`: a refused `deletions` feed is said there, and the round goes on without it. */
|
|
28
|
+
warn?: (warning: DocumentWarning) => void;
|
|
26
29
|
/** The methods the manifest cannot describe, or that the provider does otherwise; each wins over the manifest's. */
|
|
27
30
|
hooks?: (tools: DocumentManifestTools<M>) => Partial<ManifestDocumentSource<M>>;
|
|
28
31
|
}
|