strom-research 1.33.0-beta.1 → 1.33.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 +8 -1
- package/CHANGELOG.de.md +9 -1
- package/CHANGELOG.md +8 -1
- package/CHANGELOG.pl.md +9 -1
- package/dist/brief/brief.js +10 -3
- package/dist/cli/execute.js +40 -9
- package/dist/cli/registry.js +3 -3
- package/dist/commands/analysis.js +5 -4
- package/dist/commands/connectors.js +11 -3
- package/dist/commands/grep.js +6 -4
- package/dist/commands/history.js +5 -2
- package/dist/commands/media.js +209 -32
- package/dist/commands/query.js +1 -1
- package/dist/commands/sources.js +1 -1
- package/dist/commands/tasks.js +11 -2
- package/dist/core/grep.js +36 -3
- package/dist/core/indexfirst.js +57 -21
- package/dist/core/live.js +21 -1
- package/dist/core/tree.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.cs.md
CHANGED
|
@@ -7,7 +7,7 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
7
7
|
|
|
8
8
|
## 1.33.0
|
|
9
9
|
|
|
10
|
-
*Připravuje se: bety do 1.33.0-beta.
|
|
10
|
+
*Připravuje se: bety do 1.33.0-beta.2. Oddíl bude úplný s vydáním.*
|
|
11
11
|
|
|
12
12
|
- **Archivy, kam smí jen prohlížeč člověka:** agent tam už nezkouší stahovač stromu ani hledání v katalogu. Jejich
|
|
13
13
|
snímky jdou po jednom přes prohlížeč agenta (`strom media save`), jakmile to člověk povolí „přes prohlížeč“, jinak je
|
|
@@ -21,6 +21,13 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
21
21
|
přes `strom history list --event <id>`.
|
|
22
22
|
- **Z aplikace Strom:** údaj poslaný zpět v jiném tvaru téhož druhu (událost typu Census místo sčítání) se pozná jako
|
|
23
23
|
tentýž údaj – beze změny, když se nic nezměnilo, úprava toho údaje, když se změnilo datum.
|
|
24
|
+
- **Slabé a očekávané snímky:** slabý snímek se uloží ještě jednou přes `strom media save --again` jako nová kopie vedle
|
|
25
|
+
první, nic se neodebere a snímkem je ta nejostřejší; snímek, na který čeká úkol, řekne, kdo na něj čeká a další krok;
|
|
26
|
+
stahování, které se ještě zapisuje, se počká, a `strom fetch --take` vezme seznam snímků i vedle plánu stránek.
|
|
27
|
+
- **Indexy:** index jiné farnosti se nikdy nenabídne přes příslušnost, která neříká kterou farnost; počítají se roky
|
|
28
|
+
příslušnosti.
|
|
29
|
+
- **Příkazy, jak je agenti píší:** jiný název volby nebo příkazu se přijme, nebo se odpoví tím správným;
|
|
30
|
+
`strom grep --in` se začátkem názvů souborů čte tyto soubory.
|
|
24
31
|
|
|
25
32
|
## 1.32.0
|
|
26
33
|
|
package/CHANGELOG.de.md
CHANGED
|
@@ -7,7 +7,7 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
7
7
|
|
|
8
8
|
## 1.33.0
|
|
9
9
|
|
|
10
|
-
*In Vorbereitung: die Betas bis 1.33.0-beta.
|
|
10
|
+
*In Vorbereitung: die Betas bis 1.33.0-beta.2. Der Abschnitt ist mit dem Release vollständig.*
|
|
11
11
|
|
|
12
12
|
- **Archive, die nur der Browser eines Menschen betreten darf:** Der Agent versucht dort weder den Downloader von strom
|
|
13
13
|
noch die Katalogsuche. Ihre Bilder kommen einzeln über den Browser des Agenten (`strom media save`), sobald der
|
|
@@ -24,6 +24,14 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
24
24
|
- **Aus der Strom-App:** Eine Angabe, die in einer anderen Form derselben Art zurückkommt (ein Ereignis vom Typ Census
|
|
25
25
|
für eine Volkszählung), wird als dieselbe Angabe erkannt – keine Änderung, wenn sich nichts geändert hat, eine
|
|
26
26
|
Bearbeitung dieser Angabe, wenn sich ihr Datum geändert hat.
|
|
27
|
+
- **Schwache und erwartete Bilder:** Ein schwacher Scan wird mit `strom media save --again` noch einmal als neue Kopie
|
|
28
|
+
neben der ersten gespeichert, nichts wird entfernt, und die schärfste Kopie ist das Bild; ein Bild, auf das eine Aufgabe
|
|
29
|
+
wartet, nennt, wer wartet, und den nächsten Schritt; auf einen Download, der noch geschrieben wird, wird gewartet, und
|
|
30
|
+
`strom fetch --take` nimmt eine Liste von Bildern auch neben einem Seitenplan.
|
|
31
|
+
- **Indizes:** Ein Index einer anderen Pfarrei wird nie über eine Zuständigkeit angeboten, die nicht sagt, welche
|
|
32
|
+
Pfarrei; die Jahre einer Zuständigkeit zählen.
|
|
33
|
+
- **Befehle, wie Agenten sie tippen:** Ein anderer Name für eine Option oder einen Befehl wird angenommen oder mit dem
|
|
34
|
+
richtigen beantwortet; `strom grep --in` mit dem Anfang von Dateinamen liest diese Dateien.
|
|
27
35
|
|
|
28
36
|
## 1.32.0
|
|
29
37
|
|
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,7 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
7
7
|
|
|
8
8
|
## 1.33.0
|
|
9
9
|
|
|
10
|
-
*In preparation: the betas up to 1.33.0-beta.
|
|
10
|
+
*In preparation: the betas up to 1.33.0-beta.2. The section is complete with the release.*
|
|
11
11
|
|
|
12
12
|
- **Archives only a person's browser may enter:** the agent no longer tries strom's downloader or catalogue search
|
|
13
13
|
there. Their images go one at a time through the agent's browser (`strom media save`) once the person allows "through
|
|
@@ -21,6 +21,13 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
21
21
|
`strom history list --event <id>`.
|
|
22
22
|
- **From the Strom app:** a fact sent back in another shape of the same kind (an event of type Census for a census) is
|
|
23
23
|
recognized as that fact — no change when nothing changed, an edit of that fact when its date did.
|
|
24
|
+
- **Weak and awaited images:** a weak scan is saved once more with `strom media save --again` as a new copy beside the
|
|
25
|
+
first, nothing removed, and the sharpest copy is the image; an image a task waits for says who waits and the next step;
|
|
26
|
+
a download still being written is waited for, and `strom fetch --take` takes a list of images even beside a page plan.
|
|
27
|
+
- **Indexes:** an index of another parish is never offered through a jurisdiction that does not say which parish; the
|
|
28
|
+
years of a jurisdiction count.
|
|
29
|
+
- **Commands as agents type them:** another name for an option or a command is taken, or answered with the right one;
|
|
30
|
+
`strom grep --in` with the start of file names reads those files.
|
|
24
31
|
|
|
25
32
|
## 1.32.0
|
|
26
33
|
|
package/CHANGELOG.pl.md
CHANGED
|
@@ -7,7 +7,7 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
7
7
|
|
|
8
8
|
## 1.33.0
|
|
9
9
|
|
|
10
|
-
*W przygotowaniu: bety do 1.33.0-beta.
|
|
10
|
+
*W przygotowaniu: bety do 1.33.0-beta.2. Sekcja będzie kompletna z wydaniem.*
|
|
11
11
|
|
|
12
12
|
- **Archiwa, do których wolno wejść tylko przeglądarką człowieka:** agent nie próbuje już tam pobierania przez strom ani
|
|
13
13
|
wyszukiwania w katalogu. Ich skany idą pojedynczo przez przeglądarkę agenta (`strom media save`), gdy człowiek zezwoli
|
|
@@ -23,6 +23,14 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
23
23
|
`strom history list --event <id>`.
|
|
24
24
|
- **Z aplikacji Strom:** fakt odesłany w innej postaci tego samego rodzaju (zdarzenie typu Census zamiast spisu) jest
|
|
25
25
|
rozpoznawany jako ten sam fakt – bez zmiany, gdy nic się nie zmieniło, jako edycja tego faktu, gdy zmieniła się data.
|
|
26
|
+
- **Słabe i oczekiwane skany:** słaby skan zapisuje się jeszcze raz przez `strom media save --again` jako nową kopię obok
|
|
27
|
+
pierwszej, nic nie jest usuwane, a skanem jest najostrzejsza kopia; skan, na który czeka zadanie, podaje, kto czeka,
|
|
28
|
+
i następny krok; na pobieranie, które jeszcze się zapisuje, strom czeka, a `strom fetch --take` bierze listę skanów
|
|
29
|
+
także obok planu stron.
|
|
30
|
+
- **Indeksy:** indeks innej parafii nigdy nie jest proponowany przez przynależność, która nie mówi, o którą parafię
|
|
31
|
+
chodzi; liczą się lata przynależności.
|
|
32
|
+
- **Polecenia tak, jak wpisują je agenci:** inna nazwa opcji lub polecenia zostaje przyjęta albo strom odpowiada właściwą;
|
|
33
|
+
`strom grep --in` z początkiem nazw plików czyta te pliki.
|
|
26
34
|
|
|
27
35
|
## 1.32.0
|
|
28
36
|
|
package/dist/brief/brief.js
CHANGED
|
@@ -690,7 +690,7 @@ function bookRoute(tree, b, ready) {
|
|
|
690
690
|
return { connector: c.name, ...(found.size === 1 ? { book: [...found][0] } : {}), part, browser };
|
|
691
691
|
}
|
|
692
692
|
/** How many images of a record set are registered, how to look at them, and how the others come. */
|
|
693
|
-
function imagesLines(tree, b, route, shape, finder, noSharper = false, waiting, handOnly = false) {
|
|
693
|
+
function imagesLines(tree, b, route, shape, finder, noSharper = false, waiting, handOnly = false, saveAgain) {
|
|
694
694
|
// each image once: its parts and other copies are the same image
|
|
695
695
|
const nums = imagesIndex(tree).sets.get(b.id)?.images ?? [];
|
|
696
696
|
const repo = b.repository ? tree.get(b.repository) : undefined;
|
|
@@ -724,7 +724,12 @@ function imagesLines(tree, b, route, shape, finder, noSharper = false, waiting,
|
|
|
724
724
|
return [
|
|
725
725
|
` images registered (${nums.length}): ${which} · strom media view ${b.id}:<image>[-<image>] [--half left|right|both] [--grid] [--crop x,y,w,h]…`,
|
|
726
726
|
weak
|
|
727
|
-
? ` weak scans (long side ${weak} px): a negative on them is weak — ${route?.part && !noSharper
|
|
727
|
+
? ` weak scans (long side ${weak} px): a negative on them is weak — ${route?.part && !noSharper
|
|
728
|
+
? `a part sharper: strom fetch ${route.connector} --recordset ${b.id} --images <n> --crop x,y,w,h`
|
|
729
|
+
: // an archive your own browser saves images of: the image once more, sharper — never a wait for the person
|
|
730
|
+
saveAgain
|
|
731
|
+
? `a sharper scan through your browser: ${saveAgain} (the viewer zoomed in on the entry, or its full resolution; a new copy beside it, nothing removed — the sharpest is the image)`
|
|
732
|
+
: SHARPER_SCAN}`
|
|
728
733
|
: "",
|
|
729
734
|
// the others: through the connector, else as the archive allows (the person's decision waiting: not fetched)
|
|
730
735
|
(waiting ? ` more: ${waiting}` : undefined) ??
|
|
@@ -1368,6 +1373,8 @@ export function buildBrief(tree, opts) {
|
|
|
1368
1373
|
return a?.permitted && browserState(tree.env, tuneAgent, tree.root).state === "ready" ? `strom media save ${task?.id ?? "T…"} --image <n> --at <the archive's page of that image>` : undefined;
|
|
1369
1374
|
};
|
|
1370
1375
|
const finders = new Map(sets.map((b) => [b.id, routes.get(b.id) ? undefined : bookFinder(tree, b, installed, opts.shared, saveFor(b))]));
|
|
1376
|
+
// a weak scan of such an archive: the image saved once more through that browser (strom media save --again)
|
|
1377
|
+
const saveAgainFor = (b) => (saveFor(b) ? `strom media save ${task?.id ?? "T…"} --image <n> --recordset ${b.id} --at <the archive's page of that image> --again` : undefined);
|
|
1371
1378
|
const shapeFor = sets.find((b) => routes.get(b.id))?.id;
|
|
1372
1379
|
if (sets.length)
|
|
1373
1380
|
sections.push({
|
|
@@ -1392,7 +1399,7 @@ export function buildBrief(tree, opts) {
|
|
|
1392
1399
|
browserLine(tree, b, repo, opts.shared, tuneAgent, task?.id),
|
|
1393
1400
|
b.layout ? ` layout: ${b.layout}` : "",
|
|
1394
1401
|
calibrationLine(b) ? ` ${calibrationLine(b)}` : "",
|
|
1395
|
-
...imagesLines(tree, b, routes.get(b.id), b.id === shapeFor, finders.get(b.id), !!(tuning && bookTuned(tuning.state, tuning.key, b.id, tuning.since).noSharper), waitsFor(b), hand),
|
|
1402
|
+
...imagesLines(tree, b, routes.get(b.id), b.id === shapeFor, finders.get(b.id), !!(tuning && bookTuned(tuning.state, tuning.key, b.id, tuning.since).noSharper), waitsFor(b), hand, saveAgainFor(b)),
|
|
1396
1403
|
...tunedBookLines(tuning, b, routes.get(b.id), opts.shared),
|
|
1397
1404
|
].filter(Boolean).join("\n");
|
|
1398
1405
|
}),
|
package/dist/cli/execute.js
CHANGED
|
@@ -95,6 +95,11 @@ export function resolveCommand(argv) {
|
|
|
95
95
|
if (found && leftover.length === 0) {
|
|
96
96
|
if (found.def.path.length === 0 && extra.length && rest[0] !== "--")
|
|
97
97
|
throw unknownCommand(extra.slice(0, 2));
|
|
98
|
+
// a group that is a command of its own too (strom history) and takes no argument: a word after it is a subcommand
|
|
99
|
+
// it does not have (strom history read) — the near ones said, never "unexpected argument"
|
|
100
|
+
const next = rest[0];
|
|
101
|
+
if (found.def.path.length && !found.def.args?.length && next !== undefined && !next.startsWith("-") && subcommandsOf(found.def.path, true).length)
|
|
102
|
+
throw unknownCommand([...found.def.path, next], undefined, true);
|
|
98
103
|
return { def: found.def, rest };
|
|
99
104
|
}
|
|
100
105
|
// A group ("person") with a wrong or missing subcommand.
|
|
@@ -128,17 +133,22 @@ export class GroupOnly extends Error {
|
|
|
128
133
|
}
|
|
129
134
|
/**
|
|
130
135
|
* An unknown command, said as typed (`said`: another name of a group — strom book … — when `words` name the group it
|
|
131
|
-
* stands for) with the commands near it; a group's ID after it (strom book B1) offers the group's show
|
|
136
|
+
* stands for) with the commands near it; a group's ID after it (strom book B1) offers the group's show; `hidden`: the
|
|
137
|
+
* group's commands behind a gate are near ones too (a group that is a command of its own: strom history read).
|
|
132
138
|
*/
|
|
133
|
-
function unknownCommand(words, said = words) {
|
|
139
|
+
function unknownCommand(words, said = words, hidden = false) {
|
|
134
140
|
const typed = said.join(" ");
|
|
135
141
|
const all = commands().filter((c) => c.path.length > 0).map((c) => c.path.join(" "));
|
|
136
|
-
// A known group narrows the choice ("person ad" → "person add", not "lesson add")
|
|
137
|
-
|
|
142
|
+
// A known group narrows the choice ("person ad" → "person add", not "lesson add"); `hidden`: a group that is a
|
|
143
|
+
// command too (strom history), its commands behind a gate among them, as they run when named
|
|
144
|
+
const inGroup = hidden ? subcommandsOf([words[0]], true).map((c) => c.path.join(" ")) : all.filter((c) => c.startsWith(`${words[0]} `));
|
|
138
145
|
const same = (inGroup.length ? inGroup : all).filter((c) => c.split(" ").length === words.length);
|
|
139
146
|
const hits = suggest(words.join(" "), same.length ? same : all);
|
|
147
|
+
// another word for a command of the group (strom task view → task show, strom history read → history show · list),
|
|
148
|
+
// before the commands a few letters away (read is no redo)
|
|
149
|
+
const synonyms = words.length === 2 ? (SUBCOMMAND_WORDS[words[1].toLowerCase()] ?? []).map((w) => `${words[0]} ${w}`).filter((c) => inGroup.includes(c)) : [];
|
|
140
150
|
const show = !hits.length && words.length === 2 && /^\p{Lu}\p{N}+$/u.test(words[1]) && inGroup.includes(`${words[0]} show`) ? `${said[0]} show ${said[1]}` : undefined;
|
|
141
|
-
const more = show ? [show] : hits.length ? hits : suggest(words[0] ?? "", [...new Set(all.map((c) => c.split(" ")[0]))]);
|
|
151
|
+
const more = show ? [show] : synonyms.length ? synonyms : hits.length ? hits : suggest(words[0] ?? "", [...new Set(all.map((c) => c.split(" ")[0]))]);
|
|
142
152
|
// in the words typed: the group's other name kept (strom book show, not strom recordset show)
|
|
143
153
|
const asTyped = (c) => (said[0] !== words[0] && c.split(" ")[0] === words[0] ? [said[0], ...c.split(" ").slice(1)].join(" ") : c);
|
|
144
154
|
const near = more.map((c) => `strom ${asTyped(c)}`).join(" · ");
|
|
@@ -147,6 +157,25 @@ function unknownCommand(words, said = words) {
|
|
|
147
157
|
...(more.length ? { code: "command.near", params: { cmd: typed, near } } : { code: "command.unknown", params: { cmd: typed } }),
|
|
148
158
|
});
|
|
149
159
|
}
|
|
160
|
+
/** Other words agents type for a command of a group: the commands they mean, those the group has said. */
|
|
161
|
+
const SUBCOMMAND_WORDS = {
|
|
162
|
+
view: ["show", "list"],
|
|
163
|
+
get: ["show", "list"],
|
|
164
|
+
read: ["show", "list"],
|
|
165
|
+
display: ["show", "list"],
|
|
166
|
+
open: ["show"],
|
|
167
|
+
print: ["show", "list"],
|
|
168
|
+
info: ["show"],
|
|
169
|
+
detail: ["show"],
|
|
170
|
+
details: ["show"],
|
|
171
|
+
ls: ["list"],
|
|
172
|
+
all: ["list"],
|
|
173
|
+
new: ["add"],
|
|
174
|
+
create: ["add"],
|
|
175
|
+
update: ["edit"],
|
|
176
|
+
change: ["edit"],
|
|
177
|
+
modify: ["edit"],
|
|
178
|
+
};
|
|
150
179
|
/** One option as the usage under a mistake says it: --name <value>, "…" when repeatable, its limit. */
|
|
151
180
|
function optionWord(o) {
|
|
152
181
|
const value = o.type === "boolean" ? "" : ` ${o.value ?? "<value>"}`;
|
|
@@ -325,10 +354,12 @@ export function parseOptions(def, rest, program = "strom") {
|
|
|
325
354
|
code: "option.unknown", hintCode: "option.unknown.status", params: { opt, cmd, options: own.join(" "), path: def.path.join(" ") }, usage,
|
|
326
355
|
});
|
|
327
356
|
// a name agents type meaning another option (--timeout for --minutes): that one, with what it takes
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
357
|
+
// (several of them: each, what it takes and is — strom search add --about: its task, the surnames looked for)
|
|
358
|
+
const meant = optionsOf(def).filter((o) => o.mistaken?.includes(opt.replace(/^-+/u, "")));
|
|
359
|
+
if (meant.length) {
|
|
360
|
+
const word = (o) => `--${o.name}${o.value ? ` ${o.value}` : ""}`;
|
|
361
|
+
const near = meant.map(word).join(" · ");
|
|
362
|
+
throw new UsageError(`unknown option ${opt} for ${cmd}`, { hint: `meant: ${meant.map((o) => `${word(o)} — ${o.description}`).join(" · ")}`, code: "option.near", params: { opt, cmd, near }, usage });
|
|
332
363
|
}
|
|
333
364
|
const near = suggest(opt, optionsOf(def).filter((o) => !o.hidden).map((o) => `--${o.name}`));
|
|
334
365
|
const help = `strom help${def.path.length ? ` ${def.path.join(" ")}` : ""}`;
|
package/dist/cli/registry.js
CHANGED
|
@@ -74,9 +74,9 @@ export function match(words) {
|
|
|
74
74
|
}
|
|
75
75
|
return best;
|
|
76
76
|
}
|
|
77
|
-
/** Command groups ("person") that have subcommands but no command of their own. */
|
|
78
|
-
export function subcommandsOf(prefix) {
|
|
79
|
-
return registry.filter((c) => !c.hidden && c.path.length > prefix.length && prefix.every((w, i) => c.path[i] === w));
|
|
77
|
+
/** Command groups ("person") that have subcommands but no command of their own; `hidden`: those behind a gate too. */
|
|
78
|
+
export function subcommandsOf(prefix, hidden = false) {
|
|
79
|
+
return registry.filter((c) => (hidden || !c.hidden) && c.path.length > prefix.length && prefix.every((w, i) => c.path[i] === w));
|
|
80
80
|
}
|
|
81
81
|
/** An alias's words that begin with these (a group of aliases only: "lesson" has "lesson show" among them). */
|
|
82
82
|
export function aliasExtends(prefix) {
|
|
@@ -288,14 +288,14 @@ register({
|
|
|
288
288
|
options: [
|
|
289
289
|
{ name: "recordset", type: "string", multiple: true, value: "<B…>", description: "where (repeatable)", aliases: ["where"] },
|
|
290
290
|
{ name: "years", type: "string", value: "<from-to>", description: "years covered" },
|
|
291
|
-
{ name: "surname", type: "string", multiple: true, value: "<name>", description: "surnames looked for (repeatable)", aliases: ["surnames"] },
|
|
291
|
+
{ name: "surname", type: "string", multiple: true, value: "<name>", description: "surnames looked for (repeatable)", aliases: ["surnames"], mistaken: ["about"] },
|
|
292
292
|
{ name: "place", type: "string", multiple: true, value: "<name>", description: "places covered (repeatable)" },
|
|
293
293
|
{ name: "pages", type: "string", value: "<range>", description: "images/pages covered, e.g. 95-100" },
|
|
294
294
|
{ name: "method", type: "string", value: "<m>", description: SEARCH_METHODS.join(", ") },
|
|
295
295
|
{ name: "result", type: "string", value: "<r>", description: SEARCH_RESULTS.join(", ") },
|
|
296
296
|
{ name: "found", type: "string", multiple: true, value: "<S…>", description: "sources found (repeatable; required with --result found)" },
|
|
297
|
-
{ name: "task", type: "string", value: "<T…>", description: "task this search served (default: the task of the open session)" },
|
|
298
|
-
{ name: "by", type: "string", value: "<who>", description: "main (default), reader, user" },
|
|
297
|
+
{ name: "task", type: "string", value: "<T…>", description: "task this search served (default: the task of the open session) — the people it is about are the task's", mistaken: ["about"] },
|
|
298
|
+
{ name: "by", type: "string", value: "<who>", description: "main (default; agent is the same), reader, user" },
|
|
299
299
|
{ name: "note", type: "string", value: "<text>", description: "what was illegible, what is left" },
|
|
300
300
|
],
|
|
301
301
|
examples: [
|
|
@@ -331,7 +331,8 @@ register({
|
|
|
331
331
|
result,
|
|
332
332
|
findings,
|
|
333
333
|
task,
|
|
334
|
-
|
|
334
|
+
// "agent": the agent of the session, the main one (what agents type for it)
|
|
335
|
+
by: opts.by === undefined || (typeof opts.by === "string" && foldText(opts.by) === "agent") ? "main" : oneOf(opts.by, ["main", "reader", "user"], "by"),
|
|
335
336
|
note: opts.note,
|
|
336
337
|
}, (id) => `+${id} search [${result}] "${truncate(args[0], 50)}"`, [...recordsets, ...findings]);
|
|
337
338
|
return { text: lines(written(tree), ...said), data: { search: s } };
|
|
@@ -2998,10 +2998,18 @@ async function takeOver(ctx, c, result) {
|
|
|
2998
2998
|
const pagePlans = all.filter((p) => p.pages?.length);
|
|
2999
2999
|
const pagesHere = got.some((g) => g.page) || pagePlans.some((p) => p.pages.some((pg) => findDownload(dir, pg.file).file));
|
|
3000
3000
|
const imagesHere = all.some((p) => p.items.some((i) => findDownload(dir, i.file).file));
|
|
3001
|
+
// the script's line names images and no page: it was a script of images — what it saved (or not) is said of them,
|
|
3002
|
+
// never "no page taken over" of a page plan lying there
|
|
3003
|
+
const imagesSaid = got.some((g) => !g.page) && !got.some((g) => g.page);
|
|
3004
|
+
// a page plan whose script is over (it refuses to run past its time) and whose page never came holds nothing back
|
|
3005
|
+
const now = Date.now();
|
|
3006
|
+
const livePages = pagePlans.filter((p) => now <= p.until + PLAN_TTL_MS || p.pages.some((pg) => findDownload(dir, pg.file).file));
|
|
3007
|
+
const imagePlans = all.some((p) => p.items.length);
|
|
3008
|
+
const toPages = pagePlans.length > 0 && !imagesSaid && (pagesHere || (!imagesHere && (livePages.length > 0 || !imagePlans)));
|
|
3001
3009
|
// a plan made before (another strom, the terms since known): taken over only as the archive's terms let it now (D12)
|
|
3002
3010
|
if (all.length && !tree.dryRun)
|
|
3003
|
-
await gateArchive(ctx, c, { activity:
|
|
3004
|
-
if (
|
|
3011
|
+
await gateArchive(ctx, c, { activity: toPages ? "catalogue" : "images", route: "browser", ask: false });
|
|
3012
|
+
if (toPages && !tree.dryRun)
|
|
3005
3013
|
return takePages(ctx, c, pagePlans, result);
|
|
3006
3014
|
const plans = all.filter((p) => p.items.length);
|
|
3007
3015
|
if (!plans.length)
|
|
@@ -3099,7 +3107,7 @@ async function takeOver(ctx, c, result) {
|
|
|
3099
3107
|
text: lines(taken.length
|
|
3100
3108
|
? `${counted(taken.length, "image")} taken over from ${ctx.display(dir)}${added.length ? `: registered ${added.map((a) => a.id).join(" ")}` : ""}${inboxed.length ? ` into the inbox: ${[...new Set(inboxed)].join(", ")}/ — register them: strom media add --inbox ${shellArg(inboxed[0])} --recordset B…` : ""}`
|
|
3101
3109
|
: `nothing taken over from ${ctx.display(dir)}`, again.length ? ` already registered: ${again.join(" ")}` : undefined, woken.length ? ` back in the queue (they waited for these images): ${woken.join(" ")}` : undefined, ...notes.map((n) => ` ⚠ ${n}`), lost.length
|
|
3102
|
-
? ` images ${nums(lost)}: the browser fetched them but saved nothing here — Chrome lets a site download one file until the user allows automatic downloads for it (at the right end of the address bar), or it asks where to save each file (Settings → Downloads). Then plan them again: strom fetch ${c.name} ${lost[0].plan.book} --images ${nums(lost)}${lost[0].plan.recordset ? ` --recordset ${lost[0].plan.recordset}` : ""}`
|
|
3110
|
+
? ` images ${nums(lost)}: the browser fetched them but saved nothing here — Chrome lets a site download one file until the user allows automatic downloads for it (at the right end of the address bar), or it asks where to save each file (Settings → Downloads) — in the browser profile your browser tool works in (a permission given in another profile does not count). Tell the user exactly that: it is the person's to allow, never change the browser's settings yourself, and running the take again brings nothing. Then plan them again: strom fetch ${c.name} ${lost[0].plan.book} --images ${nums(lost)}${lost[0].plan.recordset ? ` --recordset ${lost[0].plan.recordset}` : ""}`
|
|
3103
3111
|
: undefined, notYet.length ? ` still waiting for images ${nums(notYet)}${notYet.some((m) => m.unfinished) ? " (a download is still running)" : ""} — run the script of their plan, or they went elsewhere: strom config set browser.downloads <folder>` : undefined),
|
|
3104
3112
|
data: { taken: taken.map((t) => ({ n: t.item.n, file: t.file })), added, again, woken, inbox: [...new Set(inboxed)], missing: missing.map((m) => m.item.n), notes },
|
|
3105
3113
|
...(!taken.length && missing.length ? { exitCode: 1 } : {}),
|
package/dist/commands/grep.js
CHANGED
|
@@ -102,7 +102,9 @@ register({
|
|
|
102
102
|
code: "grep.outside",
|
|
103
103
|
params: { where: outside },
|
|
104
104
|
});
|
|
105
|
-
const { targets, error, code, params } = grepTargets(tree.root, wanted);
|
|
105
|
+
const { targets, error, code, params, prefixed } = grepTargets(tree.root, wanted);
|
|
106
|
+
// a path no file has, the start of the names of files beside it: those files, said
|
|
107
|
+
const starts = (prefixed ?? []).map((p) => `--in ${p.where}: no such file — the files beginning so: ${p.names.join(", ")}`);
|
|
106
108
|
if (error)
|
|
107
109
|
throw new UsageError(error, { ...(code ? { code, params } : {}), hint: `strom grep ${patterns.map(shellArg).join(" ")} --in ${GREP_FOLDERS.join("|")}|all` });
|
|
108
110
|
let match;
|
|
@@ -126,7 +128,7 @@ register({
|
|
|
126
128
|
const tooBig = found.tooBig.length ? `left out, over 64 MB: ${found.tooBig.join(", ")}` : undefined;
|
|
127
129
|
if (!found.hits.length)
|
|
128
130
|
return {
|
|
129
|
-
text: lines(`not found in ${counted(found.searched, "text file")} of ${where}`, tooBig, cut, "→ the records: strom find <text>"),
|
|
131
|
+
text: lines(...starts, `not found in ${counted(found.searched, "text file")} of ${where}`, tooBig, cut, "→ the records: strom find <text>"),
|
|
130
132
|
data: { total: 0, searched: found.searched, hits: [], ...(found.tooBig.length ? { tooBig: found.tooBig } : {}) },
|
|
131
133
|
};
|
|
132
134
|
const total = `${found.hits.length}${found.capped ? "+" : ""}`;
|
|
@@ -137,13 +139,13 @@ register({
|
|
|
137
139
|
const files = [...found.counts].map(([file, n]) => ({ file, lines: n }));
|
|
138
140
|
const page = paginate(files, ctx.limit, ctx.page);
|
|
139
141
|
return {
|
|
140
|
-
text: lines(head + ":", ...page.items.map((f) => `${f.file}: ${f.lines}`), moreLine(page, again) || undefined, tooBig),
|
|
142
|
+
text: lines(...starts, head + ":", ...page.items.map((f) => `${f.file}: ${f.lines}`), moreLine(page, again) || undefined, tooBig),
|
|
141
143
|
data: { total: found.hits.length, capped: found.capped, searched: found.searched, files: page.items, ...(found.tooBig.length ? { tooBig: found.tooBig } : {}) },
|
|
142
144
|
};
|
|
143
145
|
}
|
|
144
146
|
const page = paginate(found.hits, ctx.limit, ctx.page);
|
|
145
147
|
return {
|
|
146
|
-
text: lines(head + ":", ...grepLines(page.items), moreLine(page, again) || undefined, tooBig, cut),
|
|
148
|
+
text: lines(...starts, head + ":", ...grepLines(page.items), moreLine(page, again) || undefined, tooBig, cut),
|
|
147
149
|
data: { total: found.hits.length, capped: found.capped, searched: found.searched, files: found.counts.size, hits: page.items, ...(found.tooBig.length ? { tooBig: found.tooBig } : {}) },
|
|
148
150
|
};
|
|
149
151
|
},
|
package/dist/commands/history.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// ancestors lived through (the experiment experiments.history, core/pastevents.ts). Behind its gate (hidden): runs
|
|
4
4
|
// when named, shown nowhere until the Strom app shows the events. `strom history` alone stays what changed recently.
|
|
5
5
|
import { register } from "../cli/registry.js";
|
|
6
|
-
import { lines, table } from "../cli/format.js";
|
|
6
|
+
import { lines, shellArg, table } from "../cli/format.js";
|
|
7
7
|
import { ui } from "../cli/ui.js";
|
|
8
8
|
import { StromError, UsageError } from "../core/errors.js";
|
|
9
9
|
import { listOpt, normId } from "../core/records.js";
|
|
@@ -260,7 +260,10 @@ register({
|
|
|
260
260
|
}
|
|
261
261
|
const links = listOpt(opts.region).map(regionLink);
|
|
262
262
|
if (!links.length)
|
|
263
|
-
throw new UsageError("--region <id>[:<from>-<to>] (or --unlocated)", {
|
|
263
|
+
throw new UsageError("--region <id>[:<from>-<to>] (or --unlocated)", {
|
|
264
|
+
code: "history.map",
|
|
265
|
+
hint: `strom history map ${shellArg(args[0])} --region <id>[:<from>-<to>] (once for each region it belonged to; the regions: strom history status) — or --unlocated --why "…"`,
|
|
266
|
+
});
|
|
264
267
|
const sh = shared(ctx);
|
|
265
268
|
const missing = [...new Set(links.map((l) => l.id))].filter((id) => !readCatalog(sh, id));
|
|
266
269
|
const name = texts(opts, "name");
|
package/dist/commands/media.js
CHANGED
|
@@ -30,11 +30,11 @@ import { makeThumb, THUMB_SIZES } from "../core/thumbs.js";
|
|
|
30
30
|
import { batchFull, batchPath, batchRoom, noteBatch, openBatch } from "../core/batches.js";
|
|
31
31
|
import { readEntry, readZip } from "../core/zip.js";
|
|
32
32
|
import { fileBy, handFiles, taskForFile, taskPeople } from "../core/taskfiles.js";
|
|
33
|
-
import { askedNow, folderFiles, handedImages, inboxState, inboxWaitOf, inboxWaits, numberFiles, numbersForTask, registeredImages, singleBook, unsettled } from "../core/inboxwait.js";
|
|
33
|
+
import { askedNow, folderFiles, handedImages, inboxState, inboxWaitOf, inboxWaits, numberFiles, numbersForTask, registeredImages, SETTLE_MS, singleBook, unsettled } from "../core/inboxwait.js";
|
|
34
34
|
import { formatOf } from "../image/index.js";
|
|
35
35
|
import { pdfScans } from "../image/pdf.js";
|
|
36
36
|
import { readableFile } from "../core/readable.js";
|
|
37
|
-
import { HELD_AFTER_MS, PLAN_TTL_MS, TAKEN_KEEP_MS, findDownload, loadSaves, noteSave, saveScript, storeSaves, waitFileBase } from "../core/browser.js";
|
|
37
|
+
import { HELD_AFTER_MS, PLAN_TTL_MS, TAKEN_KEEP_MS, findDownload, loadPlans, loadSaves, noteSave, saveScript, storeSaves, waitFileBase } from "../core/browser.js";
|
|
38
38
|
import { bookOn, browserGate, otherWay } from "../core/webgate.js";
|
|
39
39
|
import { allows } from "../core/terms.js";
|
|
40
40
|
import { phrase } from "../core/phrases.js";
|
|
@@ -130,10 +130,11 @@ export function wakeWaiting(tree, recordset, count, o = {}) {
|
|
|
130
130
|
};
|
|
131
131
|
if (count) {
|
|
132
132
|
const have = registeredImages(tree, recordset);
|
|
133
|
+
const pending = againPending(tree);
|
|
133
134
|
for (const t of tree.list("task").filter((t) => t.state === "waiting" && t.id !== o.except && wakes(t, recordset))) {
|
|
134
135
|
const want = t.awaits ? (parseImageList(t.awaits.images) ?? []) : [];
|
|
135
|
-
// a part of the images asked for: it waits on for the rest
|
|
136
|
-
if (want.some((n) => !have.has(n)))
|
|
136
|
+
// a part of the images asked for: it waits on for the rest (one saved once more: for its new copy)
|
|
137
|
+
if (want.some((n) => !have.has(n) || pending.has(`${t.id}:${n}`)))
|
|
137
138
|
continue;
|
|
138
139
|
// what it asked for, for the session that takes it up
|
|
139
140
|
const note = `${counted(count, "image")} of ${recordset} registered${t.awaits ? ` (it waited for images ${t.awaits.images})` : ""}`;
|
|
@@ -149,13 +150,26 @@ export function wakeWaiting(tree, recordset, count, o = {}) {
|
|
|
149
150
|
}
|
|
150
151
|
return woken;
|
|
151
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The images saved once more (strom media save --again) whose new copy was not taken yet, as "T0007:40": registered,
|
|
155
|
+
* yet what their task waits for.
|
|
156
|
+
*/
|
|
157
|
+
function againPending(tree) {
|
|
158
|
+
return new Set(loadSaves(tree.root).filter((r) => r.again && r.taken === undefined).map((r) => `${r.task}:${r.n}`));
|
|
159
|
+
}
|
|
152
160
|
/**
|
|
153
161
|
* What the person saved into the folders of tasks that wait (core/inboxwait.ts): each folder with files that settled
|
|
154
162
|
* taken whole — registered as images of its book, numbered by their names or their order, the files moved into the store
|
|
155
163
|
* — and the tasks it completes back in the queue. A folder that is not there yet is made (an older wait). Never a
|
|
156
164
|
* folder of no waiting task, never the inbox as a whole. `folder`: that one alone.
|
|
165
|
+
*
|
|
166
|
+
* Under the tree's lock from the first look at the folders to the last file registered: another strom taking them at
|
|
167
|
+
* the same moment (the bridge, the agent's own command) finds them taken — nothing to take, never a file gone under it.
|
|
157
168
|
*/
|
|
158
169
|
export function takeWaiting(tree, shared, o = {}) {
|
|
170
|
+
return tree.dryRun ? takeWaitingNow(tree, shared, o) : tree.withTreeLock(() => takeWaitingNow(tree, shared, o));
|
|
171
|
+
}
|
|
172
|
+
function takeWaitingNow(tree, shared, o) {
|
|
159
173
|
const out = [];
|
|
160
174
|
const byFolder = new Map();
|
|
161
175
|
if (o.downloads && !tree.dryRun)
|
|
@@ -193,12 +207,14 @@ export function takeWaiting(tree, shared, o = {}) {
|
|
|
193
207
|
}
|
|
194
208
|
const r = takeFiles(tree, shared, w, files, numbered.numbers);
|
|
195
209
|
const after = registeredImages(tree, w.recordset);
|
|
210
|
+
const pending = againPending(tree);
|
|
196
211
|
out.push({
|
|
197
212
|
...base,
|
|
198
213
|
added: r.added.map((m) => m.image).filter((n) => n !== undefined),
|
|
199
214
|
...(numbered.by === "order" ? { byOrder: true } : {}),
|
|
200
215
|
woken: r.woken,
|
|
201
|
-
missing: (asked ?? []).filter((n) => !after.has(n)),
|
|
216
|
+
missing: (asked ?? []).filter((n) => !after.has(n) || ws.some((x) => pending.has(`${x.task}:${n}`))),
|
|
217
|
+
...(r.copies.length ? { copies: r.copies } : {}),
|
|
202
218
|
});
|
|
203
219
|
}
|
|
204
220
|
return out;
|
|
@@ -292,6 +308,81 @@ function fromDownloads(tree, shared, downloads, waits) {
|
|
|
292
308
|
}
|
|
293
309
|
}
|
|
294
310
|
}
|
|
311
|
+
/** A browser's download not finished yet: Chrome's .crdownload, Firefox's .part, Safari's .download, a .tmp. */
|
|
312
|
+
const DOWNLOADING = /\.(crdownload|part|download|tmp)$/iu;
|
|
313
|
+
/**
|
|
314
|
+
* strom's own files of the images waiting tasks wait for (strom media save's names, this research's mark first, or
|
|
315
|
+
* the name a record of this research gives) that the browser is still writing: a download not finished (.crdownload,
|
|
316
|
+
* .part, …) or a file written a moment ago (not settled). fromDownloads leaves them for the next look.
|
|
317
|
+
*/
|
|
318
|
+
export function downloadsBeingWritten(tree, downloads, now = Date.now()) {
|
|
319
|
+
let names;
|
|
320
|
+
try {
|
|
321
|
+
names = fs.readdirSync(downloads);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
return [];
|
|
325
|
+
}
|
|
326
|
+
const esc = (x) => x.normalize("NFC").replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
327
|
+
const tail = `(?: \\(\\p{Nd}+\\))?\\.[\\p{L}\\p{N}]{2,5}(?:\\.(?:crdownload|part|download|tmp))?$`;
|
|
328
|
+
const saves = loadSaves(tree.root);
|
|
329
|
+
const out = [];
|
|
330
|
+
// gone since the folder was read (renamed by the browser as it finished): not there
|
|
331
|
+
const mtime = (name) => {
|
|
332
|
+
try {
|
|
333
|
+
return fs.statSync(path.join(downloads, name)).mtimeMs;
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
for (const w of inboxWaits(tree)) {
|
|
340
|
+
if (w.by !== "images")
|
|
341
|
+
continue;
|
|
342
|
+
const base = waitFileBase(tree.config.id, w.task, 0).slice(0, -4);
|
|
343
|
+
const re = new RegExp(`^${esc(base)}(\\p{Nd}{4,})${tail}`, "u");
|
|
344
|
+
const given = saves.filter((r) => r.task === w.task && !r.file.normalize("NFC").startsWith(base.normalize("NFC"))).map((r) => ({ n: r.n, re: new RegExp(`^${esc(r.file)}${tail}`, "u") }));
|
|
345
|
+
const byNumber = new Map();
|
|
346
|
+
for (const name of names) {
|
|
347
|
+
const nfc = name.normalize("NFC");
|
|
348
|
+
const m = re.exec(nfc);
|
|
349
|
+
const n = m ? Number(m[1]) : given.find((g) => g.re.test(nfc))?.n;
|
|
350
|
+
if (n === undefined || (w.want?.length && !w.want.includes(n)))
|
|
351
|
+
continue;
|
|
352
|
+
const at = mtime(name);
|
|
353
|
+
if (at === undefined)
|
|
354
|
+
continue;
|
|
355
|
+
byNumber.set(n, [...(byNumber.get(n) ?? []), { name, at, partial: DOWNLOADING.test(nfc) }]);
|
|
356
|
+
}
|
|
357
|
+
for (const [n, files] of byNumber) {
|
|
358
|
+
// a finished file of it that settled: it is there — a partial one beside it is not waited for
|
|
359
|
+
if (files.some((f) => !f.partial && now - f.at >= SETTLE_MS))
|
|
360
|
+
continue;
|
|
361
|
+
// a download that has not grown for a long while: stopped, not being written
|
|
362
|
+
const busy = files.filter((f) => (f.partial ? now - f.at < STALLED_MS : now - f.at < SETTLE_MS));
|
|
363
|
+
if (busy.length)
|
|
364
|
+
out.push({ task: w.task, n, name: busy[0].name });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
/** A download not written to for this long has stopped (a browser's failed or paused download): not waited for. */
|
|
370
|
+
const STALLED_MS = 60_000;
|
|
371
|
+
/**
|
|
372
|
+
* Waits a moment (at most STROM_DOWNLOAD_WAIT_MS, else a few seconds: what a browser takes to finish a scan and the
|
|
373
|
+
* file to settle) while strom's own files of waiting tasks are still being written in the downloads folder — only for
|
|
374
|
+
* them, nothing else. Those still being written after it: said, for the next look.
|
|
375
|
+
*/
|
|
376
|
+
function waitForDownloads(tree, downloads, env) {
|
|
377
|
+
const most = Number(env.STROM_DOWNLOAD_WAIT_MS ?? SETTLE_MS + 5_000);
|
|
378
|
+
const until = Date.now() + (Number.isFinite(most) && most >= 0 ? most : SETTLE_MS + 5_000);
|
|
379
|
+
for (;;) {
|
|
380
|
+
const writing = downloadsBeingWritten(tree, downloads);
|
|
381
|
+
if (!writing.length || Date.now() >= until)
|
|
382
|
+
return writing;
|
|
383
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.min(250, Math.max(1, until - Date.now())));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
295
386
|
/**
|
|
296
387
|
* Files of a task's folder of the shared inbox, numbered: registered as images of its book (the tasks they complete back in
|
|
297
388
|
* the queue, but `except`), the files moved into the store, the folder gone once nobody waits on it. What takes the
|
|
@@ -300,9 +391,11 @@ function fromDownloads(tree, shared, downloads, waits) {
|
|
|
300
391
|
function takeFiles(tree, shared, w, files, numbers, o = {}) {
|
|
301
392
|
const book = tree.get(w.recordset);
|
|
302
393
|
const items = files.map((file, i) => ({ file, image: numbers[i], url: book?.url, from: o.from?.[i] ?? path.basename(file) }));
|
|
303
|
-
const r = registerImages(tree, shared, items, w.recordset,
|
|
304
|
-
|
|
305
|
-
|
|
394
|
+
const r = registerImages(tree, shared, items, w.recordset, { wake: false });
|
|
395
|
+
// an image saved once more (strom media save --again) came: its new copy, or the same scan again (nothing sharper
|
|
396
|
+
// to have) — what its task waited for either way
|
|
397
|
+
const settled = settleAgain(tree, w.recordset, numbers);
|
|
398
|
+
r.woken.push(...wakeWaiting(tree, w.recordset, r.added.length || (settled ? r.again.length : 0), o.except ? { except: o.except } : {}));
|
|
306
399
|
if (!tree.dryRun) {
|
|
307
400
|
for (const f of files)
|
|
308
401
|
fs.rmSync(f, { force: true }); // now in the store
|
|
@@ -314,6 +407,24 @@ function takeFiles(tree, shared, w, files, numbers, o = {}) {
|
|
|
314
407
|
}
|
|
315
408
|
return r;
|
|
316
409
|
}
|
|
410
|
+
/** The saves once more (strom media save --again) of these images of a book: taken now. How many. */
|
|
411
|
+
function settleAgain(tree, recordset, numbers) {
|
|
412
|
+
if (tree.dryRun)
|
|
413
|
+
return 0;
|
|
414
|
+
const saves = loadSaves(tree.root);
|
|
415
|
+
const now = Date.now();
|
|
416
|
+
let n = 0;
|
|
417
|
+
const next = saves.map((r) => {
|
|
418
|
+
if (!r.again || r.taken !== undefined || r.recordset !== recordset || !numbers.includes(r.n))
|
|
419
|
+
return r;
|
|
420
|
+
n++;
|
|
421
|
+
const { held: _h, ...was } = r;
|
|
422
|
+
return { ...was, taken: now };
|
|
423
|
+
});
|
|
424
|
+
if (n)
|
|
425
|
+
storeSaves(tree.root, next);
|
|
426
|
+
return n;
|
|
427
|
+
}
|
|
317
428
|
/** The pictures of a file sent for a task: an image as it is, a PDF page by page (its scans as they are, else made). */
|
|
318
429
|
function picturesOf(tree, env, file, name, tmp) {
|
|
319
430
|
const fd = fs.openSync(file, "r");
|
|
@@ -474,11 +585,12 @@ function stillWaiting(tree, recordset) {
|
|
|
474
585
|
if (!recordset)
|
|
475
586
|
return [];
|
|
476
587
|
const have = registeredImages(tree, recordset);
|
|
588
|
+
const pending = againPending(tree);
|
|
477
589
|
return tree
|
|
478
590
|
.list("task")
|
|
479
591
|
.filter((t) => t.state === "waiting" && t.awaits?.recordset === recordset)
|
|
480
592
|
.map((t) => {
|
|
481
|
-
const missing = (parseImageList(t.awaits.images) ?? []).filter((n) => !have.has(n));
|
|
593
|
+
const missing = (parseImageList(t.awaits.images) ?? []).filter((n) => !have.has(n) || pending.has(`${t.id}:${n}`));
|
|
482
594
|
return `${t.id} still waits for images ${runs(missing)} of ${recordset} (it asked for ${t.awaits.images}) — it comes back once they are there`;
|
|
483
595
|
});
|
|
484
596
|
}
|
|
@@ -501,7 +613,8 @@ export function heldSaves(tree, shared, downloads, now = Date.now()) {
|
|
|
501
613
|
keep.push(r);
|
|
502
614
|
continue;
|
|
503
615
|
}
|
|
504
|
-
|
|
616
|
+
// registered (but one saved once more: its new copy is what is waited for)
|
|
617
|
+
if (!r.again && registeredImages(tree, r.recordset).has(r.n)) {
|
|
505
618
|
const { held: _h, ...was } = r;
|
|
506
619
|
keep.push({ ...was, taken: now });
|
|
507
620
|
continue;
|
|
@@ -542,7 +655,8 @@ export function heldSaves(tree, shared, downloads, now = Date.now()) {
|
|
|
542
655
|
* written waits for the next look. Never a file strom did not name, never one of an image not registered.
|
|
543
656
|
*/
|
|
544
657
|
export function tidyDownloads(tree, downloads, now = Date.now()) {
|
|
545
|
-
|
|
658
|
+
// registered — but never the file of one saved once more and not taken yet (strom media save --again): its new copy
|
|
659
|
+
const done = loadSaves(tree.root).filter((r) => !(r.again && r.taken === undefined) && registeredImages(tree, r.recordset).has(r.n));
|
|
546
660
|
if (!done.length)
|
|
547
661
|
return [];
|
|
548
662
|
let names;
|
|
@@ -611,16 +725,16 @@ function heldLine(ctx, h, downloads) {
|
|
|
611
725
|
}
|
|
612
726
|
/** What was taken of the folders, a line each (strom media add --inbox --waiting, a session's start). */
|
|
613
727
|
export function takenLines(taken) {
|
|
614
|
-
return taken.
|
|
728
|
+
return taken.flatMap((t) => {
|
|
615
729
|
const who = t.tasks.join(" ");
|
|
616
730
|
if (t.settling)
|
|
617
731
|
return `${t.folder}/: ${counted(t.settling, "file")} still being written — taken on the next look (${who})`;
|
|
618
732
|
if (t.problem)
|
|
619
733
|
return `${t.folder}/: nothing taken — ${t.problem} (${who})`;
|
|
620
|
-
return [
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
734
|
+
return [[
|
|
735
|
+
`${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)"}`,
|
|
736
|
+
t.woken.length ? ` — back in the queue: ${t.woken.join(" ")}` : t.missing.length ? ` — ${who} still waits${t.missing.length ? ` for images ${runs(t.missing)}` : ""}` : "",
|
|
737
|
+
].join("")].concat((t.copies ?? []).map((c) => ` ${c}`));
|
|
624
738
|
});
|
|
625
739
|
}
|
|
626
740
|
function sharedDir(ctx) {
|
|
@@ -632,6 +746,39 @@ function pageLabel(tree, m) {
|
|
|
632
746
|
const b = m.recordset && m.image !== undefined ? tree.get(m.recordset) : undefined;
|
|
633
747
|
return (b && pageOf(b, m.image)) ?? "";
|
|
634
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* Image n of a book not registered, that a task waits for: said with how it comes and the exact next step — through the
|
|
751
|
+
* agent's browser (strom media save gave its script: once the browser saved it, strom media add --inbox --waiting;
|
|
752
|
+
* the script not run or over: strom media save again), through a connector's browser plan (its take), else the
|
|
753
|
+
* person's hand. No task waits for it: undefined (said as not registered).
|
|
754
|
+
*/
|
|
755
|
+
export function notYetRegistered(tree, recordset, n) {
|
|
756
|
+
const t = tree
|
|
757
|
+
.list("task")
|
|
758
|
+
.find((x) => x.state === "waiting" && x.awaits?.recordset === recordset && (parseImageList(x.awaits.images) ?? []).includes(n));
|
|
759
|
+
const plan = loadPlans(tree.root).find((p) => p.recordset === recordset && p.items.some((i) => i.n === n));
|
|
760
|
+
if (!t && !plan)
|
|
761
|
+
return undefined;
|
|
762
|
+
const then = "strom media add --inbox --waiting";
|
|
763
|
+
const save = t ? loadSaves(tree.root).find((r) => r.task === t.id && r.recordset === recordset && r.n === n && r.taken === undefined) : undefined;
|
|
764
|
+
if (t && save) {
|
|
765
|
+
const since = new Date(save.at).toTimeString().slice(0, 8);
|
|
766
|
+
const again = `strom media save ${t.id} --image ${n} --recordset ${recordset} --at ${save.url}`;
|
|
767
|
+
return {
|
|
768
|
+
message: `image ${n} of ${recordset} is not registered yet: ${t.id} waits for it through your browser (strom media save gave its script at ${since})${save.held ? ` — the browser held its file back: the person allows ${save.host} to download several files, in the browser profile your browser tool works in` : ""}`,
|
|
769
|
+
hint: `once the browser saved it: ${then} takes it and says whether it came (never look into the downloads folder yourself); the script not run yet, or over: ${again}, its script in that tab, then ${then}`,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
if (plan)
|
|
773
|
+
return {
|
|
774
|
+
message: `image ${n} of ${recordset} is not registered yet: a browser plan of connector ${plan.connector} has it${t ? ` (${t.id} waits for it)` : ""}`,
|
|
775
|
+
hint: `run the script of its plan in your browser's tab, then strom fetch ${plan.connector} --take --result "<the line it returned>"; the plan over: strom fetch ${plan.connector} ${plan.book} --images ${n} --recordset ${recordset}`,
|
|
776
|
+
};
|
|
777
|
+
return {
|
|
778
|
+
message: `image ${n} of ${recordset} is not registered yet: ${t.id} waits for it${t.waitingOn ? ` (${truncate(t.waitingOn, 160)})` : ""}`,
|
|
779
|
+
hint: `${then} takes it once it is in the task's folder (strom task show ${t.id} names it); meanwhile other work`,
|
|
780
|
+
};
|
|
781
|
+
}
|
|
635
782
|
/** "M0012", "B0001:57", "I0002" — or a record set with --image / --page. */
|
|
636
783
|
function resolveTarget(tree, shared, ref, opts) {
|
|
637
784
|
const at = /^([Bb]\d+):(\d+)$/.exec(ref.trim());
|
|
@@ -647,7 +794,7 @@ function resolveTarget(tree, shared, ref, opts) {
|
|
|
647
794
|
throw new UsageError("which image?", { hint: `${b.id}:57, or --image 57, or --page 112` });
|
|
648
795
|
const m = imageOfRef(tree.list("media"), b.id, image);
|
|
649
796
|
if (!m)
|
|
650
|
-
throw
|
|
797
|
+
throw notRegistered(tree, b.id, image);
|
|
651
798
|
return { key: m.id, file: path.join(shared, m.file), media: m };
|
|
652
799
|
}
|
|
653
800
|
// a page of a document the user gave: I0002:3
|
|
@@ -997,7 +1144,7 @@ function resolveTargets(tree, shared, all, args, opts, parts, maxViews = VIEW_MA
|
|
|
997
1144
|
const m = parts.length > 1 && (opts.crop !== undefined || opts.half !== undefined || opts.split !== undefined) ? findImage(all, w.b.id, image) : imageOfRef(all, w.b.id, image);
|
|
998
1145
|
if (!m) {
|
|
999
1146
|
if (wants.length === 1 && !several)
|
|
1000
|
-
throw
|
|
1147
|
+
throw notRegistered(tree, w.b.id, image);
|
|
1001
1148
|
missing.push(`${w.b.id}:${image}`);
|
|
1002
1149
|
continue;
|
|
1003
1150
|
}
|
|
@@ -1014,10 +1161,25 @@ function resolveTargets(tree, shared, all, args, opts, parts, maxViews = VIEW_MA
|
|
|
1014
1161
|
}
|
|
1015
1162
|
if (!targets.length && !several) {
|
|
1016
1163
|
const b = missing[0].split(":")[0];
|
|
1017
|
-
throw new UsageError(`none of these images is registered: ${missing.join(", ")}`, { hint: `strom media list --recordset ${b} · strom media add <files> --recordset ${b}` });
|
|
1164
|
+
throw new UsageError(`none of these images is registered: ${missing.join(", ")}`, { hint: waitedLines(tree, missing).join("\n") || `strom media list --recordset ${b} · strom media add <files> --recordset ${b}` });
|
|
1018
1165
|
}
|
|
1019
1166
|
return { targets, missing };
|
|
1020
1167
|
}
|
|
1168
|
+
/** Image n of a book is not registered: why (a task waits for it: how it comes, the next step), else where to look. */
|
|
1169
|
+
function notRegistered(tree, recordset, n) {
|
|
1170
|
+
const w = notYetRegistered(tree, recordset, n);
|
|
1171
|
+
if (w)
|
|
1172
|
+
return new UsageError(w.message, { hint: w.hint });
|
|
1173
|
+
return new UsageError(`image ${n} of ${recordset} is not registered`, { hint: `strom media list --recordset ${recordset} · strom media add <files> --recordset ${recordset}` });
|
|
1174
|
+
}
|
|
1175
|
+
/** Of images not registered ("B0001:64"), those a task waits for: a line each, with its next step. */
|
|
1176
|
+
function waitedLines(tree, missing) {
|
|
1177
|
+
return missing.flatMap((ref) => {
|
|
1178
|
+
const m = /^(B\p{N}+):(\p{N}+)$/u.exec(ref);
|
|
1179
|
+
const w = m ? notYetRegistered(tree, m[1], Number(m[2])) : undefined;
|
|
1180
|
+
return w ? [`${w.message} — ${w.hint}`] : [];
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1021
1183
|
/**
|
|
1022
1184
|
* One view of one image: from a part fetched sharper where there is one; the clip of what it shows; the archive's
|
|
1023
1185
|
* sharper part — never of a book whose portal gave none sharper (`noSharper`: core/tune.ts, A5).
|
|
@@ -1160,6 +1322,8 @@ register({
|
|
|
1160
1322
|
throw new UsageError("--waiting takes the folders of the waiting tasks as they are: no folder, --recordset, --first or --image");
|
|
1161
1323
|
// what the agent's browser saved for them (strom media save) first goes into their folders
|
|
1162
1324
|
const downloads = ctx.settings.downloads();
|
|
1325
|
+
// a file the browser is still writing (a scan just saved): waited for a moment, then taken with the rest
|
|
1326
|
+
const writing = tree.dryRun ? [] : waitForDownloads(tree, downloads, ctx.env);
|
|
1163
1327
|
const taken = takeWaiting(tree, shared, { downloads });
|
|
1164
1328
|
const woken = taken.flatMap((t) => t.woken);
|
|
1165
1329
|
// what the agent's browser was to save and never saved: held back by the browser — said, to the person too
|
|
@@ -1170,14 +1334,18 @@ register({
|
|
|
1170
1334
|
const mine = currentSession(tree, ctx.env)?.task;
|
|
1171
1335
|
const waits = inboxWaits(tree).filter((x) => x.by === "images");
|
|
1172
1336
|
const saves = loadSaves(tree.root);
|
|
1337
|
+
const pending = againPending(tree);
|
|
1173
1338
|
const missingOf = (x) => {
|
|
1174
1339
|
const have = registeredImages(tree, x.recordset);
|
|
1175
|
-
return (x.want ?? []).filter((n) => !have.has(n));
|
|
1340
|
+
return (x.want ?? []).filter((n) => !have.has(n) || pending.has(`${x.task}:${n}`));
|
|
1176
1341
|
};
|
|
1177
1342
|
const own = waits.find((x) => x.task === mine);
|
|
1178
1343
|
const ownLines = [];
|
|
1179
|
-
|
|
1180
|
-
|
|
1344
|
+
// still being written after the wait: said, never as "nothing came"
|
|
1345
|
+
const writingLines = writing.map((d) => `image ${d.n} (${d.task}): its download is still being written in the downloads folder (${d.name}) — this command again in a few seconds takes it`);
|
|
1346
|
+
const missingNow = own ? missingOf(own).filter((n) => !writing.some((d) => d.task === own.task && d.n === n)) : [];
|
|
1347
|
+
if (own && missingNow.length) {
|
|
1348
|
+
const missing = missingNow;
|
|
1181
1349
|
const given = saves.filter((r) => r.task === own.task && r.taken === undefined && missing.includes(r.n) && !held.some((h) => h.task === r.task && h.n === r.n));
|
|
1182
1350
|
const last = given.length ? new Date(Math.max(...given.map((r) => r.at))).toTimeString().slice(0, 8) : undefined;
|
|
1183
1351
|
ownLines.push(`${own.task} (this session's task) still waits for image${missing.length > 1 ? "s" : ""} ${runs(missing)} of ${own.recordset}: nothing of ${missing.length > 1 ? "them" : "it"} came yet — not in the downloads folder, not in its folder ${ctx.display(path.join(shared, "inbox", own.folder))}${given.length ? ` (the script of ${runs(given.map((r) => r.n))} given at ${last}: the browser saves it within seconds — this command once more in a moment says whether it came)` : ""}. Never look into the downloads folder yourself.`);
|
|
@@ -1190,15 +1358,16 @@ register({
|
|
|
1190
1358
|
.map((x) => `${x.task} images ${runs(missingOf(x))} of ${x.recordset}${heldOthers.some((h) => h.task === x.task) ? ` (the browser held back ${runs(heldOthers.filter((h) => h.task === x.task).map((h) => h.n))})` : ""}`)
|
|
1191
1359
|
.join(", ")}`
|
|
1192
1360
|
: undefined;
|
|
1193
|
-
const nothing = !taken.length && !held.length && !ownLines.length && !side;
|
|
1361
|
+
const nothing = !taken.length && !held.length && !ownLines.length && !side && !writing.length;
|
|
1194
1362
|
return {
|
|
1195
|
-
text: lines(nothing ? (waits.length ? "nothing came: no file in the downloads folder or the folders of the waiting tasks" : "no task waits for images saved into the inbox") : undefined, ...takenLines(taken), ...ownLines, ...heldMine.map((h) => heldLine(ctx, h, downloads)), side, tidied.length ? `${counted(tidied.length, "file")} of strom's own in the downloads folder removed: ${tidied.slice(0, 5).join(", ")}${tidied.length > 5 ? " …" : ""} — copies of images registered already` : undefined),
|
|
1363
|
+
text: lines(nothing ? (waits.length ? "nothing came: no file in the downloads folder or the folders of the waiting tasks" : "no task waits for images saved into the inbox") : undefined, ...takenLines(taken), ...writingLines, ...ownLines, ...heldMine.map((h) => heldLine(ctx, h, downloads)), side, tidied.length ? `${counted(tidied.length, "file")} of strom's own in the downloads folder removed: ${tidied.slice(0, 5).join(", ")}${tidied.length > 5 ? " …" : ""} — copies of images registered already` : undefined),
|
|
1196
1364
|
data: {
|
|
1197
1365
|
taken,
|
|
1198
1366
|
woken,
|
|
1199
1367
|
held: held.map((h) => ({ task: h.task, recordset: h.recordset, image: h.n, host: h.host, url: h.url, since: new Date(h.at).toISOString() })),
|
|
1200
1368
|
waits: waits.map((x) => ({ task: x.task, recordset: x.recordset, missing: missingOf(x), ...(x.task === mine ? { current: true } : {}) })).filter((x) => x.missing.length),
|
|
1201
1369
|
tidied,
|
|
1370
|
+
...(writing.length ? { writing: writing.map((d) => ({ task: d.task, image: d.n, file: d.name })) } : {}),
|
|
1202
1371
|
},
|
|
1203
1372
|
};
|
|
1204
1373
|
}
|
|
@@ -1348,14 +1517,16 @@ register({
|
|
|
1348
1517
|
"it waits for are there; a copy saved late or twice is tidied once the image is registered. One image at a time,\n" +
|
|
1349
1518
|
"never a book; nothing is asked of the archive but the page you open. Refused where strom's list or the archive's robots.txt keeps\n" +
|
|
1350
1519
|
"automated tools off, without the person's permission, and for an agent whose browser strom does not keep — the\n" +
|
|
1351
|
-
"person saves it by hand then."
|
|
1520
|
+
"person saves it by hand then. An image registered already that reads too weak: --again saves it once more (the\n" +
|
|
1521
|
+
"viewer zoomed in, its full resolution) as a new copy beside it — nothing removed; the sharpest copy is the image.",
|
|
1352
1522
|
args: [{ name: "task", description: "the task the image is for (T…)", required: true }],
|
|
1353
1523
|
options: [
|
|
1354
1524
|
{ name: "image", type: "string", value: "<n>", description: "the image number, as the archive's viewer counts it" },
|
|
1355
1525
|
{ name: "at", type: "string", value: "<url>", description: "the archive's page of that one image (as its viewer's address names it)" },
|
|
1356
1526
|
{ name: "recordset", type: "string", value: "<B…>", description: "the book (else the one the task waits for, or the one of its books on the archive of --at)" },
|
|
1527
|
+
{ name: "again", type: "boolean", description: "an image registered already, saved once more (a sharper scan: the viewer zoomed in, its full resolution) — a new copy beside it, nothing removed; the sharpest copy is the image views, readings and citations use" },
|
|
1357
1528
|
],
|
|
1358
|
-
examples: ["strom media save T0007 --image 40 --at https://archive.example.org/viewer/book-17?image=40"],
|
|
1529
|
+
examples: ["strom media save T0007 --image 40 --at https://archive.example.org/viewer/book-17?image=40", "strom media save T0007 --image 40 --recordset B0003 --at https://archive.example.org/viewer/book-17?image=40 --again"],
|
|
1359
1530
|
run(ctx, { args, opts }) {
|
|
1360
1531
|
const tree = ctx.tree();
|
|
1361
1532
|
const t = requireRecord(tree, normId(args[0]), "task");
|
|
@@ -1374,8 +1545,11 @@ register({
|
|
|
1374
1545
|
}
|
|
1375
1546
|
if (t.state === "done" || t.state === "parked" || (t.state === "waiting" && (!w || w.recordset !== b.id)))
|
|
1376
1547
|
throw new UsageError(`${t.id} is ${t.state}${t.state === "waiting" ? ` — for ${waitKindOf(t) === "images" && w ? `images of ${w.recordset}` : "something else"}` : ""}: an image of ${b.id} is saved for a task that works in it`, { hint: `strom task show ${t.id}` });
|
|
1377
|
-
|
|
1378
|
-
|
|
1548
|
+
const again = registeredImages(tree, b.id).has(n);
|
|
1549
|
+
if (again && !opts.again)
|
|
1550
|
+
throw new UsageError(`image ${n} of ${b.id} is registered already`, {
|
|
1551
|
+
hint: `strom media view ${b.id}:${n} shows it; a sharper scan of it (the viewer zoomed in, its full resolution): strom media save ${t.id} --image ${n} --recordset ${b.id} --at ${String(opts.at ?? "").trim() || "<the archive's page of it>"} --again — a new copy beside it, nothing removed`,
|
|
1552
|
+
});
|
|
1379
1553
|
let u;
|
|
1380
1554
|
try {
|
|
1381
1555
|
u = new URL(String(opts.at ?? "").trim());
|
|
@@ -1427,7 +1601,10 @@ register({
|
|
|
1427
1601
|
fs.mkdirSync(dir, { recursive: true });
|
|
1428
1602
|
const file = waitFileBase(tree.config.id, t.id, n);
|
|
1429
1603
|
if (!tree.dryRun) {
|
|
1430
|
-
|
|
1604
|
+
// saved once more: strom's late copies of the earlier save tidied first — never taken for the new one
|
|
1605
|
+
if (again)
|
|
1606
|
+
tidyDownloads(tree, ctx.settings.downloads());
|
|
1607
|
+
noteSave(tree.root, { task: t.id, n, recordset: b.id, host: u.hostname, url: u.href, file, at: Date.now(), ...(again ? { again: true } : {}) });
|
|
1431
1608
|
// the task's other images held back before: asked of the person once more by this wait, so said anew
|
|
1432
1609
|
if (wasHeld)
|
|
1433
1610
|
storeSaves(tree.root, loadSaves(tree.root).map(({ held, ...r }) => (r.task === t.id || !held ? r : { ...r, held })));
|
|
@@ -1437,8 +1614,8 @@ register({
|
|
|
1437
1614
|
const script = saveScript({ url: u.href, file, n, task: t.id, until: Date.now() + PLAN_TTL_MS, other: phrase(lang, "browser.save.other", { n: String(n), url: u.href }) }, tileWait ? { tileWaitMs: tileWait } : {});
|
|
1438
1615
|
const then = "strom media add --inbox --waiting";
|
|
1439
1616
|
return {
|
|
1440
|
-
text: lines(...tree.written.map((o) => o.summary), `${t.id} · image ${n} of ${b.id} — saved from ${g.host} through your browser, this one image:`, `1. Open ${u.href} in a tab of your own (once; a tab of yours on it already: that one). Never another image or page of the book for it.`, `2. Run this script in that tab with your browser's JavaScript tool; it answers "strom-result ${n}:200:<bytes>" (the file ${file}.jpg in the downloads folder):`, script, ...(tileWait ? [` It answers "strom-wait …" while the viewer's tiles still come (browser.tileWait): run the same script again in the same tab, as often as it says so — it goes on where it is.`] : []), `3. ${then} — moves it into the task's folder as image ${n}, takes it and says whether it came and where it is now (or that nothing came yet); never look into the downloads folder yourself. Anything else the script answers: tell the user, never try another way.`, `Chrome saves one file of a page by itself; one more from the same page waits until the user allows ${u.hostname} to download several files (once, at the right end of the address bar), in the browser profile your browser tool works in — a permission given in another profile does not count. The script said saved and nothing came: tell the user, never change Chrome's settings yourself.`),
|
|
1441
|
-
data: { task: t.id, recordset: b.id, image: n, waits: images, url: u.href, file, script, then },
|
|
1617
|
+
text: lines(...tree.written.map((o) => o.summary), `${t.id} · image ${n} of ${b.id} — saved from ${g.host} through your browser, this one image${again ? " once more (registered already: the new copy goes beside it, the sharpest is the image)" : ""}:`, `1. Open ${u.href} in a tab of your own (once; a tab of yours on it already: that one). Never another image or page of the book for it.`, `2. Run this script in that tab with your browser's JavaScript tool; it answers "strom-result ${n}:200:<bytes>" (the file ${file}.jpg in the downloads folder):`, script, ...(tileWait ? [` It answers "strom-wait …" while the viewer's tiles still come (browser.tileWait): run the same script again in the same tab, as often as it says so — it goes on where it is.`] : []), `3. ${then} — moves it into the task's folder as image ${n}, takes it and says whether it came and where it is now (or that nothing came yet); never look into the downloads folder yourself. Anything else the script answers: tell the user, never try another way.`, `Chrome saves one file of a page by itself; one more from the same page waits until the user allows ${u.hostname} to download several files (once, at the right end of the address bar), in the browser profile your browser tool works in — a permission given in another profile does not count. The script said saved and nothing came: tell the user, never change Chrome's settings yourself.`),
|
|
1618
|
+
data: { task: t.id, recordset: b.id, image: n, waits: images, url: u.href, file, script, then, ...(again ? { again: true } : {}) },
|
|
1442
1619
|
};
|
|
1443
1620
|
},
|
|
1444
1621
|
}, {
|
|
@@ -1682,7 +1859,7 @@ register({
|
|
|
1682
1859
|
r.near ? ` ${nearLine(r.near, t)}` : undefined,
|
|
1683
1860
|
r.part ? ` ${partLine(r.part)}` : undefined,
|
|
1684
1861
|
r.fetchPart ? ` this part sharper from the archive (one request): ${r.fetchPart}` : undefined,
|
|
1685
|
-
]), missing.length ? `not registered: ${missing.join(", ")} — strom media list --recordset ${missing[0].split(":")[0]}` : undefined, ...failed.map((f) => `no view of ${f.ref}: ${f.error}${f.hint ? ` → ${f.hint}` : ""}`), sizes.has("reduced") ? `reduced: ${REDUCED_HINT}${made.some((m) => m.overview && viewSize(m.r.v) === "reduced") ? `; ${OVERVIEW_HINT}` : ""}` : undefined, sizes.has("enlarged") ? `enlarged: the scan has no more detail there. ${ENLARGED_HINT}; ${SHARPER_SCAN}` : undefined);
|
|
1862
|
+
]), missing.length ? `not registered: ${missing.join(", ")} — strom media list --recordset ${missing[0].split(":")[0]}` : undefined, ...waitedLines(tree, missing).map((l) => ` ${l}`), ...failed.map((f) => `no view of ${f.ref}: ${f.error}${f.hint ? ` → ${f.hint}` : ""}`), sizes.has("reduced") ? `reduced: ${REDUCED_HINT}${made.some((m) => m.overview && viewSize(m.r.v) === "reduced") ? `; ${OVERVIEW_HINT}` : ""}` : undefined, sizes.has("enlarged") ? `enlarged: the scan has no more detail there. ${ENLARGED_HINT}; ${SHARPER_SCAN}` : undefined);
|
|
1686
1863
|
return {
|
|
1687
1864
|
text,
|
|
1688
1865
|
data: { views: made.map(({ t, label, note, r }) => ({ ...viewData(t, r), ref: t.ref, ...(label ? { part: label } : {}), ...(note ? { note } : {}) })), images: targets.length - failed.length, ...(missing.length ? { missing } : {}), ...(failed.length ? { failed } : {}) },
|
package/dist/commands/query.js
CHANGED
|
@@ -91,7 +91,7 @@ register({
|
|
|
91
91
|
{ name: "source", type: "string", value: "<S…|words>", description: "facts citing this source (its ID, or words of its title)" },
|
|
92
92
|
{ name: "status", type: "string", multiple: true, value: "<status>", description: `only facts this sure: ${ASKED_STATUSES.join(", ")} (repeatable); disproven only so` },
|
|
93
93
|
{ name: "story", type: "string", multiple: true, value: "<word>", description: "the stories holding this word, a row per story (repeatable: any of them)" },
|
|
94
|
-
{ name: "of", type: "string", value: "<P…>", description: "the person the relations are to (default: the main person, strom config get main.person)" },
|
|
94
|
+
{ name: "of", type: "string", value: "<P…>", description: "the person the relations are to (default: the main person, strom config get main.person)", mistaken: ["person"] },
|
|
95
95
|
{ name: "kin", type: "string", value: "<set>", description: `whose facts: ${KIN_SETS.join(", ")} (default blood)` },
|
|
96
96
|
{ name: "count", type: "boolean", description: "only the numbers (people, facts); with --by for each group" },
|
|
97
97
|
{ name: "by", type: "string", value: "<group>", description: `group by ${FACT_GROUPS.join(", ")} (with --count: numbers only)` },
|
package/dist/commands/sources.js
CHANGED
|
@@ -570,7 +570,7 @@ register({
|
|
|
570
570
|
{ name: "place", type: "string", value: "<name>", description: "only the books of this place (diacritics optional)" },
|
|
571
571
|
{ name: "kind", type: "string", value: "<kind>", description: "only the books holding this kind of record (baptism, marriage, burial…)" },
|
|
572
572
|
{ name: "years", type: "string", value: "<from-to>", description: "only the books whose years reach into these" },
|
|
573
|
-
{ name: "repo", type: "string", value: "<R…>", description: "only the books of this archive" },
|
|
573
|
+
{ name: "repo", type: "string", value: "<R…>", description: "only the books of this archive", aliases: ["repo-of"] },
|
|
574
574
|
{ name: "full", type: "boolean", description: "--json: whole records instead of one row each" },
|
|
575
575
|
],
|
|
576
576
|
run(ctx, { args, opts }) {
|
package/dist/commands/tasks.js
CHANGED
|
@@ -704,14 +704,19 @@ register({
|
|
|
704
704
|
tree: true,
|
|
705
705
|
options: [
|
|
706
706
|
{ name: "state", type: "string", value: "<state>", description: "open (default queue), doing, done, parked, waiting, dropped, all" },
|
|
707
|
+
{ name: "all", type: "boolean", description: "every task, whatever its state (the same as --state all)" },
|
|
707
708
|
{ name: "research", type: "string", value: "<G…>", description: "only this research" },
|
|
708
709
|
{ name: "level", type: "string", value: "<level>", description: "only this level" },
|
|
709
710
|
{ name: "about", type: "string", value: "<who>", description: "only tasks about this person/record (also X…, H…)" },
|
|
710
711
|
{ name: "off-tree", type: "boolean", description: "the open tasks that wait out of the queue: about people nothing links to the tree yet" },
|
|
711
712
|
{ name: "full", type: "boolean", description: "--json: whole records instead of one row each" },
|
|
712
713
|
],
|
|
713
|
-
run(ctx,
|
|
714
|
+
run(ctx, input) {
|
|
714
715
|
const tree = ctx.tree();
|
|
716
|
+
if (input.opts.all && input.opts.state !== undefined && input.opts.state !== "all")
|
|
717
|
+
throw new UsageError(`--all is every state, --state ${String(input.opts.state)} one of them — not both`, { hint: `strom task list --state ${String(input.opts.state)}` });
|
|
718
|
+
// --all: what --state all lists
|
|
719
|
+
const opts = input.opts.all ? { ...input.opts, state: "all" } : input.opts;
|
|
715
720
|
const research = typeof opts.research === "string" ? resolveResearch(tree, opts.research).id : undefined;
|
|
716
721
|
let all;
|
|
717
722
|
const why = new Map();
|
|
@@ -924,6 +929,8 @@ register({
|
|
|
924
929
|
{ name: "answer", type: "string", value: "<text>", description: "the user's answer to what the task waited for (the user's alone; at most 4000 characters)" },
|
|
925
930
|
{ name: "expect", type: "string", value: "<at>", description: "only if the task is still as it was then (its updated time): else refused, task.changed (the bridge's answer from the app)" },
|
|
926
931
|
{ name: "check", type: "string", value: "works|view|no", description: "the user's answer to a check of a site: works, view (only to be viewed there), no (the user's alone)" },
|
|
932
|
+
// what agents type for --reason here (the write option every writing command has): taken as it
|
|
933
|
+
{ name: "note", type: "string", value: "<text>", description: "the same as --reason: why it comes back", hidden: true },
|
|
927
934
|
],
|
|
928
935
|
examples: ["strom task wake T0002", 'strom task wake T0003 --answer "https://archive.example.org/book/5359"', 'strom task wake T0004 --check view --answer "the book is there, its images only in the viewer"'],
|
|
929
936
|
run(ctx, { args, opts }) {
|
|
@@ -991,7 +998,9 @@ register({
|
|
|
991
998
|
...(fromApp ? { givenIn: "app" } : {}),
|
|
992
999
|
}
|
|
993
1000
|
: undefined;
|
|
994
|
-
|
|
1001
|
+
// why it comes back (--reason, or --note as agents type it): kept with the change in the history
|
|
1002
|
+
const why = [opts.reason, opts.note].find((v) => typeof v === "string" && !!v.trim());
|
|
1003
|
+
return stateChange(tree, id, "open", said ? { answers: [...(before.answers ?? []), said] } : {}, why?.trim(), "wake");
|
|
995
1004
|
});
|
|
996
1005
|
return { text: written(tree), data: { task: t } };
|
|
997
1006
|
},
|
package/dist/core/grep.js
CHANGED
|
@@ -27,7 +27,8 @@ const rel = (root, file) => path.relative(root, file).split(path.sep).join("/");
|
|
|
27
27
|
*/
|
|
28
28
|
export function grepTargets(root, wanted) {
|
|
29
29
|
const out = [];
|
|
30
|
-
|
|
30
|
+
const prefixed = [];
|
|
31
|
+
next: for (const w of wanted.length ? wanted : GREP_DEFAULT) {
|
|
31
32
|
const v = w.trim().replace(/\\/g, "/").replace(/\/+$/u, "");
|
|
32
33
|
if (v === "all") {
|
|
33
34
|
out.push(...GREP_FOLDERS.map((f) => path.join(root, f)));
|
|
@@ -40,7 +41,7 @@ export function grepTargets(root, wanted) {
|
|
|
40
41
|
return { targets: [], error: `--in ${w}: only ${GREP_FOLDERS.map((f) => `${f}/`).join(", ")} are searched (data/ through strom find, the records' commands)`, code: "grep.in.only", params: { where: w, folders: GREP_FOLDERS.map((f) => `${f}/`).join(", ") } };
|
|
41
42
|
// never through a symbolic link: each step from the tree's folder down is what it says it is
|
|
42
43
|
let at = root;
|
|
43
|
-
for (const p of parts) {
|
|
44
|
+
for (const [i, p] of parts.entries()) {
|
|
44
45
|
at = path.join(at, p);
|
|
45
46
|
let st;
|
|
46
47
|
try {
|
|
@@ -50,6 +51,13 @@ export function grepTargets(root, wanted) {
|
|
|
50
51
|
// a folder of the research it does not have (yet): nothing in it
|
|
51
52
|
if (parts.length === 1)
|
|
52
53
|
break;
|
|
54
|
+
// the start of names in its folder (notes/readings/B0001-12 for B0001-12-1.md, B0001-12-2.md): those files
|
|
55
|
+
const names = i === parts.length - 1 ? namesBeginning(path.dirname(at), p) : [];
|
|
56
|
+
if (names.length) {
|
|
57
|
+
out.push(...names.map((n) => path.join(path.dirname(at), n)));
|
|
58
|
+
prefixed.push({ where: w, names });
|
|
59
|
+
continue next;
|
|
60
|
+
}
|
|
53
61
|
return { targets: [], error: `--in ${w}: no such file or folder in the research`, code: "grep.in.missing", params: { where: w } };
|
|
54
62
|
}
|
|
55
63
|
if (st.isSymbolicLink())
|
|
@@ -57,7 +65,32 @@ export function grepTargets(root, wanted) {
|
|
|
57
65
|
}
|
|
58
66
|
out.push(at);
|
|
59
67
|
}
|
|
60
|
-
return { targets: [...new Set(out)] };
|
|
68
|
+
return { targets: [...new Set(out)], ...(prefixed.length ? { prefixed } : {}) };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The names in a folder that begin with a start given, the start a whole part of them (what follows it is no letter or
|
|
72
|
+
* digit: B0001-12 is the start of B0001-12-1.md, never of B0001-125.md) — no dotfiles, no symbolic links; compared in
|
|
73
|
+
* one Unicode form (a name written decomposed too), the names as they are.
|
|
74
|
+
*/
|
|
75
|
+
function namesBeginning(dir, start) {
|
|
76
|
+
const s = start.normalize("NFC");
|
|
77
|
+
if (!s)
|
|
78
|
+
return [];
|
|
79
|
+
try {
|
|
80
|
+
return fs
|
|
81
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
82
|
+
.filter((e) => {
|
|
83
|
+
if (e.name.startsWith(".") || e.isSymbolicLink())
|
|
84
|
+
return false;
|
|
85
|
+
const n = e.name.normalize("NFC");
|
|
86
|
+
return n.startsWith(s) && n.length > s.length && !/^[\p{L}\p{M}\p{N}]/u.test(n.slice(s.length));
|
|
87
|
+
})
|
|
88
|
+
.map((e) => e.name)
|
|
89
|
+
.sort();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
61
94
|
}
|
|
62
95
|
/** The text files under the targets, in order: no dotfiles, no symbolic links, nothing binary. */
|
|
63
96
|
function textFiles(targets) {
|
package/dist/core/indexfirst.js
CHANGED
|
@@ -13,7 +13,7 @@ import { currentSession } from "./session.js";
|
|
|
13
13
|
import { researchKey } from "./viewsizes.js";
|
|
14
14
|
import { indexFirstThreshold } from "./tuneask.js";
|
|
15
15
|
import { imagesIndex } from "./mediaindex.js";
|
|
16
|
-
import { yearsOverlap } from "./years.js";
|
|
16
|
+
import { parseYears, yearsOverlap } from "./years.js";
|
|
17
17
|
import { foldText } from "./text.js";
|
|
18
18
|
import { sameFamily } from "./surnames.js";
|
|
19
19
|
import { subjectPeople } from "./records.js";
|
|
@@ -28,37 +28,73 @@ export function indexFirstFrom(root, cfg, key) {
|
|
|
28
28
|
return t ?? INDEX_FIRST_DEFAULT;
|
|
29
29
|
}
|
|
30
30
|
const isIndex = (b) => b.kinds.some((k) => foldText(k) === "index");
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const firstPart = (s) => foldText(s.split(",")[0].trim());
|
|
32
|
+
/**
|
|
33
|
+
* The parishes a place belonged to in a span of years, as far as they say which parish: a jurisdiction of kind parish
|
|
34
|
+
* whose years (from/to) reach into the span — a dated one says it for its years, so undated ones beside it are not
|
|
35
|
+
* taken; undated ones only when they are one parish (several without years — a parish and a deanery or vicariate
|
|
36
|
+
* written as a parish — do not say which, and match nothing).
|
|
37
|
+
*/
|
|
38
|
+
function parishesIn(pl, span) {
|
|
39
|
+
const inYears = (j) => !span || ((j.from ?? -Infinity) <= span.to && (j.to ?? Infinity) >= span.from);
|
|
40
|
+
const parishes = pl.jurisdictions.filter((j) => j.kind === "parish" && j.name.trim() && inYears(j));
|
|
41
|
+
const dated = parishes.filter((j) => j.from !== undefined || j.to !== undefined);
|
|
42
|
+
if (dated.length)
|
|
43
|
+
return [...new Set(dated.map((j) => firstPart(j.name)))];
|
|
44
|
+
const undated = new Set(parishes.map((j) => firstPart(j.name)));
|
|
45
|
+
return undated.size === 1 ? [...undated] : [];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A record set's places as names to compare (an L… is its names) and the parishes of those places in its years: an L…
|
|
49
|
+
* by its own jurisdictions, a name by those of the one place of the research of that name (several places of one name:
|
|
50
|
+
* which of them is not known, no parish taken).
|
|
51
|
+
*/
|
|
52
|
+
function covers(tree, b) {
|
|
53
|
+
const places = new Set();
|
|
54
|
+
const parishes = new Set();
|
|
55
|
+
const span = parseYears(b.years);
|
|
56
|
+
const all = tree.list("place").filter((p) => !p.retracted);
|
|
57
|
+
for (const raw of b.places) {
|
|
58
|
+
const x = raw.trim();
|
|
59
|
+
if (!x)
|
|
60
|
+
continue;
|
|
61
|
+
const byId = /^L\d{4,}$/u.test(x) ? tree.get(x) : undefined;
|
|
62
|
+
let pl;
|
|
63
|
+
if (byId?.type === "place" && !byId.retracted) {
|
|
64
|
+
pl = byId;
|
|
38
65
|
for (const n of pl.names)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
66
|
+
places.add(firstPart(n.name));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const key = firstPart(x);
|
|
70
|
+
places.add(key);
|
|
71
|
+
const named = all.filter((p) => p.names.some((n) => firstPart(n.name) === key));
|
|
72
|
+
if (named.length === 1)
|
|
73
|
+
pl = named[0];
|
|
74
|
+
}
|
|
75
|
+
if (pl)
|
|
76
|
+
for (const p of parishesIn(pl, span))
|
|
77
|
+
parishes.add(p);
|
|
42
78
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
79
|
+
return { places, parishes };
|
|
80
|
+
}
|
|
81
|
+
/** Two record sets of one parish: a place they share, the parish of one the place or parish of the other. */
|
|
82
|
+
function sameParish(a, b) {
|
|
83
|
+
const meets = (k) => b.places.has(k) || b.parishes.has(k);
|
|
84
|
+
return [...a.places].some(meets) || [...a.parishes].some(meets);
|
|
49
85
|
}
|
|
50
86
|
/** The kinds of record a book holds, its index left out. */
|
|
51
87
|
const recordKinds = (b) => b.kinds.map(foldText).filter((k) => k && k !== "index");
|
|
52
88
|
/**
|
|
53
|
-
* The index books of a book's parish: an index (kinds: index) of a place it covers or the parish of one, its years
|
|
89
|
+
* The index books of a book's parish: an index (kinds: index) of a place it covers or the parish of one in its years, its years
|
|
54
90
|
* reaching into the book's and its kinds of record the book's (an index naming no kind, or a book naming none: any).
|
|
55
91
|
* None for a book that is an index or holds one itself.
|
|
56
92
|
*/
|
|
57
93
|
export function indexBooksOf(tree, book) {
|
|
58
94
|
if (book.retracted || isIndex(book))
|
|
59
95
|
return [];
|
|
60
|
-
const
|
|
61
|
-
if (!places.size)
|
|
96
|
+
const own = covers(tree, book);
|
|
97
|
+
if (!own.places.size && !own.parishes.size)
|
|
62
98
|
return [];
|
|
63
99
|
const kinds = recordKinds(book);
|
|
64
100
|
const out = [];
|
|
@@ -71,7 +107,7 @@ export function indexBooksOf(tree, book) {
|
|
|
71
107
|
continue;
|
|
72
108
|
if (!yearsOverlap(b.years, book.years))
|
|
73
109
|
continue;
|
|
74
|
-
if (!
|
|
110
|
+
if (!sameParish(own, covers(tree, b)))
|
|
75
111
|
continue;
|
|
76
112
|
out.push(describe(tree, b, sets.get(b.id)?.images ?? []));
|
|
77
113
|
}
|
package/dist/core/live.js
CHANGED
|
@@ -821,6 +821,21 @@ export function widgetMaker(root, env, said) {
|
|
|
821
821
|
throw e;
|
|
822
822
|
});
|
|
823
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
* What a strom of the bridge's said of its error: --json gives it on stdout ({"status":"error","message"}), else the
|
|
826
|
+
* "error:" line of stderr. None: undefined.
|
|
827
|
+
*/
|
|
828
|
+
export function takeError(stdout, stderr) {
|
|
829
|
+
try {
|
|
830
|
+
const j = JSON.parse(stdout);
|
|
831
|
+
if (j && j.status === "error" && typeof j.message === "string" && j.message.trim())
|
|
832
|
+
return j.message.trim().slice(0, 300);
|
|
833
|
+
}
|
|
834
|
+
catch {
|
|
835
|
+
// not its JSON: stderr says it
|
|
836
|
+
}
|
|
837
|
+
return stderr.trim().split("\n").find((l) => l.startsWith("error:"))?.slice(6).trim() || undefined;
|
|
838
|
+
}
|
|
824
839
|
/** One line (or an error with its stack) into the bridge's log; never fails, never grows past its size. */
|
|
825
840
|
export function noteLive(root, text) {
|
|
826
841
|
try {
|
|
@@ -7074,7 +7089,12 @@ export function serveLive(root, env) {
|
|
|
7074
7089
|
return done(false);
|
|
7075
7090
|
}
|
|
7076
7091
|
if (code !== 0) {
|
|
7077
|
-
|
|
7092
|
+
// the research busy with another writer the whole wait (the agent's own take among them): nothing wrong —
|
|
7093
|
+
// the next look takes what is still there, quietly
|
|
7094
|
+
if (code === EXIT.locked)
|
|
7095
|
+
return done(false);
|
|
7096
|
+
// a real error: said with its words (--json gives them on stdout), never a bare exit code
|
|
7097
|
+
noteLive(root, `images saved for waiting tasks not taken now: ${takeError(out, err) ?? `exit ${code}`}`);
|
|
7078
7098
|
return done(false);
|
|
7079
7099
|
}
|
|
7080
7100
|
try {
|
package/dist/core/tree.js
CHANGED
|
@@ -32,7 +32,7 @@ export const TREE_FILE = "strom.json";
|
|
|
32
32
|
export const SEAL_FOREIGN = "seal.foreign";
|
|
33
33
|
// between releases the candidate being made (a bridge run from the sources says what it is: the Strom app goes by it);
|
|
34
34
|
// at a release the release's own (package.json)
|
|
35
|
-
export const VERSION = "1.33.0-beta.
|
|
35
|
+
export const VERSION = "1.33.0-beta.2";
|
|
36
36
|
/** What a new research is settled with from the start: nothing an older strom counted otherwise to set right in it. */
|
|
37
37
|
export const NEW_TREE_SETTLED = ["readers-1", "proven-originals-1", "origins-1", "verify-originals-1", "origins-tree-1"];
|
|
38
38
|
const GITIGNORE = `# Strom Research — local state and large files are not versioned
|