strom-research 1.35.0 → 1.36.0-beta.2
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.cs.md +45 -0
- package/CHANGELOG.de.md +53 -0
- package/CHANGELOG.md +48 -0
- package/CHANGELOG.pl.md +47 -0
- package/assets/lang/cs.json +47 -5
- package/assets/lang/de.json +47 -5
- package/assets/lang/pl.json +46 -4
- package/assets/plugins/gates/claude-usage/gate.ts +94 -16
- package/dist/cli/help.js +2 -2
- package/dist/cli/menu-links.js +58 -11
- package/dist/cli/menu-settings.js +19 -0
- package/dist/cli/menu-waiting.js +50 -1
- package/dist/cli/ui.js +41 -5
- package/dist/commands/analysis.js +20 -1
- package/dist/commands/guide.js +4 -1
- package/dist/commands/index.js +1 -0
- package/dist/commands/intake.js +32 -9
- package/dist/commands/links.js +10 -6
- package/dist/commands/media.js +166 -32
- package/dist/commands/setup.js +6 -0
- package/dist/commands/sourceretract.js +139 -0
- package/dist/commands/sources.js +42 -13
- package/dist/commands/sync.js +5 -3
- package/dist/commands/tasks.js +37 -9
- package/dist/commands/verify.js +7 -4
- package/dist/core/actions.js +11 -9
- package/dist/core/busy.js +9 -0
- package/dist/core/changelog.js +17 -0
- package/dist/core/config.js +7 -0
- package/dist/core/evidence.js +16 -0
- package/dist/core/import.js +9 -3
- package/dist/core/inboxwait.js +133 -15
- package/dist/core/inboxwatch.js +5 -4
- package/dist/core/links.js +13 -2
- package/dist/core/live.js +368 -33
- package/dist/core/material.js +12 -5
- package/dist/core/materialdelete.js +97 -23
- package/dist/core/media.js +4 -0
- package/dist/core/origin.js +16 -6
- package/dist/core/phrases.js +6 -0
- package/dist/core/queue.js +12 -4
- package/dist/core/report.js +1 -1
- package/dist/core/samescan.js +359 -0
- package/dist/core/sort.js +1 -1
- package/dist/core/sourcefields.js +16 -0
- package/dist/core/sourceretract.js +531 -0
- package/dist/core/sync.js +152 -7
- package/dist/core/taskaudit.js +104 -6
- package/dist/core/taskkind.js +58 -0
- package/dist/core/tree.js +1 -1
- package/dist/core/verify.js +12 -6
- package/dist/core/verifyfacts.js +7 -0
- package/dist/core/waiting.js +22 -3
- package/dist/core/waitkept.js +2 -0
- package/dist/gedcom/export.js +32 -9
- package/dist/gedcom/validate.js +8 -3
- package/dist/image/index.js +6 -3
- package/dist/image/jpeg-decode.js +80 -21
- package/package.json +4 -1
package/dist/commands/media.js
CHANGED
|
@@ -31,7 +31,7 @@ import { makeThumb, THUMB_SIZES } from "../core/thumbs.js";
|
|
|
31
31
|
import { batchFull, batchPath, batchRoom, noteBatch, openBatch } from "../core/batches.js";
|
|
32
32
|
import { readEntry, readZip } from "../core/zip.js";
|
|
33
33
|
import { fileBy, handFiles, taskForFile, taskPeople } from "../core/taskfiles.js";
|
|
34
|
-
import { askedNow, bookFolders, bookTimes, folderFiles, handedImages, inboxState, inboxWaitOf, inboxWaits, numberBookFiles, numberFiles, numbersForTask, registeredImages, SETTLE_MS, unsettled, webWaitBook } from "../core/inboxwait.js";
|
|
34
|
+
import { askedNow, bookFolders, bookTimes, folderFiles, handedImages, inboxState, inboxWaitOf, inboxWaits, numberBookFiles, numberFiles, numbersForTask, registeredImages, SETTLE_MS, unsettled, webWaitBook, DOWNLOADING, folderBusy, STALLED_MS, asideFiles } from "../core/inboxwait.js";
|
|
35
35
|
import { formatOf } from "../image/index.js";
|
|
36
36
|
import { pdfScans } from "../image/pdf.js";
|
|
37
37
|
import { readableFile } from "../core/readable.js";
|
|
@@ -41,6 +41,9 @@ import { allows } from "../core/terms.js";
|
|
|
41
41
|
import { phrase } from "../core/phrases.js";
|
|
42
42
|
import { browserKept, withoutBrowserReason } from "../core/browserhelp.js";
|
|
43
43
|
import { goesAhead } from "../core/queue.js";
|
|
44
|
+
import { localDayOf } from "../core/readers.js";
|
|
45
|
+
import { scanLikeness } from "../core/samescan.js";
|
|
46
|
+
import { moveToTrash } from "../core/trash.js";
|
|
44
47
|
const IMAGE_EXT = IMAGE_FILE_EXT;
|
|
45
48
|
/**
|
|
46
49
|
* Register images of a record set: stored once by content, each with its number
|
|
@@ -211,9 +214,10 @@ function takeWaitingNow(tree, shared, o) {
|
|
|
211
214
|
if (!files.length)
|
|
212
215
|
continue;
|
|
213
216
|
const base = { folder: w.folder, recordset: w.recordset, tasks: ws.map((x) => x.task) };
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
+
// the whole batch settled: no file still written, no download of the browser still running in it (B0408)
|
|
218
|
+
const busy = folderBusy(dir, files, o.now);
|
|
219
|
+
if (busy) {
|
|
220
|
+
out.push({ ...base, added: [], woken: [], missing: [], settling: busy });
|
|
217
221
|
continue;
|
|
218
222
|
}
|
|
219
223
|
// what the tasks of the folder asked for, together
|
|
@@ -224,7 +228,7 @@ function takeWaitingNow(tree, shared, o) {
|
|
|
224
228
|
out.push({ ...base, added: [], woken: [], missing: (asked ?? []).filter((n) => !before.has(n)), problem: numbered.problem });
|
|
225
229
|
continue;
|
|
226
230
|
}
|
|
227
|
-
const r = takeFiles(tree, shared, w, files, numbered.numbers, persons(ws, files, numbered.numbers) ? { ahead: at } : {});
|
|
231
|
+
const r = takeFiles(tree, shared, w, files, numbered.numbers, { otherScans: true, ...(persons(ws, files, numbered.numbers) ? { ahead: at } : {}) });
|
|
228
232
|
const after = registeredImages(tree, w.recordset);
|
|
229
233
|
const pending = againPending(tree);
|
|
230
234
|
out.push({
|
|
@@ -245,9 +249,9 @@ function takeWaitingNow(tree, shared, o) {
|
|
|
245
249
|
if (!files.length)
|
|
246
250
|
continue;
|
|
247
251
|
const base = { folder: b.folder, recordset: b.recordset, tasks: b.tasks, book: true };
|
|
248
|
-
const busy =
|
|
249
|
-
if (busy
|
|
250
|
-
out.push({ ...base, added: [], woken: [], missing: [], settling: busy
|
|
252
|
+
const busy = folderBusy(path.join(shared, "inbox", b.folder), files, o.now);
|
|
253
|
+
if (busy) {
|
|
254
|
+
out.push({ ...base, added: [], woken: [], missing: [], settling: busy });
|
|
251
255
|
continue;
|
|
252
256
|
}
|
|
253
257
|
const numbered = numberBookFiles(files, b.recordset, b.times);
|
|
@@ -256,7 +260,7 @@ function takeWaitingNow(tree, shared, o) {
|
|
|
256
260
|
continue;
|
|
257
261
|
}
|
|
258
262
|
// the files with a number taken; one without a number stays lying, never holding back the rest
|
|
259
|
-
const r = takeFiles(tree, shared, { task: "", recordset: b.recordset, folder: b.folder, by: "images" }, numbered.files, numbered.numbers, { ahead: at });
|
|
263
|
+
const r = takeFiles(tree, shared, { task: "", recordset: b.recordset, folder: b.folder, by: "images" }, numbered.files, numbered.numbers, { ahead: at, otherScans: true });
|
|
260
264
|
out.push({
|
|
261
265
|
...base,
|
|
262
266
|
added: r.added.map((m) => m.image).filter((n) => n !== undefined),
|
|
@@ -361,8 +365,6 @@ function fromDownloads(tree, shared, downloads, waits) {
|
|
|
361
365
|
}
|
|
362
366
|
return moved;
|
|
363
367
|
}
|
|
364
|
-
/** A browser's download not finished yet: Chrome's .crdownload, Firefox's .part, Safari's .download, a .tmp. */
|
|
365
|
-
const DOWNLOADING = /\.(crdownload|part|download|tmp)$/iu;
|
|
366
368
|
/**
|
|
367
369
|
* strom's own files of the images waiting tasks wait for (strom media save's names, this research's mark first, or
|
|
368
370
|
* the name a record of this research gives) that the browser is still writing: a download not finished (.crdownload,
|
|
@@ -419,8 +421,6 @@ export function downloadsBeingWritten(tree, downloads, now = Date.now()) {
|
|
|
419
421
|
}
|
|
420
422
|
return out;
|
|
421
423
|
}
|
|
422
|
-
/** A download not written to for this long has stopped (a browser's failed or paused download): not waited for. */
|
|
423
|
-
const STALLED_MS = 60_000;
|
|
424
424
|
/**
|
|
425
425
|
* Waits a moment (at most STROM_DOWNLOAD_WAIT_MS, else a few seconds: what a browser takes to finish a scan and the
|
|
426
426
|
* file to settle) while strom's own files of waiting tasks are still being written in the downloads folder — only for
|
|
@@ -441,33 +441,74 @@ function waitForDownloads(tree, downloads, env) {
|
|
|
441
441
|
* the queue, but `except`), the files moved into the store, the folder gone once nobody waits on it. What takes the
|
|
442
442
|
* folder (takeWaiting) and what the Strom app sends for the task (takeForTask) both register so.
|
|
443
443
|
*/
|
|
444
|
-
function takeFiles(tree, shared, w,
|
|
444
|
+
function takeFiles(tree, shared, w, all, allNumbers, o = {}) {
|
|
445
445
|
const book = tree.get(w.recordset);
|
|
446
|
-
|
|
446
|
+
// another scan under a number taken already (B0374: page 203 saved as 3.jpg): never a sharper copy of that image,
|
|
447
|
+
// unsaid — set aside beside it, the user asked which one is the image (strom media aside); a sharper copy is taken
|
|
448
|
+
// only when surely of the same scan (core/samescan.ts)
|
|
449
|
+
const other = new Map();
|
|
450
|
+
const unsure = new Set();
|
|
451
|
+
if (o.otherScans && !tree.dryRun) {
|
|
452
|
+
const media = tree.list("media").filter((m) => !m.retracted);
|
|
453
|
+
const wholes = media.filter((m) => isWhole(m.part));
|
|
454
|
+
all.forEach((f, i) => {
|
|
455
|
+
const kept = findImage(wholes, w.recordset, allNumbers[i]);
|
|
456
|
+
if (!kept)
|
|
457
|
+
return;
|
|
458
|
+
const sha = fileSha256(f);
|
|
459
|
+
if (media.some((m) => m.sha === sha))
|
|
460
|
+
return; // the same file: registerImages says what it is
|
|
461
|
+
const was = path.join(shared, kept.file);
|
|
462
|
+
// taken as a sharper copy only when surely the same scan; unsure (nothing written to compare, a format strom does
|
|
463
|
+
// not read itself) is set aside and asked as well
|
|
464
|
+
if (!fs.existsSync(was))
|
|
465
|
+
return;
|
|
466
|
+
const alike = scanLikeness(f, was);
|
|
467
|
+
if (alike !== "same")
|
|
468
|
+
other.set(f, kept.id);
|
|
469
|
+
if (alike === undefined)
|
|
470
|
+
unsure.add(f);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
const files = all.filter((f) => !other.has(f));
|
|
474
|
+
const numbers = files.map((f) => allNumbers[all.indexOf(f)]);
|
|
475
|
+
const from = o.from ? files.map((f) => o.from[all.indexOf(f)]) : undefined;
|
|
476
|
+
const items = files.map((file, i) => ({ file, image: numbers[i], url: book?.url, from: from?.[i] ?? path.basename(file) }));
|
|
447
477
|
const r = { ...registerImages(tree, shared, items, w.recordset, { wake: false }), aside: [] };
|
|
448
478
|
// an image saved once more (strom media save --again) came: its new copy, or the same scan again (nothing sharper
|
|
449
479
|
// to have) — what its task waited for either way
|
|
450
480
|
const settled = settleAgain(tree, w.recordset, numbers);
|
|
451
481
|
r.woken.push(...wakeWaiting(tree, w.recordset, r.added.length || (settled ? r.again.length : 0), { ...(o.except ? { except: o.except } : {}), ...(o.ahead ? { ahead: o.ahead } : {}) }));
|
|
452
482
|
if (!tree.dryRun) {
|
|
453
|
-
// the same file as another image (another number, another book: B0408, "33.jpg" the same scan as image 2)
|
|
454
|
-
// deleted unsaid — set aside beside it (no image's name: never
|
|
483
|
+
// the same file as another image (another number, another book: B0408, "33.jpg" the same scan as image 2), another
|
|
484
|
+
// scan than the image of its number (B0374): never deleted unsaid — set aside beside it (no image's name: never
|
|
485
|
+
// taken again), what it is said (live.log, the output, strom media aside)
|
|
455
486
|
const clash = new Map(r.clashed.map((c) => [c.file, c.same]));
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
continue;
|
|
461
|
-
}
|
|
462
|
-
const to = `${f}.same-as-${same}`;
|
|
487
|
+
const setAside = (f, same, kind) => {
|
|
488
|
+
const to = `${f}.${kind === "same" ? "same-as" : "other-than"}-${same}`;
|
|
489
|
+
const image = allNumbers[all.indexOf(f)];
|
|
490
|
+
const said = kind === "other" ? { kind, ...(unsure.has(f) ? { unsure: true } : {}) } : {};
|
|
463
491
|
try {
|
|
464
492
|
fs.renameSync(f, to);
|
|
465
|
-
r.aside.push({ file: path.basename(to), image
|
|
493
|
+
r.aside.push({ file: path.basename(to), image, same, ...said });
|
|
466
494
|
}
|
|
467
495
|
catch {
|
|
468
496
|
// left lying as it is: said all the same
|
|
469
|
-
r.aside.push({ file: path.basename(f), image
|
|
497
|
+
r.aside.push({ file: path.basename(f), image, same, ...said });
|
|
470
498
|
}
|
|
499
|
+
};
|
|
500
|
+
for (const f of all) {
|
|
501
|
+
const otherThan = other.get(f);
|
|
502
|
+
if (otherThan !== undefined) {
|
|
503
|
+
setAside(f, otherThan, "other");
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
const same = clash.get(f);
|
|
507
|
+
if (same === undefined) {
|
|
508
|
+
fs.rmSync(f, { force: true }); // now in the store
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
setAside(f, same, "same");
|
|
471
512
|
}
|
|
472
513
|
// the folder goes once nobody waits on it; one still waiting keeps it for the rest
|
|
473
514
|
const dir = path.join(shared, "inbox", w.folder);
|
|
@@ -479,6 +520,8 @@ function takeFiles(tree, shared, w, files, numbers, o = {}) {
|
|
|
479
520
|
}
|
|
480
521
|
/** What a file set aside says (live.log, strom media add --inbox): which image it was taken for, which one it is. */
|
|
481
522
|
export function asideLine(t, a, tree) {
|
|
523
|
+
if (a.kind === "other")
|
|
524
|
+
return `the file for image ${a.image} of ${t.recordset} is ${a.unsure ? "not surely the same scan as" : "another scan than"} ${a.same}, image ${a.image} registered already — not taken as a sharper copy of it, set aside as ${a.file}: which one is image ${a.image} is the user's to say (strom media aside)`;
|
|
482
525
|
const m = tree?.get(a.same);
|
|
483
526
|
const as = m ? `${m.recordset ?? "no record set"}${m.image !== undefined ? `:${m.image}` : ""}` : a.same;
|
|
484
527
|
return `the file for image ${a.image} of ${t.recordset} is the same scan as ${a.same} (${as}), registered already — not taken, set aside as ${a.file}: one of the two numbers is wrong (the image of ${a.same} renumbered, or the file named by its own number)`;
|
|
@@ -831,7 +874,7 @@ export function takenLines(taken) {
|
|
|
831
874
|
if (t.problem)
|
|
832
875
|
return `${t.folder}/: nothing taken — ${t.problem} (${who})`;
|
|
833
876
|
return [[
|
|
834
|
-
`${t.folder}/: ${t.added.length ? `images ${runs(t.added)} of ${t.recordset} registered${t.byOrder ? " (numbered by their order: the names gave none of the numbers asked for)" : ""}` : "nothing new (the same scans are registered)"}`,
|
|
877
|
+
`${t.folder}/: ${t.added.length ? `images ${runs(t.added)} of ${t.recordset} registered${t.byOrder ? " (numbered by their order: the names gave none of the numbers asked for)" : ""}` : t.aside?.length ? `nothing taken: ${counted(t.aside.length, "file")} set aside` : "nothing new (the same scans are registered)"}`,
|
|
835
878
|
t.woken.length ? ` — back in the queue: ${t.woken.join(" ")}` : t.missing.length ? ` — ${who} still waits${t.missing.length ? ` for images ${runs(t.missing)}` : ""}` : "",
|
|
836
879
|
t.book && t.added.length ? ` — the book's own folder: its tasks read them from disk (${who})` : "",
|
|
837
880
|
t.left ? ` — ${counted(t.left, "file")} left lying: no image number in the name (name each by the number its viewer counts, 40.jpg)` : "",
|
|
@@ -1582,7 +1625,7 @@ register({
|
|
|
1582
1625
|
});
|
|
1583
1626
|
}
|
|
1584
1627
|
// what the person put into the shared inbox: the tasks it completes go ahead in the queue, once (core/queue.ts goesAhead)
|
|
1585
|
-
const { added, again, restored, woken, clashes, copies } = registerImages(tree, shared, items, recordset, opts.inbox ? { ahead: new Date().toISOString() } : {});
|
|
1628
|
+
const { added, again, restored, woken, clashes, copies, clashed } = registerImages(tree, shared, items, recordset, opts.inbox ? { ahead: new Date().toISOString() } : {});
|
|
1586
1629
|
// the material is the book's images now: sorted, done with
|
|
1587
1630
|
for (const i of taken) {
|
|
1588
1631
|
const m = tree.list("media").find((x) => x.sha === i.sha && !x.retracted);
|
|
@@ -1591,9 +1634,24 @@ register({
|
|
|
1591
1634
|
summary: `${i.id} an image of ${recordset}${m ? ` (${m.id})` : ""}`,
|
|
1592
1635
|
});
|
|
1593
1636
|
}
|
|
1637
|
+
const setAside = [];
|
|
1594
1638
|
if (opts.inbox && !tree.dryRun) {
|
|
1595
|
-
|
|
1596
|
-
|
|
1639
|
+
// the same file as another image (B0408): never deleted unsaid — set aside beside it, kept
|
|
1640
|
+
const clash = new Map(clashed.map((c) => [c.file, c.same]));
|
|
1641
|
+
for (const f of files) {
|
|
1642
|
+
const same = clash.get(f);
|
|
1643
|
+
if (same === undefined) {
|
|
1644
|
+
fs.rmSync(f, { force: true }); // now in the store
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
try {
|
|
1648
|
+
fs.renameSync(f, `${f}.same-as-${same}`);
|
|
1649
|
+
setAside.push(`${path.basename(f)} set aside as ${path.basename(f)}.same-as-${same} (the same scan as ${same}) — kept`);
|
|
1650
|
+
}
|
|
1651
|
+
catch {
|
|
1652
|
+
setAside.push(`${path.basename(f)} left lying (the same scan as ${same}) — kept`);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1597
1655
|
for (const p of paths)
|
|
1598
1656
|
if (p !== inbox && fs.existsSync(p) && fs.statSync(p).isDirectory() && collectFiles([p]).length === 0)
|
|
1599
1657
|
fs.rmSync(p, { recursive: true, force: true });
|
|
@@ -1601,7 +1659,7 @@ register({
|
|
|
1601
1659
|
const nums = added.map((m) => m.image).filter((n) => n !== undefined);
|
|
1602
1660
|
const text = lines(added.length
|
|
1603
1661
|
? `${counted(added.length, "image")} registered: ${added[0].id}${added.length > 1 ? `–${added.at(-1).id}` : ""}${recordset ? ` of ${recordset}` : ""}${nums.length ? ` (images ${runs(nums)}${byOrder ? ", numbered by their order: the names gave none of the numbers asked for" : ""})` : ""}`
|
|
1604
|
-
: restored.length ? undefined : "no new images", restored.length ? `${counted(restored.length, "image")} put back (their file was not here; the same scan): ${restored.slice(0, 5).join(" ")}${restored.length > 5 ? " …" : ""}` : undefined, again.length ? `${again.length} already registered (same content): ${again.slice(0, 5).join(" ")}${again.length > 5 ? " …" : ""}` : undefined, ...clashes.slice(0, 10).map((c) => `⚠ ${c}`), ...copies.slice(0, 10), copies.length > 10 ? `… and ${copies.length - 10} more images with a sharper copy` : undefined, woken.length ? `back in the queue (they waited for these images): ${woken.join(" ")}` : undefined, ...stillWaiting(tree, recordset), added[0] ? `\nlook at one: strom media view ${recordset && added[0].image !== undefined ? `${recordset}:${added[0].image}` : added[0].id} --grid` : undefined);
|
|
1662
|
+
: restored.length ? undefined : "no new images", restored.length ? `${counted(restored.length, "image")} put back (their file was not here; the same scan): ${restored.slice(0, 5).join(" ")}${restored.length > 5 ? " …" : ""}` : undefined, again.length ? `${again.length} already registered (same content): ${again.slice(0, 5).join(" ")}${again.length > 5 ? " …" : ""}` : undefined, ...clashes.slice(0, 10).map((c) => `⚠ ${c}`), ...setAside.slice(0, 10).map((c) => ` ${c}`), ...copies.slice(0, 10), copies.length > 10 ? `… and ${copies.length - 10} more images with a sharper copy` : undefined, woken.length ? `back in the queue (they waited for these images): ${woken.join(" ")}` : undefined, ...stillWaiting(tree, recordset), added[0] ? `\nlook at one: strom media view ${recordset && added[0].image !== undefined ? `${recordset}:${added[0].image}` : added[0].id} --grid` : undefined);
|
|
1605
1663
|
return { text, data: { added: added.map((m) => ({ id: m.id, image: m.image })), again, woken, clashes, copies } };
|
|
1606
1664
|
},
|
|
1607
1665
|
}, {
|
|
@@ -1783,7 +1841,7 @@ register({
|
|
|
1783
1841
|
const copies = otherCopies(all, m);
|
|
1784
1842
|
const image = copies.length && m.recordset && m.image !== undefined ? findImage(all, m.recordset, m.image) : undefined;
|
|
1785
1843
|
return {
|
|
1786
|
-
text: lines(`${m.id} ${m.part ? `part ${regionText(partShown(sharedDir(ctx), all, m))} of ` : ""}${b ? `image ${m.image ?? "?"} of ${b.id} ${b.title}` : "image"}${pageLabel(tree, m) ? ` · page ${pageLabel(tree, m)}` : ""}`, `${m.width ? `${m.width}×${m.height} px · ` : ""}${Math.round(m.size / 1024)} kB · ${m.mime}${m.from ? ` · from ${m.from}` : ""}${m.url ? ` · ${m.url}` : ""}`, m.retracted ? `RETRACTED ${m.retracted.at
|
|
1844
|
+
text: lines(`${m.id} ${m.part ? `part ${regionText(partShown(sharedDir(ctx), all, m))} of ` : ""}${b ? `image ${m.image ?? "?"} of ${b.id} ${b.title}` : "image"}${pageLabel(tree, m) ? ` · page ${pageLabel(tree, m)}` : ""}`, `${m.width ? `${m.width}×${m.height} px · ` : ""}${Math.round(m.size / 1024)} kB · ${m.mime}${m.from ? ` · from ${m.from}` : ""}${m.url ? ` · ${m.url}` : ""}`, m.retracted ? `RETRACTED ${localDayOf(m.retracted.at)}: ${m.retracted.reason} — no view, part or excerpt uses it` : undefined, parts.length ? `parts of it, sharper (a view of the image uses them by itself): ${parts.map((p) => `${p.id} ${regionText(partShown(sharedDir(ctx), all, p))}${p.width ? ` ${p.width}×${p.height}` : ""}`).join(" · ")}` : undefined, copies.length
|
|
1787
1845
|
? `other copies of the image: ${copies.map((c) => `${c.id}${c.width ? ` ${c.width}×${c.height}` : ""}`).join(" · ")} — the image is the sharpest (${image.id}); a view of any copy uses it`
|
|
1788
1846
|
: undefined, sources.length ? `sources on it: ${sources.map((s) => `${s.id} ${s.title}`).join(" · ")}` : "no source cites it yet", `view: strom media view ${m.id} [--half left|right] [--crop x,y,w,h] [--grid]`),
|
|
1789
1847
|
data: { media: m, parts: parts.map((p) => p.id), copies: copies.map((c) => c.id), sources: sources.map((s) => s.id), page: pageLabel(tree, m) || undefined },
|
|
@@ -1813,6 +1871,82 @@ register({
|
|
|
1813
1871
|
const out = update(tree, m.id, "media", (x) => ({ ...x, retracted: { at: now(), reason: String(opts.reason) } }), { op: "media.retract", summary: `${m.id} retracted: ${truncate(String(opts.reason), 80)}` });
|
|
1814
1872
|
return { text: lines(...tree.written.map((o) => o.summary)), data: { media: out } };
|
|
1815
1873
|
},
|
|
1874
|
+
}, {
|
|
1875
|
+
path: ["media", "aside"],
|
|
1876
|
+
summary: "Files of the inbox set aside, not taken — the same scan as another image, or another scan than the image of their number: list them, or say which one is the image",
|
|
1877
|
+
group: "sources",
|
|
1878
|
+
tree: true,
|
|
1879
|
+
writes: true,
|
|
1880
|
+
description: "Images saved by hand into a book's folder of the inbox that strom did not take: the same file as an image\n" +
|
|
1881
|
+
"registered under another number (one of the two numbers is wrong), or another scan than the image registered\n" +
|
|
1882
|
+
"under its number already (never taken as a sharper copy of it, unasked). Without a file: the list. With one,\n" +
|
|
1883
|
+
"the answer: --discard (the image registered stays; the file into the system's trash), --take (another scan: it\n" +
|
|
1884
|
+
"is the image of its number — the one there withdrawn and kept, one a source cites stays beside it), --image <n>\n" +
|
|
1885
|
+
"(another scan: it is image n, a number not taken yet).",
|
|
1886
|
+
args: [{ name: "file", description: "the file's name as listed (or <folder>/<file>)" }],
|
|
1887
|
+
options: [
|
|
1888
|
+
{ name: "discard", type: "boolean", description: "the image registered stays; the file goes into the system's trash" },
|
|
1889
|
+
{ name: "take", type: "boolean", description: "another scan: it is the image of its number (the one there withdrawn, kept)" },
|
|
1890
|
+
{ name: "image", type: "string", value: "<n>", description: "another scan: it is image n of the book (a number not taken yet)" },
|
|
1891
|
+
],
|
|
1892
|
+
examples: ["strom media aside", "strom media aside 3.jpg.other-than-M0003 --take", "strom media aside 3.jpg.other-than-M0003 --image 203", "strom media aside 3.jpg.other-than-M0003 --discard"],
|
|
1893
|
+
run(ctx, { args, opts }) {
|
|
1894
|
+
const tree = ctx.tree();
|
|
1895
|
+
const shared = sharedDir(ctx);
|
|
1896
|
+
const all = asideFiles(tree, shared);
|
|
1897
|
+
const said = (a) => a.kind === "same"
|
|
1898
|
+
? `${a.folder}/${a.file}: saved as image ${a.image ?? "?"} of ${a.recordset}, the same file as ${a.media} — one of the two numbers is wrong`
|
|
1899
|
+
: `${a.folder}/${a.file}: saved as image ${a.image ?? "?"} of ${a.recordset}, another scan than ${a.media} registered as that image — which one is it?`;
|
|
1900
|
+
const json = (a) => ({ folder: a.folder, file: a.file, name: a.name, recordset: a.recordset, image: a.image, kind: a.kind, media: a.media, at: a.at });
|
|
1901
|
+
const answers = [opts.discard, opts.take, opts.image !== undefined].filter(Boolean).length;
|
|
1902
|
+
if (!args[0]) {
|
|
1903
|
+
if (answers)
|
|
1904
|
+
throw new UsageError("which file? strom media aside <file> …", { hint: "strom media aside (the list)" });
|
|
1905
|
+
return {
|
|
1906
|
+
text: all.length ? lines(`${counted(all.length, "file")} of the inbox set aside, not taken:`, ...all.map((a) => ` ${said(a)}`), "answer: strom media aside <file> --discard | --take | --image <n>") : "no file of the inbox set aside",
|
|
1907
|
+
data: { aside: all.map(json) },
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
const want = String(args[0]).normalize("NFC");
|
|
1911
|
+
const a = all.find((x) => x.file.normalize("NFC") === want || `${x.folder}/${x.file}`.normalize("NFC") === want);
|
|
1912
|
+
if (!a)
|
|
1913
|
+
throw new UsageError(`no file set aside named ${args[0]}`, { hint: "strom media aside (the list)", code: "aside.unknown" });
|
|
1914
|
+
if (answers !== 1)
|
|
1915
|
+
return { text: lines(said(a), "answer: --discard | --take | --image <n>"), data: { aside: json(a) } };
|
|
1916
|
+
if (opts.discard) {
|
|
1917
|
+
if (!tree.dryRun)
|
|
1918
|
+
moveToTrash(a.path, ctx.env, a.file);
|
|
1919
|
+
return { text: `${a.file} into the system's trash — ${a.media} stays${a.image !== undefined ? ` image ${a.image} of ${a.recordset}` : ""}`, data: { aside: json(a), done: "discard" } };
|
|
1920
|
+
}
|
|
1921
|
+
if (a.kind === "same")
|
|
1922
|
+
throw new UsageError(`${a.file} is the same file as ${a.media}, registered already: nothing to take`, { hint: `--discard; or renumber the image of ${a.media} (strom media retract ${a.media} --reason "…", then strom media add …)`, code: "aside.same" });
|
|
1923
|
+
const n = opts.take ? a.image : Number(opts.image);
|
|
1924
|
+
if (n === undefined || !Number.isInteger(n) || n < 1)
|
|
1925
|
+
throw new UsageError(opts.take ? `${a.file}: its name gives no image number` : `--image ${opts.image}: an image number`, { hint: "--image <n>" });
|
|
1926
|
+
const media = tree.list("media").filter((m) => !m.retracted && m.recordset === a.recordset && m.image === n && isWhole(m.part));
|
|
1927
|
+
if (opts.image !== undefined && media.length && media.every((m) => !fs.existsSync(path.join(shared, m.file)) || scanLikeness(a.path, path.join(shared, m.file)) !== "same"))
|
|
1928
|
+
throw new UsageError(`image ${n} of ${a.recordset} is there already (${media.map((m) => m.id).join(", ")}), another scan`, { hint: `--take for image ${a.image ?? "?"}, or another number`, code: "aside.taken" });
|
|
1929
|
+
const replaced = [];
|
|
1930
|
+
const out = tree.withTreeLock(() => {
|
|
1931
|
+
if (opts.take)
|
|
1932
|
+
for (const m of media) {
|
|
1933
|
+
const cited = tree.list("source").some((s) => !s.retracted && (s.media?.includes(m.id) || s.clips?.some((c) => c.media === m.id)));
|
|
1934
|
+
if (cited)
|
|
1935
|
+
continue; // what a source cites stays; the new scan is registered beside it
|
|
1936
|
+
update(tree, m.id, "media", (x) => ({ ...x, retracted: { at: now(), reason: `another scan of image ${n} is the image (${a.file})` } }), { op: "media.retract", summary: `${m.id} retracted: another scan of image ${n} is the image` });
|
|
1937
|
+
replaced.push(m.id);
|
|
1938
|
+
}
|
|
1939
|
+
const book = tree.get(a.recordset);
|
|
1940
|
+
return registerImages(tree, shared, [{ file: a.path, image: n, url: book?.url, from: a.name }], a.recordset);
|
|
1941
|
+
});
|
|
1942
|
+
if (!tree.dryRun && out.added.length)
|
|
1943
|
+
fs.rmSync(a.path, { force: true });
|
|
1944
|
+
const kept = media.filter((m) => !replaced.includes(m.id));
|
|
1945
|
+
return {
|
|
1946
|
+
text: lines(out.added.length ? `${a.file} registered as image ${n} of ${a.recordset}: ${out.added[0].id}` : `${a.file} not registered`, replaced.length ? `withdrawn, kept: ${replaced.join(" ")}` : undefined, opts.take && kept.length ? `cited by a source, stays beside it: ${kept.map((m) => m.id).join(" ")}` : undefined, ...out.clashes.map((c) => `⚠ ${c}`), ...out.copies, out.woken.length ? `back in the queue (they waited for these images): ${out.woken.join(" ")}` : undefined),
|
|
1947
|
+
data: { aside: json(a), done: opts.take ? "take" : "image", image: n, added: out.added.map((m) => m.id), replaced, woken: out.woken },
|
|
1948
|
+
};
|
|
1949
|
+
},
|
|
1816
1950
|
}, {
|
|
1817
1951
|
path: ["media", "view"],
|
|
1818
1952
|
summary: "Make views of images to look at: a crop, a half page, enlarged, more contrast, a grid — several in one call",
|
package/dist/commands/setup.js
CHANGED
|
@@ -1239,6 +1239,7 @@ const FALLBACKS = {
|
|
|
1239
1239
|
"sync.edits": () => "conflict",
|
|
1240
1240
|
"sync.review": () => "off",
|
|
1241
1241
|
"read.sourceTask": () => "ask",
|
|
1242
|
+
"run.confirm": () => "ask",
|
|
1242
1243
|
"hypotheses.decide": () => "agent",
|
|
1243
1244
|
"excerpts.quality": (s, tree) => s.excerpts(tree).quality,
|
|
1244
1245
|
"excerpts.for": (s, tree) => s.excerpts(tree).for,
|
|
@@ -1756,6 +1757,11 @@ async function setUserSetting(ctx, key, value) {
|
|
|
1756
1757
|
if (key === "run.gate" && value !== s.runGate())
|
|
1757
1758
|
if (!(await ctx.requireHumanYes(value ? `Let the gate "${value}" decide when the agent working alone goes on?` : `Remove the gate "${s.runGate()}" — the agent working alone no longer asks it?`, value ? `strom config set run.gate ${value}` : "strom config unset run.gate", "run.gate", ui(ctx.uiLang(), value ? "ui.consent.gate.set" : "ui.consent.gate.unset", { name: String(value ?? s.runGate()) }))))
|
|
1758
1759
|
return false;
|
|
1760
|
+
// The agent started from the Strom app's links without the question (a standing yes to its subscription or credit):
|
|
1761
|
+
// turned on by the user alone, their yes in a terminal too; asking again is anyone's.
|
|
1762
|
+
if (key === "run.confirm" && value === "no" && s.runConfirm() !== "no")
|
|
1763
|
+
if (!(await ctx.requireHumanYes("Start the agent from the Strom app's links without asking first (it works on the subscription or AI credit)?", "strom config set run.confirm no", "run.confirm", ui(ctx.uiLang(), "ui.consent.run.confirm"))))
|
|
1764
|
+
return false;
|
|
1759
1765
|
// A person's pace for the images of restricted archives: theirs alone, faster or slower — never the agent's.
|
|
1760
1766
|
if (key === "archive.pace" && value !== (s.config.archivePace ?? undefined)) {
|
|
1761
1767
|
const p = typeof value === "string" && value !== "auto" ? parseArchivePace(value) : undefined;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// strom source retract | restore: a source the person deletes — retracted in the research with its citations kept in it,
|
|
2
|
+
// put back as it was (spec 117, core/sourceretract.ts). The person's alone: their terminal (their yes), a window of the
|
|
3
|
+
// system, or the Strom app's bridge with the confirmation it signed of what the person saw; an agent only previews it
|
|
4
|
+
// (--dry-run) to propose it to the person with the counts.
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { register } from "../cli/registry.js";
|
|
7
|
+
import { lines, shellArg } from "../cli/format.js";
|
|
8
|
+
import { ui } from "../cli/ui.js";
|
|
9
|
+
import { notFound, UsageError } from "../core/errors.js";
|
|
10
|
+
import { phrase } from "../core/phrases.js";
|
|
11
|
+
import { checkRetractConfirm, restoreSources, retractImpacts, retractSources, RETRACT_MOST } from "../core/sourceretract.js";
|
|
12
|
+
import { isAgent } from "../core/which.js";
|
|
13
|
+
const PERSON_RETRACT = "Deleting a source is the person's own (the Strom app, or their terminal): an agent shows what it would take (strom source retract <S…> --dry-run) and proposes it, never runs it";
|
|
14
|
+
const PERSON_RESTORE = "Putting back a source the person deleted is the person's own (the Strom app, or their terminal): an agent tells them it can be, never runs it";
|
|
15
|
+
/** The sources given: the arguments and --sources-from (a file, - stdin: the bridge's list). */
|
|
16
|
+
function sourcesGiven(ctx, args, opts) {
|
|
17
|
+
const from = opts["sources-from"];
|
|
18
|
+
let more = [];
|
|
19
|
+
if (typeof from === "string") {
|
|
20
|
+
const text = from === "-" ? (ctx.io.stdinText?.() ?? "") : fs.existsSync(ctx.resolvePath(from)) ? fs.readFileSync(ctx.resolvePath(from), "utf8") : undefined;
|
|
21
|
+
if (text === undefined)
|
|
22
|
+
throw notFound(from);
|
|
23
|
+
more = text.split(/[\s,]+/u).filter(Boolean);
|
|
24
|
+
}
|
|
25
|
+
const ids = [...args, ...more];
|
|
26
|
+
if (!ids.length)
|
|
27
|
+
throw new UsageError("give the sources (S…)", { code: "source.body", hint: "strom source list" });
|
|
28
|
+
return ids;
|
|
29
|
+
}
|
|
30
|
+
const citesOf = (i) => i.counts.names + i.counts.events + i.counts.families;
|
|
31
|
+
/** A list of what it takes for a person: its first IDs, how many more. */
|
|
32
|
+
const some = (ids, more = 0) => (ids.length ? `${ids.slice(0, 5).join(", ")}${ids.length + more > 5 ? ` (+${ids.length + more - Math.min(ids.length, 5)})` : ""}` : "0");
|
|
33
|
+
const factIds = (list) => list.map((f) => `${f.owner} ${f.fact}`);
|
|
34
|
+
/** What deleting a source would take, for a person (strom source retract --dry-run, strom input delete --retract-sources). */
|
|
35
|
+
export function wouldLine(lang, i) {
|
|
36
|
+
return ui(lang, "ui.source.retract.would", {
|
|
37
|
+
name: i.title,
|
|
38
|
+
id: i.id,
|
|
39
|
+
cites: citesOf(i),
|
|
40
|
+
stories: i.counts.stories,
|
|
41
|
+
bare: some(factIds(i.bare), i.more.bare),
|
|
42
|
+
lowered: some(factIds(i.lowered), i.more.lowered),
|
|
43
|
+
tasks: some(i.tasks.map((t) => `${t.id} ${t.becomes}`), i.more.tasks),
|
|
44
|
+
conflicts: some(i.conflicts.filter((c) => c.becomes === "review").map((c) => c.id)),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const sourcesOption = { name: "sources-from", type: "string", value: "<file|->", description: "the source IDs from a file, one a line (- = stdin)" };
|
|
48
|
+
register({
|
|
49
|
+
path: ["source", "retract"],
|
|
50
|
+
summary: "Delete a source: retracted with its citations kept in it, to be put back (the person's alone); --dry-run says what it takes",
|
|
51
|
+
group: "sources",
|
|
52
|
+
tree: true,
|
|
53
|
+
writes: true,
|
|
54
|
+
// the preview reads only: anybody's, an agent's too, also on a research sealed on another computer
|
|
55
|
+
writesWith: ({ opts }) => !opts["dry-run"],
|
|
56
|
+
person: PERSON_RETRACT,
|
|
57
|
+
agentMay: { when: "--dry-run (what it would take, to propose it to the person with the counts)", check: (_ctx, { opts }) => !!opts["dry-run"] },
|
|
58
|
+
description: `Of each source given (at most ${RETRACT_MOST}): retracted (the reason "deleted"), gone from the family tree the Strom app gets.\n` +
|
|
59
|
+
"Its citations are taken off the facts, names and families and kept in the source; the values stay, a fact the\n" +
|
|
60
|
+
"citations left cannot carry as sure is lowered; a main citation goes (none other is chosen). A task working on it\n" +
|
|
61
|
+
"alone is given up, one with other places goes on without it; a conflict standing on it is marked for review, its\n" +
|
|
62
|
+
"state kept (strom conflict keep, or deciding it, takes the mark off). The text of a story never changes. One\n" +
|
|
63
|
+
"operation of the history; strom source restore puts back what it took. All or nothing: a source the research does\n" +
|
|
64
|
+
"not have or retracted already, and nothing is written. --dry-run says all of it (--json: impacts), anybody's. Without\n" +
|
|
65
|
+
"it the person says yes in their own terminal (Enter says no), else in a window of the system; nobody to ask: exit\n" +
|
|
66
|
+
"4. An agent never runs it: it may propose it to the person with the counts of --dry-run. Many sources:\n" +
|
|
67
|
+
"--sources-from <file> (one ID a line; - = stdin).",
|
|
68
|
+
args: [{ name: "sources", description: "source IDs (S0001 …)", variadic: true, unless: ["sources-from"] }],
|
|
69
|
+
options: [
|
|
70
|
+
sourcesOption,
|
|
71
|
+
// the Strom app's yes: what its bridge signed of the impacts the person saw there (POST /source/retract)
|
|
72
|
+
{ name: "confirm", type: "string", value: "<token>", hidden: true, description: "the Strom app's confirmation, signed by its bridge" },
|
|
73
|
+
],
|
|
74
|
+
examples: ["strom source retract S0002 --dry-run", 'strom source retract S0002 --reason "<why>"'],
|
|
75
|
+
async run(ctx, { args, opts }) {
|
|
76
|
+
const tree = ctx.tree();
|
|
77
|
+
const impacts = retractImpacts(tree, sourcesGiven(ctx, args, opts));
|
|
78
|
+
const sources = impacts.map((i) => i.id);
|
|
79
|
+
const lang = tree.lang;
|
|
80
|
+
if (ctx.dryRun)
|
|
81
|
+
return { text: lines(...impacts.map((i) => wouldLine(lang, i))), data: { sources, impacts } };
|
|
82
|
+
const reason = typeof opts.reason === "string" ? opts.reason : undefined;
|
|
83
|
+
if (typeof opts.confirm === "string") {
|
|
84
|
+
// the Strom app's: its bridge signed the impacts the person saw and said yes to there — only those, only a while.
|
|
85
|
+
// An agent's marks outweigh STROM_FOR_APP (the bridge runs this without them)
|
|
86
|
+
if (isAgent(ctx.env))
|
|
87
|
+
throw new UsageError("an agent never deletes a source, not even with the Strom app's confirmation: nothing written", { code: "source.agent", hint: "the person deletes it in the Strom app, or says yes to strom source retract in their own terminal" });
|
|
88
|
+
const said = ctx.env.STROM_FOR_APP === "1" ? checkRetractConfirm(tree.key, sources, impacts, opts.confirm) : "invalid";
|
|
89
|
+
if (said === "changed")
|
|
90
|
+
throw new UsageError("deleting the sources would take other things with them than the person saw: nothing written", { code: "source.retract-changed", params: { sources: sources.join(",").slice(0, 200) }, hint: "the person looks at the list again in the Strom app" });
|
|
91
|
+
if (said !== "ok")
|
|
92
|
+
throw new UsageError("no confirmation of the Strom app that holds (signed by its bridge, at most 15 minutes old): nothing written", { code: "source.body", hint: "strom help source retract" });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const set = `strom source retract ${sources.length > 10 ? `${sources.slice(0, 10).join(" ")} …` : sources.join(" ")}${reason ? ` --reason ${shellArg(reason)}` : ""}`;
|
|
96
|
+
const says = ui(ctx.uiLang(), "ui.consent.retract", {
|
|
97
|
+
list: impacts.map((i) => `${i.title} [${i.id}]`).join(", "),
|
|
98
|
+
cites: impacts.reduce((n, i) => n + citesOf(i), 0),
|
|
99
|
+
stories: impacts.reduce((n, i) => n + i.counts.stories, 0),
|
|
100
|
+
lowered: impacts.reduce((n, i) => n + i.lowered.length + i.more.lowered, 0),
|
|
101
|
+
});
|
|
102
|
+
const how = await ctx.requireHumanYes(`Delete ${sources.length} source(s) (${sources.slice(0, 10).join(", ")}${sources.length > 10 ? " …" : ""})? Only the user decides this; an agent never deletes one, it may propose it.`, set, "source.retract", says);
|
|
103
|
+
if (!how)
|
|
104
|
+
return { text: ui(ctx.uiLang(), "ui.consent.delete.no"), data: { sources, retracted: [], impacts } };
|
|
105
|
+
}
|
|
106
|
+
const got = retractSources(tree, sources, { via: ctx.env.STROM_FOR_APP === "1" ? "bridge" : "terminal", ...(reason ? { reason } : {}) });
|
|
107
|
+
return {
|
|
108
|
+
text: lines(...got.impacts.map((i) => phrase(lang, "log.source.deleted", { name: i.title, id: i.id, cites: citesOf(i), stories: i.counts.stories })), `strom source restore ${got.retracted.join(" ")}`),
|
|
109
|
+
data: got,
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
}, {
|
|
113
|
+
path: ["source", "restore"],
|
|
114
|
+
summary: "Put back a source the person deleted (strom source retract): the same ID, its citations where they were (the person's alone)",
|
|
115
|
+
group: "sources",
|
|
116
|
+
tree: true,
|
|
117
|
+
writes: true,
|
|
118
|
+
person: PERSON_RESTORE,
|
|
119
|
+
description: "Of each source given (deleted by strom source retract): the same record back, each citation kept in it on the fact\n" +
|
|
120
|
+
"it was on — found by its ID where it is now (a person merged since: under the one it went into) — unless the fact\n" +
|
|
121
|
+
"is gone or cites it again already (--json: skipped, why gone | already | main); a main citation only where no other\n" +
|
|
122
|
+
"became main meanwhile; a status lowered only where nobody changed it since and the citations carry it; the tasks it\n" +
|
|
123
|
+
"changed where unchanged since (never with a place of a source still deleted); the marks of review gone. One\n" +
|
|
124
|
+
"operation of the history. Refused: a source not retracted (source.notRetracted), one retracted otherwise — merged,\n" +
|
|
125
|
+
"taken back by a sync (source.notRestorable).",
|
|
126
|
+
args: [{ name: "sources", description: "source IDs (S0001 …)", variadic: true, unless: ["sources-from"] }],
|
|
127
|
+
options: [sourcesOption],
|
|
128
|
+
examples: ["strom source restore S0007"],
|
|
129
|
+
run(ctx, { args, opts }) {
|
|
130
|
+
const tree = ctx.tree();
|
|
131
|
+
const got = restoreSources(tree, sourcesGiven(ctx, args, opts));
|
|
132
|
+
const lang = tree.lang;
|
|
133
|
+
const skipped = got.skipped.filter((s) => s.why !== "main").length;
|
|
134
|
+
return {
|
|
135
|
+
text: lines(phrase(lang, "log.source.restored", { name: got.restored.map((id) => tree.get(id)?.title ?? id).join(", "), id: got.restored.join(", "), cites: got.citations }), skipped ? ui(lang, "ui.source.restore.skipped", { n: skipped }) : undefined),
|
|
136
|
+
data: got,
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
package/dist/commands/sources.js
CHANGED
|
@@ -19,11 +19,12 @@ import { clipNote, clipText, imageOfRef, MAX_CLIPS, transcriptNote } from "../co
|
|
|
19
19
|
import { mediaOrient, partRegion } from "../core/views.js";
|
|
20
20
|
import { fileToShown } from "../image/image.js";
|
|
21
21
|
import { formatName } from "../core/people.js";
|
|
22
|
+
import { deletedSource } from "../core/sourceretract.js";
|
|
22
23
|
import { yearsOption, yearsOverlap } from "../core/years.js";
|
|
23
24
|
import { readAgainOf, unverifiedReading } from "../core/sourceread.js";
|
|
24
25
|
import { levelWords } from "../core/archiveasks.js";
|
|
25
26
|
import { bookUrlKey, sameBooks, sameBookText } from "../core/samebook.js";
|
|
26
|
-
import { handReading, typedByHand, userReading } from "../core/readers.js";
|
|
27
|
+
import { handReading, localDayOf, typedByHand, userReading } from "../core/readers.js";
|
|
27
28
|
import { agentClipped, joinedText, mergeOverlappingClips, researchWritesNow } from "../core/clipmerge.js";
|
|
28
29
|
import { transcriptDiffers } from "../core/transcriptguard.js";
|
|
29
30
|
import { decideProposal, proposeTranscript } from "../core/proposal.js";
|
|
@@ -244,21 +245,22 @@ register({
|
|
|
244
245
|
{ name: "kind", type: "string", value: "<kind>", description: "only this kind" },
|
|
245
246
|
{ name: "recordset", type: "string", value: "<B…>", description: "only from this recordset" },
|
|
246
247
|
{ name: "full", type: "boolean", description: "--json: whole records instead of one row each" },
|
|
248
|
+
{ name: "retracted", type: "boolean", description: "only the sources retracted: deleted by the person (when, how many citations kept in it — strom source restore puts it back), merged, taken back" },
|
|
247
249
|
],
|
|
248
250
|
run(ctx, { args, opts }) {
|
|
249
251
|
const tree = ctx.tree();
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (opts.recordset)
|
|
256
|
-
all = all.filter((s) => s.recordset === normId(opts.recordset));
|
|
252
|
+
const wanted = (s) => (!args[0] || matches(s.title, args[0]) || matches(s.locator, args[0]) || matches(s.folio, args[0]) || matches(s.image, args[0]) || matches(s.transcript, args[0])) &&
|
|
253
|
+
(!opts.kind || s.kind === opts.kind) &&
|
|
254
|
+
(!opts.recordset || s.recordset === normId(opts.recordset));
|
|
255
|
+
const found = tree.list("source").filter(wanted);
|
|
256
|
+
const all = found.filter((s) => !!s.retracted === !!opts.retracted);
|
|
257
257
|
const page = paginate(all, ctx.limit, ctx.page);
|
|
258
258
|
const text = all.length
|
|
259
|
-
?
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
? opts.retracted
|
|
260
|
+
? lines(table(page.items.map((s) => [s.id, s.kind, truncate(s.title, 60), retractedLine(s)])), moreLine(page, "strom source list --retracted"), page.items.some(deletedSource) ? "put back a deleted one (the person's alone): strom source restore <S…>" : undefined)
|
|
261
|
+
: lines(table(page.items.map((s) => [s.id, s.kind, truncate(s.title, 60), s.locator ?? "", s.form === "original" ? "" : s.form])), moreLine(page, "strom source list"))
|
|
262
|
+
: opts.retracted ? "no retracted sources match" : lines("no sources match", retractedHint(found));
|
|
263
|
+
const rows = opts.full ? page.items : page.items.map((s) => ({ id: s.id, kind: s.kind, title: s.title, locator: s.locator, form: s.form, information: s.information, ...(s.retracted ? retractedData(s) : {}) }));
|
|
262
264
|
return { text, data: { total: page.total, sources: rows } };
|
|
263
265
|
},
|
|
264
266
|
}, {
|
|
@@ -294,13 +296,13 @@ register({
|
|
|
294
296
|
}
|
|
295
297
|
const again = readAgainState(tree, s);
|
|
296
298
|
const loc = locationOf(tree, s);
|
|
297
|
-
const text = lines(`${s.id} ${s.title}`, `kind ${s.kind} · ${s.form} · information ${s.information}${s.language ? ` · language ${s.language}` : ""}${s.date ? ` · dated ${s.date}` : ""}`, s.recordset || s.repository ? `in ${[s.recordset, s.repository].filter(Boolean).join(" · ")}${s.locator ? ` · ${s.locator}` : ""}` : s.locator ? `at ${s.locator}` : undefined,
|
|
299
|
+
const text = lines(`${s.id} ${s.title}`, s.retracted ? `RETRACTED ${retractedLine(s)}${deletedSource(s) ? ` — the person puts it back: strom source restore ${s.id}` : ""}` : undefined, `kind ${s.kind} · ${s.form} · information ${s.information}${s.language ? ` · language ${s.language}` : ""}${s.date ? ` · dated ${s.date}` : ""}`, s.recordset || s.repository ? `in ${[s.recordset, s.repository].filter(Boolean).join(" · ")}${s.locator ? ` · ${s.locator}` : ""}` : s.locator ? `at ${s.locator}` : undefined,
|
|
298
300
|
// what finds the entry again when its link no longer leads to it: the archive, the book's call number, the folio, the image
|
|
299
301
|
loc.line ? `find ${loc.line}` : undefined, loc.proposed ? `from its locator: ${[loc.proposed.folio ? `--folio ${shellArg(loc.proposed.folio)}` : "", loc.proposed.image ? `--image ${shellArg(loc.proposed.image)}` : "", loc.proposed.locator !== undefined ? locatorArg(loc.proposed.locator) : ""].filter(Boolean).join(" ")} (strom source edit ${s.id} to take them)` : undefined,
|
|
300
302
|
// with a proposal, its edit says the rest (of the fields it takes too)
|
|
301
303
|
overlapLine(s, !loc.proposed), s.url ? `url ${s.url}` : undefined, s.media?.length ? `images ${s.media.map((id) => { const m = tree.get(id); return m ? `${id}${m.recordset ? ` (${m.recordset}:${m.image ?? "?"})` : ""}` : id; }).join(" · ")} — strom media view <M…>` : undefined,
|
|
302
304
|
// as --clip takes them: of the picture as its view shows it
|
|
303
|
-
s.clips?.length ? `clips ${s.clips.map((c, i) => `${i + 1}. ${clipText({ media: c.media, region: fileToShown(c.region, mediaOrient(shared, tree.get(c.media))) })}`).join(" · ")} — where the entry is on its image` : undefined, s.transcript ? `\ntranscript\n${s.transcript}` : undefined, s.translation ? `\ntranslation\n${s.translation}` : undefined, againLine(again, s.id, again?.state === "unchecked" ? (unverifiedReading(tree, s)?.places ?? 0) : 0), citing.length ? `\ncited by\n${citing.map((c) => ` ${c}`).join("\n")}` : "\ncited by nothing yet", ...s.notes.map((n) => `note ${n.text}`));
|
|
305
|
+
s.clips?.length ? `clips ${s.clips.map((c, i) => `${i + 1}. ${clipText({ media: c.media, region: fileToShown(c.region, mediaOrient(shared, tree.get(c.media))) })}`).join(" · ")} — where the entry is on its image` : undefined, s.transcript ? `\ntranscript\n${s.transcript}` : undefined, s.translation ? `\ntranslation\n${s.translation}` : undefined, againLine(again, s.id, again?.state === "unchecked" ? (unverifiedReading(tree, s)?.places ?? 0) : 0), citing.length ? `\ncited by\n${citing.map((c) => ` ${c}`).join("\n")}` : deletedSource(s) ? `\ncited by nothing now — ${s.deleted.cites.length === 1 ? "the citation" : `the ${s.deleted.cites.length} citations`} kept in it come${s.deleted.cites.length === 1 ? "s" : ""} back with strom source restore ${s.id}` : s.retracted ? "\ncited by nothing" : "\ncited by nothing yet", ...s.notes.map((n) => `note ${n.text}`));
|
|
304
306
|
return {
|
|
305
307
|
text,
|
|
306
308
|
data: {
|
|
@@ -310,6 +312,7 @@ register({
|
|
|
310
312
|
...(loc.proposed ? { proposed: loc.proposed } : {}),
|
|
311
313
|
...(locatorOverlap(s) ? { locatorOverlap: locatorOverlap(s) } : {}),
|
|
312
314
|
citedBy: citing,
|
|
315
|
+
...(s.retracted ? retractedData(s) : {}),
|
|
313
316
|
...(again ? { readAgain: again } : {}),
|
|
314
317
|
},
|
|
315
318
|
};
|
|
@@ -1127,3 +1130,29 @@ register({
|
|
|
1127
1130
|
return { text: written(tree), data: { ...confirmAnswer(tree, source.id), task: t.id, take } };
|
|
1128
1131
|
},
|
|
1129
1132
|
});
|
|
1133
|
+
/** A retracted source in one line: deleted by the person (when, where, how many citations kept in it), merged, taken back. */
|
|
1134
|
+
function retractedLine(s) {
|
|
1135
|
+
const at = localDayOf(s.retracted.at);
|
|
1136
|
+
if (deletedSource(s))
|
|
1137
|
+
return `deleted by the person ${at}${s.deleted.via === "bridge" ? " in the Strom app" : s.deleted.via === "terminal" ? " in the terminal" : ""} · ${counted(s.deleted.cites.length, "citation")} kept in it`;
|
|
1138
|
+
if (s.mergedInto)
|
|
1139
|
+
return `merged into ${s.mergedInto} ${at}`;
|
|
1140
|
+
return `retracted ${at}: ${s.retracted.reason}`;
|
|
1141
|
+
}
|
|
1142
|
+
/** Nothing standing matched, but retracted sources match: where they are listed. */
|
|
1143
|
+
function retractedHint(all) {
|
|
1144
|
+
const n = all.filter((s) => s.retracted).length;
|
|
1145
|
+
return n ? `${counted(n, "retracted source")}: strom source list --retracted` : undefined;
|
|
1146
|
+
}
|
|
1147
|
+
/** The same for --json: when, why, and of a deleted one how many citations it keeps and the command that puts it back. */
|
|
1148
|
+
function retractedData(s) {
|
|
1149
|
+
const d = deletedSource(s) ? s.deleted : undefined;
|
|
1150
|
+
return {
|
|
1151
|
+
retracted: {
|
|
1152
|
+
at: s.retracted.at,
|
|
1153
|
+
reason: s.retracted.reason,
|
|
1154
|
+
...(d ? { deleted: true, ...(d.via ? { via: d.via } : {}), cites: d.cites.length, restore: `strom source restore ${s.id}` } : {}),
|
|
1155
|
+
...(s.mergedInto ? { mergedInto: s.mergedInto } : {}),
|
|
1156
|
+
},
|
|
1157
|
+
};
|
|
1158
|
+
}
|