strom-research 1.36.0-beta.5 → 1.36.0-beta.6
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 +6 -1
- package/CHANGELOG.de.md +7 -1
- package/CHANGELOG.md +6 -1
- package/CHANGELOG.pl.md +7 -1
- package/assets/method/core.md +2 -1
- package/dist/cli/human.js +61 -12
- package/dist/cli/menu-links.js +6 -17
- package/dist/cli/menu-research.js +2 -2
- package/dist/cli/menu-waiting.js +6 -6
- package/dist/commands/analysis.js +3 -2
- package/dist/commands/document.js +20 -8
- package/dist/commands/readers.js +184 -0
- package/dist/commands/session.js +22 -3
- package/dist/core/document.js +23 -5
- package/dist/core/errors.js +14 -0
- package/dist/core/readchoice.js +3 -0
- package/dist/core/readprovider.js +148 -0
- package/dist/core/session.js +2 -4
- 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.36.0
|
|
9
9
|
|
|
10
|
-
*Připravuje se: bety do 1.36.0-beta.
|
|
10
|
+
*Připravuje se: bety do 1.36.0-beta.6. Oddíl bude úplný s vydáním.*
|
|
11
11
|
|
|
12
12
|
- **Zkouška hromadného ověření hned:** úkoly zkoušky hromadného ověření (`strom verify bulk --try`) stojí na začátku
|
|
13
13
|
fronty – vezme je příští sezení – a aplikace Strom je dá zpracovat hned, každý úkol jedno sezení, odkazem, který úkoly
|
|
@@ -64,6 +64,11 @@ Změny každé verze ve zkratce. Úplné poznámky a instalační řádky jsou n
|
|
|
64
64
|
tak označené, aby ho aplikace k umístění přidala, aniž by z něj vystřihla číslo jiného snímku. `strom pack` a `strom
|
|
65
65
|
trees remove` jmenují skeny z archivů jako skeny (které jdou s sebou, které se vynechají) a záloha před odstraněním
|
|
66
66
|
řekne, že v ní jsou rodinné fotky a originály.
|
|
67
|
+
V terminálu jmenují otázka a varianty hypotézy lidi a rodiny, které uvádějí kódem, jménem s kódem (v Co čeká i když
|
|
68
|
+
aplikace Strom žádá o rozhodnutí) a agent je tak i píše; jméno napsané před kódem – osoby nebo partnerů rodiny – se
|
|
69
|
+
nikdy neopakuje.
|
|
70
|
+
Běhy vedle sebe v jednom stromu („spustit další vedle něj“, konverzace vedle běhu): běh, jehož další úkol těsně před
|
|
71
|
+
začátkem vzal jiný, pokračuje dalším volným úkolem místo konce celého běhu; žádný úkol se nevezme dvakrát.
|
|
67
72
|
|
|
68
73
|
## 1.35.0
|
|
69
74
|
|
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.36.0
|
|
9
9
|
|
|
10
|
-
*In Vorbereitung: die Betas bis 1.36.0-beta.
|
|
10
|
+
*In Vorbereitung: die Betas bis 1.36.0-beta.6. Der Abschnitt ist mit dem Release vollständig.*
|
|
11
11
|
|
|
12
12
|
- **Ein Versuch der Sammelprüfung sofort:** Die Aufgaben eines Versuchs der Sammelprüfung (`strom verify bulk --try`)
|
|
13
13
|
stehen am Anfang der Warteschlange – die nächste Sitzung nimmt sie –, und die Strom-App lässt sie sofort bearbeiten,
|
|
@@ -74,6 +74,12 @@ Die Änderungen jeder Version in Kürze. Die vollständigen Hinweise und die Ins
|
|
|
74
74
|
gekennzeichnet, sodass die App sie zur Fundstelle hinzufügt, ohne die Nummer eines anderen Bildes daraus zu entfernen.
|
|
75
75
|
`strom pack` und `strom trees remove` nennen die Scans der Archive als Scans (welche mitgehen, welche weggelassen
|
|
76
76
|
werden), und die Sicherung vor dem Entfernen sagt, dass sie die Fotos und Originale der Familie enthält.
|
|
77
|
+
Im Terminal nennen die Frage und die Varianten einer Hypothese die Personen und Familien, die sie mit ihrer ID angeben,
|
|
78
|
+
mit Namen und ID (unter „Was wartet“ und wenn die Strom-App um eine Entscheidung bittet), und der Agent schreibt sie
|
|
79
|
+
auch so; ein vor der ID geschriebener Name – einer Person oder der Partner einer Familie – wird nie doppelt genannt.
|
|
80
|
+
Läufe nebeneinander in einem Stammbaum („einen weiteren daneben starten“, eine Unterhaltung neben einem Lauf): ein
|
|
81
|
+
Lauf, dessen nächste Aufgabe kurz vor dem Beginn ein anderer übernommen hat, macht mit der nächsten freien Aufgabe
|
|
82
|
+
weiter, statt den ganzen Lauf zu beenden; keine Aufgabe wird zweimal übernommen.
|
|
77
83
|
|
|
78
84
|
## 1.35.0
|
|
79
85
|
|
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.36.0
|
|
9
9
|
|
|
10
|
-
*In preparation: the betas up to 1.36.0-beta.
|
|
10
|
+
*In preparation: the betas up to 1.36.0-beta.6. The section is complete with the release.*
|
|
11
11
|
|
|
12
12
|
- **A try of the bulk verification at once:** the tasks of a try of the bulk verification (`strom verify bulk --try`)
|
|
13
13
|
stand first in the queue — the next session takes them — and the Strom app can have them worked on at once, one
|
|
@@ -67,6 +67,11 @@ The changes of each version in short. The full notes and the install lines are o
|
|
|
67
67
|
registered scans is marked as such, so that the app adds it to the location without cutting another image's number out
|
|
68
68
|
of it. `strom pack` and `strom trees remove` name the archives' scans as scans (which go along, which are left out),
|
|
69
69
|
and the backup before a removal says it holds the family's photos and originals.
|
|
70
|
+
In the terminal a hypothesis's question and variants name the people and families they give by ID by their names with
|
|
71
|
+
the ID (in What waits and when the Strom app asks to decide one), and the agent writes them so too; a name written before
|
|
72
|
+
the ID — a person's, or the partners' of a family — is never said twice.
|
|
73
|
+
Runs side by side on one tree ("start another one beside it", a conversation beside a run): a run whose next task another
|
|
74
|
+
took just before it began goes on with the next free task instead of ending the whole run; no task is taken twice.
|
|
70
75
|
|
|
71
76
|
## 1.35.0
|
|
72
77
|
|
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.36.0
|
|
9
9
|
|
|
10
|
-
*W przygotowaniu: bety do 1.36.0-beta.
|
|
10
|
+
*W przygotowaniu: bety do 1.36.0-beta.6. Sekcja będzie kompletna z wydaniem.*
|
|
11
11
|
|
|
12
12
|
- **Próba zbiorczej weryfikacji od razu:** zadania próby zbiorczej weryfikacji (`strom verify bulk --try`) stoją na
|
|
13
13
|
początku kolejki – weźmie je następna sesja – a aplikacja Strom pozwala przerobić je od razu, każde zadanie w jednej
|
|
@@ -67,6 +67,12 @@ Zmiany każdej wersji w skrócie. Pełne informacje o wydaniach i polecenia inst
|
|
|
67
67
|
tak oznaczony, by aplikacja dodała go do lokalizacji, nie wycinając z niej numeru innego skanu. `strom pack` i `strom
|
|
68
68
|
trees remove` nazywają skany z archiwów skanami (które idą razem, które są pominięte), a kopia zapasowa przed
|
|
69
69
|
usunięciem mówi, że zawiera rodzinne zdjęcia i oryginały.
|
|
70
|
+
W terminalu pytanie i warianty hipotezy nazywają osoby i rodziny podane identyfikatorem imieniem z identyfikatorem
|
|
71
|
+
(w Co czeka i gdy aplikacja Strom prosi o rozstrzygnięcie), a agent też tak je pisze; imię zapisane przed
|
|
72
|
+
identyfikatorem – osoby lub partnerów rodziny – nigdy nie powtarza się.
|
|
73
|
+
Przebiegi obok siebie w jednym drzewie („uruchomić kolejnego obok niego”, rozmowa obok przebiegu): przebieg, którego
|
|
74
|
+
następne zadanie tuż przed rozpoczęciem wziął inny, kontynuuje następnym wolnym zadaniem zamiast kończyć cały
|
|
75
|
+
przebieg; żadne zadanie nie jest brane dwa razy.
|
|
70
76
|
|
|
71
77
|
## 1.35.0
|
|
72
78
|
|
package/assets/method/core.md
CHANGED
|
@@ -86,7 +86,8 @@ conclusion so the next researcher can follow it.
|
|
|
86
86
|
words only. An older open hypothesis you work on that has none gets them
|
|
87
87
|
then (`strom hypothesis list --unlinked`). A variant's letter stays its
|
|
88
88
|
claim's: a claim that would connect other people is a new variant
|
|
89
|
-
(`strom hypothesis variant H… "<claim>"`).
|
|
89
|
+
(`strom hypothesis variant H… "<claim>"`). The question and claims name
|
|
90
|
+
people by name and ID ("the son of Jan Lhoták (P0118)"), never the ID alone.
|
|
90
91
|
- **The user decides a hypothesis**; you propose it once the records point
|
|
91
92
|
to one variant: `strom hypothesis propose H… --variant B --decision "…"`
|
|
92
93
|
(none holds: `--abandon`), and go on — unless the user lets you decide
|
package/dist/cli/human.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// they are shown.
|
|
5
5
|
import { MONTHS } from "../core/gdate.js";
|
|
6
6
|
import { ui } from "./ui.js";
|
|
7
|
-
import { displayName } from "../core/people.js";
|
|
7
|
+
import { currentName, displayName } from "../core/people.js";
|
|
8
8
|
import { foldText } from "../core/text.js";
|
|
9
9
|
import { houseHasWord } from "../core/house.js";
|
|
10
10
|
const MONTH_PL = {
|
|
@@ -158,6 +158,62 @@ function namesOne(word, names) {
|
|
|
158
158
|
return word.length >= k && word.slice(0, k) === n.slice(0, k);
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
+
/** The words of a person's given name, folded; none given: the words of their whole name. */
|
|
162
|
+
function givenWords(p) {
|
|
163
|
+
const given = foldText(currentName(p).given).split(/[^\p{L}\p{M}\p{N}]+/u).filter((w) => w.length >= 2);
|
|
164
|
+
return given.length ? given : nameWords(p);
|
|
165
|
+
}
|
|
166
|
+
/** Can each partner be told by a word of their own (no word naming two of them)? */
|
|
167
|
+
function eachByOwnWord(words, partners, used = new Set()) {
|
|
168
|
+
if (!partners.length)
|
|
169
|
+
return true;
|
|
170
|
+
const [names, ...rest] = partners;
|
|
171
|
+
return words.some((w, i) => !used.has(i) && namesOne(w, names) && eachByOwnWord(words, rest, new Set([...used, i])));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Whether the text before a person's ID ends with their name (the two words before it, declined too); before a family's,
|
|
175
|
+
* with the given names of all its partners, each by a word of its own (two words each and a word between them: "Jan +
|
|
176
|
+
* Anna F0001", "Jana Lhotáka a Anny Lhotové F0001") — a surname two partners share never names both.
|
|
177
|
+
*/
|
|
178
|
+
function namedBefore(tree, id, before) {
|
|
179
|
+
const r = tree.get(id);
|
|
180
|
+
const people = r?.type === "person" ? [r] : r?.type === "family" ? r.partners.map((x) => tree.get(x)).filter((x) => x?.type === "person") : [];
|
|
181
|
+
if (!people.length)
|
|
182
|
+
return false;
|
|
183
|
+
// the words before the ID (letters only, none of them an ID)
|
|
184
|
+
const words = foldText(before.slice(-60 * people.length)).split(/[^\p{L}\p{M}\p{N}]+/u).filter(Boolean).slice(-3 * people.length + 1).filter((w) => !/^[pfsbn]\d{4,}$/u.test(w));
|
|
185
|
+
if (people.length === 1)
|
|
186
|
+
return words.slice(-2).some((w) => namesOne(w, nameWords(people[0])));
|
|
187
|
+
return eachByOwnWord(words, people.map(givenWords));
|
|
188
|
+
}
|
|
189
|
+
/** A person or a family of the research by name with its ID: "Jan Lhoták (P0001)", "Jan Lhoták + Anna Lhotová (F0001)". */
|
|
190
|
+
export function whoSaid(tree, id) {
|
|
191
|
+
const r = tree.get(id);
|
|
192
|
+
if (r?.type === "person")
|
|
193
|
+
return `${displayName(r)} (${id})`;
|
|
194
|
+
if (r?.type === "family") {
|
|
195
|
+
const names = r.partners.map((p) => tree.get(p)).filter((p) => p?.type === "person").map(displayName);
|
|
196
|
+
return names.length ? `${names.join(" + ")} (${id})` : id;
|
|
197
|
+
}
|
|
198
|
+
return id;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* What an agent wrote of a hypothesis (its question, a variant's claim), for the person: the people and families it
|
|
202
|
+
* names by ID by their names with the ID, as the tree's changes beside it say them ("syn P0118" → "syn Jan Lhoták
|
|
203
|
+
* (P0118)"). A person's ID right after their name keeps the name as written ("Jana Lhotáka P0118", "… [P0118]" →
|
|
204
|
+
* "Jana Lhotáka (P0118)"); an ID the research has not stays as it is.
|
|
205
|
+
*/
|
|
206
|
+
export function humanClaim(tree, text) {
|
|
207
|
+
return text.replace(/([[(])?(?<![\p{L}\p{M}\p{N}])([PF]\d{4,})(?![\p{L}\p{M}\p{N}])([\])])?/gu, (all, open, id, close, at) => {
|
|
208
|
+
const r = tree.get(id);
|
|
209
|
+
if (r?.type !== "person" && r?.type !== "family")
|
|
210
|
+
return all;
|
|
211
|
+
// one bracket alone is the text's own: kept around what is said
|
|
212
|
+
const paired = !!open && !!close && (open === "[") === (close === "]");
|
|
213
|
+
const [lead, tail] = paired ? ["", ""] : [open ?? "", close ?? ""];
|
|
214
|
+
return `${lead}${namedBefore(tree, id, text.slice(0, at)) ? `(${id})` : whoSaid(tree, id)}${tail}`;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
161
217
|
/**
|
|
162
218
|
* What the agent wrote into a task, for the user: the records it names by ID by their names ("S0001" → its title).
|
|
163
219
|
* `asWritten`: a person's ID right after their name in the text stays the bare ID in brackets ("Václava Nováka P0001" →
|
|
@@ -165,15 +221,7 @@ function namesOne(word, names) {
|
|
|
165
221
|
* after their name, as strom writes it ("Karel Němec [P0001]"), stays as it is either way.
|
|
166
222
|
*/
|
|
167
223
|
export function humanTask(tree, text, lang, o = {}) {
|
|
168
|
-
const named = (id, before) =>
|
|
169
|
-
const p = tree.get(id);
|
|
170
|
-
if (p?.type !== "person")
|
|
171
|
-
return false;
|
|
172
|
-
// the two words before the ID (letters only, none of them an ID)
|
|
173
|
-
const words = foldText(before.slice(-60)).split(/[^\p{L}\p{M}\p{N}]+/u).filter(Boolean).slice(-2).filter((w) => !/^[pfsbn]\d{4,}$/u.test(w));
|
|
174
|
-
const names = nameWords(p);
|
|
175
|
-
return words.some((w) => namesOne(w, names));
|
|
176
|
-
};
|
|
224
|
+
const named = (id, before) => namedBefore(tree, id, before);
|
|
177
225
|
const name = (id) => {
|
|
178
226
|
const r = tree.get(id);
|
|
179
227
|
if (!r)
|
|
@@ -187,12 +235,13 @@ export function humanTask(tree, text, lang, o = {}) {
|
|
|
187
235
|
return r.title;
|
|
188
236
|
};
|
|
189
237
|
// A list of IDs as a list of names, each once (two sessions of one day read as one).
|
|
190
|
-
|
|
238
|
+
// already in brackets ("… [F0001]"): the bare ID inside them, never "[[F0001]]"
|
|
239
|
+
const names = (ids, at, bracketed = false) => o.asWritten && !ids.includes(",") && named(ids, text.slice(0, at)) ? (bracketed ? ids : `[${ids}]`) : [...new Set(ids.split(", ").map(name))].join(", ");
|
|
191
240
|
return text.replace(/(\[)?\b([PFSBN]\d{4,}\b(?:, [PFSBN]\d{4,}\b)*)(\])?/g, (all, open, ids, close, at) => {
|
|
192
241
|
// a person's ID in brackets as strom writes it ("Karel Němec [P0001]"): kept after their name, else their name in its place
|
|
193
242
|
if (open && close && !ids.includes(",") && tree.get(ids)?.type === "person")
|
|
194
243
|
return named(ids, text.slice(0, at)) ? all : name(ids);
|
|
195
|
-
return `${open ?? ""}${names(ids, at + (open ? 1 : 0))}${close ?? ""}`;
|
|
244
|
+
return `${open ?? ""}${names(ids, at + (open ? 1 : 0), !!open && !!close)}${close ?? ""}`;
|
|
196
245
|
});
|
|
197
246
|
}
|
|
198
247
|
/**
|
package/dist/cli/menu-links.js
CHANGED
|
@@ -7,7 +7,7 @@ import fs from "node:fs";
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { outOfAnswers, translator } from "./menu-parts.js";
|
|
9
9
|
import { askPaths, directionTasks, offerChat, setDirection } from "./menu-research.js";
|
|
10
|
-
import { humanCost, humanDay, humanTask, humanWhen } from "./human.js";
|
|
10
|
+
import { humanClaim, humanCost, humanDay, humanTask, humanWhen, whoSaid } from "./human.js";
|
|
11
11
|
import { lines, truncate } from "./format.js";
|
|
12
12
|
import { isArchive } from "../core/mode.js";
|
|
13
13
|
import { actsAsArchive, kindOf } from "../core/state.js";
|
|
@@ -796,24 +796,13 @@ export async function hypothesisDo(ctx, run, lang, root, id, how = "decide", var
|
|
|
796
796
|
out(ctx, t("ui.link.hypothesis.notInApp", { id: h.id }));
|
|
797
797
|
else if (picked)
|
|
798
798
|
return hypothesisPicked(ctx, run, lang, root, h, how, variant);
|
|
799
|
-
if (!(await asks(ctx, lang, root, t(h.state === "open" ? "ui.link.what.hypothesis.decide" : "ui.link.what.hypothesis.change", { question: truncate(h.question, 120) }))))
|
|
799
|
+
if (!(await asks(ctx, lang, root, t(h.state === "open" ? "ui.link.what.hypothesis.decide" : "ui.link.what.hypothesis.change", { question: truncate(humanClaim(tree, h.question), 120) }))))
|
|
800
800
|
return false;
|
|
801
801
|
const { decideHypothesis } = await import("./menu-waiting.js");
|
|
802
802
|
return decideHypothesis(ctx, run, lang, root, h.id);
|
|
803
803
|
}
|
|
804
804
|
/** People a decision joins to the tree from which the terminal says how many (the app's K1.4: "a large part of the tree"). */
|
|
805
805
|
export const HYPOTHESIS_BIG_JOIN = 50;
|
|
806
|
-
/** A person or a family as the person reads it: the name and the ID ("Josef Lhoták (P0001)", "Václav Lhoták + Marie Lhotová (F0001)"). */
|
|
807
|
-
function whoSaid(tree, id) {
|
|
808
|
-
const r = tree.get(id);
|
|
809
|
-
if (r?.type === "person")
|
|
810
|
-
return `${displayName(r)} (${id})`;
|
|
811
|
-
if (r?.type === "family") {
|
|
812
|
-
const names = r.partners.map((p) => tree.get(p)).filter((p) => p?.type === "person").map(displayName);
|
|
813
|
-
return names.length ? `${names.join(" + ")} (${id})` : id;
|
|
814
|
-
}
|
|
815
|
-
return id;
|
|
816
|
-
}
|
|
817
806
|
/** One link of a variant in the research language — into the family it went to, when there is one. */
|
|
818
807
|
function linkSaid(t, tree, l, family) {
|
|
819
808
|
if (l.kind === "child") {
|
|
@@ -904,7 +893,7 @@ async function hypothesisPicked(ctx, run, lang, root, h, how, label) {
|
|
|
904
893
|
const tree = Tree.open(root, ctx.env);
|
|
905
894
|
const archive = actsAsArchive(tree);
|
|
906
895
|
const p = archive ? undefined : h.proposal;
|
|
907
|
-
out(ctx, ["", ` ${h.id} · ${h.question}`, ...h.variants.map((v) => ` ${v.label}) ${truncate(v.claim, 110)}`), ...(h.state !== "open" ? [` ${decidedLine(t, tree, h, lang)}`] : []), ""].join("\n"));
|
|
896
|
+
out(ctx, ["", ` ${h.id} · ${humanClaim(tree, h.question)}`, ...h.variants.map((v) => ` ${v.label}) ${truncate(humanClaim(tree, v.claim), 110)}`), ...(h.state !== "open" ? [` ${decidedLine(t, tree, h, lang)}`] : []), ""].join("\n"));
|
|
908
897
|
const why = async (fallback) => {
|
|
909
898
|
const said = (await ctx.ask(t("ui.link.hypothesis.why", { reason: fallback }))).trim();
|
|
910
899
|
return said === "0" ? undefined : said || fallback;
|
|
@@ -922,7 +911,7 @@ async function hypothesisPicked(ctx, run, lang, root, h, how, label) {
|
|
|
922
911
|
if (h.state === "decided" && h.chosen === v.label)
|
|
923
912
|
return stop(ctx, `${decidedLine(t, tree, h, lang)} ${t("ui.link.hypothesis.nothing")}`);
|
|
924
913
|
const n = branchJoined(tree, h, v);
|
|
925
|
-
const what = t(h.state === "open" ? "ui.link.what.hypothesis.pick" : "ui.link.what.hypothesis.repick", { id: h.id, variant: v.label, claim: truncate(v.claim, 110) });
|
|
914
|
+
const what = t(h.state === "open" ? "ui.link.what.hypothesis.pick" : "ui.link.what.hypothesis.repick", { id: h.id, variant: v.label, claim: truncate(humanClaim(tree, v.claim), 110) });
|
|
926
915
|
// the earlier link stays (other work stands on it) and the new one cannot be written: said first, cancel suggested
|
|
927
916
|
const stays = changeWarning(lang, tree, h, v);
|
|
928
917
|
// a variant that connects nothing, and nothing of an earlier decision on the tree to take off: only the decision is
|
|
@@ -1001,13 +990,13 @@ export async function acceptProposals(ctx, run, lang, root, ids) {
|
|
|
1001
990
|
const line = (h) => {
|
|
1002
991
|
const p = h.proposal;
|
|
1003
992
|
if (p.abandon || !p.variant)
|
|
1004
|
-
return [` ${t("ui.link.accept.none", { id: h.id, question: truncate(h.question, 80) })}`];
|
|
993
|
+
return [` ${t("ui.link.accept.none", { id: h.id, question: truncate(humanClaim(tree, h.question), 80) })}`];
|
|
1005
994
|
const v = h.variants.find((x) => x.label === p.variant);
|
|
1006
995
|
const warn = changeWarning(lang, tree, h, v);
|
|
1007
996
|
if (warn)
|
|
1008
997
|
stays = true;
|
|
1009
998
|
const n = v && !warn ? branchJoined(tree, h, v) : 0;
|
|
1010
|
-
return [` ${t("ui.link.accept.variant", { id: h.id, variant: p.variant, claim: truncate(v?.claim ?? "", 80) })}${n ? ` ${t("ui.link.accept.joins", { n })}` : ""}`, ...(warn ? [` ${warn}`] : [])];
|
|
999
|
+
return [` ${t("ui.link.accept.variant", { id: h.id, variant: p.variant, claim: truncate(humanClaim(tree, v?.claim ?? ""), 80) })}${n ? ` ${t("ui.link.accept.joins", { n })}` : ""}`, ...(warn ? [` ${warn}`] : [])];
|
|
1011
1000
|
};
|
|
1012
1001
|
if (!take.length)
|
|
1013
1002
|
return stop(ctx, [t("ui.link.accept.nothing"), ...said].join("\n"));
|
|
@@ -16,7 +16,7 @@ import { displayName, lifespan } from "../core/people.js";
|
|
|
16
16
|
import { DEATH_AFTER_YEARS, unprovenPeople } from "../core/review.js";
|
|
17
17
|
import { planSync, readTreeFile, receivedAll, receivedSince, SYNC_INBOX } from "../core/sync.js";
|
|
18
18
|
import { undoSending } from "./menu-links.js";
|
|
19
|
-
import { humanWhen } from "./human.js";
|
|
19
|
+
import { humanClaim, humanWhen } from "./human.js";
|
|
20
20
|
import { truncate } from "./format.js";
|
|
21
21
|
import { appSendsChanges, stromAppState } from "../core/stromapp.js";
|
|
22
22
|
import { UNPROVEN_BATCH } from "../commands/research.js";
|
|
@@ -590,7 +590,7 @@ async function personHypotheses(ctx, run, lang, root, person) {
|
|
|
590
590
|
if (!all.length)
|
|
591
591
|
return;
|
|
592
592
|
const state = (h) => t(h.state === "open" ? (h.proposal && !actsAsArchive(tree) ? "ui.review.hypothesis.proposed" : "ui.review.hypothesis.open") : h.state === "decided" ? "ui.review.hypothesis.decided" : "ui.review.hypothesis.abandoned");
|
|
593
|
-
const i = await ctx.choose(t("ui.review.hypotheses.title"), all.map((h) => ({ label: `${h.id} · ${state(h)} · ${truncate(h.question, 70)}` })), all.length, { back: t("ui.browse.back") });
|
|
593
|
+
const i = await ctx.choose(t("ui.review.hypotheses.title"), all.map((h) => ({ label: `${h.id} · ${state(h)} · ${truncate(humanClaim(tree, h.question), 70)}` })), all.length, { back: t("ui.browse.back") });
|
|
594
594
|
if (i === undefined)
|
|
595
595
|
return;
|
|
596
596
|
await decideHypothesis(ctx, run, lang, root, all[i].id);
|
package/dist/cli/menu-waiting.js
CHANGED
|
@@ -30,7 +30,7 @@ import { agentDecided } from "../core/hypolinks.js";
|
|
|
30
30
|
import { normId } from "../core/records.js";
|
|
31
31
|
import { actsAsArchive } from "../core/state.js";
|
|
32
32
|
import { branchOf } from "../core/offline.js";
|
|
33
|
-
import { eventName, humanDay, humanTask } from "./human.js";
|
|
33
|
+
import { eventName, humanClaim, humanDay, humanTask } from "./human.js";
|
|
34
34
|
import { provenReviewSince, provenToReview } from "../core/provenfix.js";
|
|
35
35
|
import { conflictTitle, displayName, lifespan } from "../core/people.js";
|
|
36
36
|
import { claimOf, isEditConflict, sideText } from "../core/conflicts.js";
|
|
@@ -129,9 +129,9 @@ function daysSince(iso, now = Date.now()) {
|
|
|
129
129
|
function sentWords(t, lang, iso) {
|
|
130
130
|
return `${t("ui.wait.sentline", { day: humanDay(iso, lang), ago: ago(t, iso) })}${daysSince(iso) > NO_REPLY_DAYS ? ` · ${t("ui.wait.noreply", { days: NO_REPLY_DAYS })}` : ""}`;
|
|
131
131
|
}
|
|
132
|
-
/** What a thing is, short: a task's words as written, its records named (a person's ID after their name only bracketed). */
|
|
132
|
+
/** What a thing is, short: a task's words as written, its records named (a person's ID after their name only bracketed); a hypothesis's question its people named. */
|
|
133
133
|
function short(tree, lang, w) {
|
|
134
|
-
return w.task ? humanTask(tree, w.item.what, lang, { asWritten: true }) : w.item.what;
|
|
134
|
+
return w.task ? humanTask(tree, w.item.what, lang, { asWritten: true }) : w.hypothesis ? humanClaim(tree, w.item.what) : w.item.what;
|
|
135
135
|
}
|
|
136
136
|
const sentAtOf = (w) => String(w.item.sentAt ?? w.item.at);
|
|
137
137
|
/** The places of a list, in its order (the items of one place stand together). */
|
|
@@ -654,9 +654,9 @@ export async function decideHypothesis(ctx, run, lang, root, id) {
|
|
|
654
654
|
out([
|
|
655
655
|
"",
|
|
656
656
|
` ${h.id} · ${kindWord(t, "hypothesis")}${since ? ` · ${t("ui.wait.since", { day: humanDay(since, lang) })}` : ""}`,
|
|
657
|
-
` ${h.question}`,
|
|
657
|
+
` ${humanClaim(tree, h.question)}`,
|
|
658
658
|
...now,
|
|
659
|
-
...h.variants.map((v) => ` ${v.label}) ${v.claim}`),
|
|
659
|
+
...h.variants.map((v) => ` ${v.label}) ${humanClaim(tree, v.claim)}`),
|
|
660
660
|
...(proposed ? ["", ` ${proposed}`, ...(p.reason ? [` ${t("ui.wait.hypothesis.again", { reason: p.reason })}`] : [])] : []),
|
|
661
661
|
].join("\n"));
|
|
662
662
|
// a change the tree cannot follow (the earlier link stays, other work stands on it; the new one is not written): said
|
|
@@ -670,7 +670,7 @@ export async function decideHypothesis(ctx, run, lang, root, id) {
|
|
|
670
670
|
};
|
|
671
671
|
// another variant, or none holds — and why: the decision's words; a decided one decided again: the reason too
|
|
672
672
|
const otherwise = async () => {
|
|
673
|
-
const v = await ctx.choose(t("ui.wait.hypothesis.pick"), [...h.variants.map((x) => ({ label: `${x.label}) ${truncate(x.claim, 70)}` })), { label: t("ui.wait.hypothesis.none") }], h.variants.length + 1, { back: t("ui.browse.back") });
|
|
673
|
+
const v = await ctx.choose(t("ui.wait.hypothesis.pick"), [...h.variants.map((x) => ({ label: `${x.label}) ${truncate(humanClaim(tree, x.claim), 70)}` })), { label: t("ui.wait.hypothesis.none") }], h.variants.length + 1, { back: t("ui.browse.back") });
|
|
674
674
|
if (v === undefined)
|
|
675
675
|
return undefined;
|
|
676
676
|
if (v < h.variants.length && !(await goesOn(h.variants[v])))
|
|
@@ -838,10 +838,11 @@ register({
|
|
|
838
838
|
group: "analysis",
|
|
839
839
|
tree: true,
|
|
840
840
|
writes: true,
|
|
841
|
+
description: 'The question and each claim name the people of the tree by name with the ID ("Jan Lhoták (P0001)"), never the ID alone: the user decides by reading them.',
|
|
841
842
|
args: [{ name: "question", description: 'e.g. "Who was the father of Marie?"', required: true }],
|
|
842
843
|
options: [
|
|
843
844
|
{ name: "about", type: "string", multiple: true, value: "<who>", description: "person/record concerned (repeatable)" },
|
|
844
|
-
{ name: "variant", type: "string", multiple: true, value: "<A: claim>", description: 'a variant, e.g. "A:
|
|
845
|
+
{ name: "variant", type: "string", multiple: true, value: "<A: claim>", description: 'a variant, e.g. "A: the son of Jan Lhoták (P0001)" — a person of the tree by name with the ID (repeat)' },
|
|
845
846
|
{ name: "note", type: "string", value: "<text>", description: "short note" },
|
|
846
847
|
],
|
|
847
848
|
run(ctx, { args, opts }) {
|
|
@@ -908,7 +909,7 @@ register({
|
|
|
908
909
|
description: "A variant's letter stays one claim's (the Strom app remembers it): a claim that changes whom it would connect is a new variant.",
|
|
909
910
|
args: [
|
|
910
911
|
{ name: "hypothesis", description: "hypothesis ID (H0001)", required: true },
|
|
911
|
-
{ name: "claim", description: 'the claim, e.g. "the son of
|
|
912
|
+
{ name: "claim", description: 'the claim, e.g. "the son of Jan Lhoták (P0001)" — a person of the tree by name with the ID (or "C: …" with its letter)', required: true },
|
|
912
913
|
],
|
|
913
914
|
examples: ['strom hypothesis variant H0001 "syn Josefa z čp. 12"'],
|
|
914
915
|
run(ctx, { args }) {
|
|
@@ -23,7 +23,8 @@ import { verifyFast } from "../core/integrity.js";
|
|
|
23
23
|
import { addReaders } from "../core/session.js";
|
|
24
24
|
import { READER_MINUTES_HELP } from "../core/reader.js";
|
|
25
25
|
import { stamp } from "../core/net.js";
|
|
26
|
-
import { readerAgent,
|
|
26
|
+
import { readerAgent, readTeam } from "./readers.js";
|
|
27
|
+
import { readProvider } from "../core/readprovider.js";
|
|
27
28
|
import { RUNNERS } from "../runners/index.js";
|
|
28
29
|
import { EFFORTS } from "../agents/effort.js";
|
|
29
30
|
import { ownModel } from "../agents/models.js";
|
|
@@ -32,7 +33,7 @@ import { catalog } from "../core/phrases.js";
|
|
|
32
33
|
import { readerDefault } from "../core/readchoice.js";
|
|
33
34
|
import { heldAgainst, keepSourceReading, notAgain, originalPages, readingOfSource } from "../core/sourceread.js";
|
|
34
35
|
import { askOfReading } from "./source-reading.js";
|
|
35
|
-
import { alive, APP_READ_FROM, backBefore, beforeOf, buildResult, cancelPath, DOC_NEXT, DOC_PAGES, DOC_VIEWS, aboutFor, docPrompt, endState, FINAL_STATES, listReadings, loadState, newReadId, nextVersion, parseRegion, READ_ID, reportPath, resultPath, saveState, shownName, SMALL_PX, withoutDocNext, words, } from "../core/document.js";
|
|
36
|
+
import { alive, APP_READ_FROM, backBefore, beforeOf, buildResult, cancelPath, DOC_NEXT, linesPath, DOC_PAGES, DOC_VIEWS, aboutFor, docPrompt, endState, FINAL_STATES, listReadings, loadState, newReadId, nextVersion, parseRegion, READ_ID, reportPath, resultPath, saveState, shownName, SMALL_PX, withoutDocNext, words, } from "../core/document.js";
|
|
36
37
|
/** How often a reading at work looks whether it was cancelled (strom document cancel, from another process). */
|
|
37
38
|
const CANCEL_LOOK_MS = 500;
|
|
38
39
|
/** The image types a document is read from: a photo, a scan, a PDF (HEIC and PDF converted for the reader). */
|
|
@@ -125,6 +126,16 @@ function withOf(ctx, tree, opts) {
|
|
|
125
126
|
const str = (v) => (typeof v === "string" ? v.trim() : undefined);
|
|
126
127
|
const one = (at, agent, model, effort, like) => {
|
|
127
128
|
const pre = at ? "--blind-" : "--";
|
|
129
|
+
// a reading service (core/readprovider.ts): its model as asked (none: its own), no effort; the transcript alone
|
|
130
|
+
const service = readProvider(agent, ctx.env);
|
|
131
|
+
if (service?.kind === "service") {
|
|
132
|
+
if (!at && !opts.source)
|
|
133
|
+
throw new UsageError(`${service.title} reads the transcript alone: it is the second, blind reader of a document (--blind-agent ${agent}), or reads a source again (--source)`, { code: "read.with", params: { at: String(at), field: "agent" }, hint: `strom document read … --readers 2 --blind-agent ${agent}` });
|
|
134
|
+
if (effort)
|
|
135
|
+
throw new UsageError(`${service.title} takes no effort`, { code: "read.with", params: { at: String(at), field: "effort" }, hint: `leave ${pre}effort out` });
|
|
136
|
+
const m = model ?? (like?.agent === agent ? (like.model ?? "") : "");
|
|
137
|
+
return { agent, ...(m ? { model: m } : {}) };
|
|
138
|
+
}
|
|
128
139
|
if (!RUNNERS[agent])
|
|
129
140
|
throw new UsageError(`no reader of the agent "${agent.slice(0, 40)}"`, { code: "read.with", params: { at: String(at), field: "agent" }, hint: `${pre}agent ${Object.keys(RUNNERS).filter((a) => a !== "script").join("|")}` });
|
|
130
141
|
const dflt = like && like.agent === agent ? { model: like.model ?? "", effort: like.effort ?? "" } : readerDefault(tree, ctx.settings, agent, research);
|
|
@@ -378,7 +389,8 @@ async function readWith(ctx, tree, s, opts, only) {
|
|
|
378
389
|
return finish(ctx, tree, s, []);
|
|
379
390
|
}
|
|
380
391
|
// each reader as asked (s.with: the first, the blind one — its own agent, model, effort), else the research's readers
|
|
381
|
-
|
|
392
|
+
// (an agent's readers, or a reading service's: core/readprovider.ts)
|
|
393
|
+
const teamOf = (r) => readTeam(ctx, tree, shared, "document", "1", opts, undefined, { stem: s.id, ...(r ? { with: r } : {}) });
|
|
382
394
|
const first = only === "blind" ? undefined : teamOf(s.with?.[0]);
|
|
383
395
|
const blind = s.readers > 1 ? (first && sameReader(s.with?.[0], s.with?.[1]) ? first : teamOf(s.with?.[1])) : undefined;
|
|
384
396
|
const team = (first ?? blind);
|
|
@@ -415,12 +427,12 @@ async function readWith(ctx, tree, s, opts, only) {
|
|
|
415
427
|
return;
|
|
416
428
|
const n = next++;
|
|
417
429
|
const by = (job.blind ? blind : first);
|
|
418
|
-
s = { ...s, reports: [...s.reports, { n, group: job.group, blind: job.blind, version: s.version, agent: by.agent, ...(by.model ? { model: by.model } : {}), ...(by.effort ? { effort: by.effort } : {}), began: now() }] };
|
|
430
|
+
s = { ...s, reports: [...s.reports, { n, group: job.group, blind: job.blind, version: s.version, agent: by.agent, ...(by.model ? { model: by.model } : {}), ...(by.effort ? { effort: by.effort } : {}), ...(by.kind ? { kind: by.kind } : {}), began: now() }] };
|
|
419
431
|
saveState(tree.root, s);
|
|
420
432
|
const mine = viewsBy.get(by).filter((v) => s.groups[job.group].includes(v.n));
|
|
421
433
|
const files = mine.flatMap((v) => [v.view, ...(v.parts ?? []).map((x) => x.view)]);
|
|
422
434
|
const head = `# Document ${s.id} · reader ${n}${job.blind ? " (blind)" : ""}\n\nPages: ${mine.map((v) => v.n).join(", ")}\n\n${DOC_NEXT}\n`;
|
|
423
|
-
const r = await by.read(String(n), files, `Document ${s.id}`, (report) => docPrompt({ pages: mine, report, lang: s.lang, note: s.note, blind: job.blind, source: about && aboutFor(about, by.agent, by.model) }), { head, signal: stop.signal });
|
|
435
|
+
const r = await by.read(String(n), files, `Document ${s.id}`, (report) => docPrompt({ pages: mine, report, lang: s.lang, note: s.note, blind: job.blind, source: about && aboutFor(about, by.agent, by.model) }), { head, signal: stop.signal, doc: { pages: mine, source: about } });
|
|
424
436
|
try {
|
|
425
437
|
fs.writeFileSync(r.report, withoutDocNext(fs.readFileSync(r.report, "utf8")).replace(/\n*$/u, "\n"));
|
|
426
438
|
}
|
|
@@ -429,7 +441,7 @@ async function readWith(ctx, tree, s, opts, only) {
|
|
|
429
441
|
}
|
|
430
442
|
s = {
|
|
431
443
|
...s,
|
|
432
|
-
reports: s.reports.map((x) => (x.n === n ? { ...x, outcome: r.outcome, ended: now(), ...(r.costUsd !== undefined ? { usd: r.costUsd } : {}), ...(r.costPartial || r.costUsd === undefined ? { partial: true } : {}), ...(r.resumeAt ? { resets: r.resumeAt } : {}), ...(r.modelRejected ? { rejected: "model" } : {}) } : x)),
|
|
444
|
+
reports: s.reports.map((x) => (x.n === n ? { ...x, outcome: r.outcome, ended: now(), ...(r.costUsd !== undefined ? { usd: r.costUsd } : {}), ...(r.costPartial || (r.costUsd === undefined && r.credits === undefined) ? { partial: true } : {}), ...(r.credits !== undefined ? { credits: r.credits } : {}), ...(r.resumeAt ? { resets: r.resumeAt } : {}), ...(r.modelRejected ? { rejected: "model" } : {}) } : x)),
|
|
433
445
|
};
|
|
434
446
|
saveState(tree.root, s);
|
|
435
447
|
};
|
|
@@ -544,7 +556,7 @@ function finish(ctx, tree, s, ran, spent, back = false) {
|
|
|
544
556
|
persist();
|
|
545
557
|
}
|
|
546
558
|
const session = spent?.runs ? addReaders(tree, ctx.env, ctx.refs, { usd: spent.usd, runs: spent.runs, partial: spent.partial }) : undefined;
|
|
547
|
-
const files = [resultPath(tree.root, s.id), ...s.reports.
|
|
559
|
+
const files = [resultPath(tree.root, s.id), ...s.reports.flatMap((r) => [reportPath(tree.root, s.id, r.n), linesPath(tree.root, s.id, r.n)])].filter((f) => fs.existsSync(f)).map((f) => tree.relative(f));
|
|
548
560
|
tree.commit(`Reading of a document ${s.id}${back ? ", read again and cancelled" : ""}${s.version > 1 ? `, version ${s.version}` : ""}: ${s.state}${result.entries.length ? `, ${counted(result.entries.length, "entry", "entries")}` : ""}${kept ? ` — ${kept.id} read again from its original, ${kept.agree === "same" ? "alike its transcript" : "differs from its transcript"}` : ""}`, [...files, ...(session || kept ? ["data"] : [])]);
|
|
549
561
|
});
|
|
550
562
|
}
|
|
@@ -617,7 +629,7 @@ function whoSaid(r) {
|
|
|
617
629
|
const who = r.readers.who;
|
|
618
630
|
if (!who?.length)
|
|
619
631
|
return undefined;
|
|
620
|
-
const one = (w, i) => `${[w.agent, w.model, w.effort].filter(Boolean).join(" · ")}${i > 0 ? " (blind)" : ""}${w.ran === false ? " — not read to an end" : ""}`;
|
|
632
|
+
const one = (w, i) => `${[w.agent, w.model, w.effort].filter(Boolean).join(" · ")}${w.kind === "service" ? ` (a reading service: the transcript alone${w.credits !== undefined ? `, ${w.credits} credits` : ""})` : ""}${i > 0 ? " (blind)" : ""}${w.ran === false ? " — not read to an end" : ""}`;
|
|
621
633
|
return `who: ${who.map(one).join(" / ")}`;
|
|
622
634
|
}
|
|
623
635
|
/** A source read again from its original: whether the new reading is alike its transcript, where not and the task. */
|
package/dist/commands/readers.js
CHANGED
|
@@ -22,6 +22,8 @@ import { currentSession } from "../core/session.js";
|
|
|
22
22
|
import { noReaderHere, refusedBySandbox, sandboxOf } from "../core/sandbox.js";
|
|
23
23
|
import { VERSION } from "../core/tree.js";
|
|
24
24
|
import { refuseInArchive } from "../core/state.js";
|
|
25
|
+
import { readProvider } from "../core/readprovider.js";
|
|
26
|
+
import { linesPathOf, within } from "../core/document.js";
|
|
25
27
|
/**
|
|
26
28
|
* The agent of the readers: one named for this command (--agent, STROM_AGENT), else the agent the session at work was
|
|
27
29
|
* started with (strom run --agent, a conversation of another agent), else the tree's.
|
|
@@ -307,3 +309,185 @@ export function readers(ctx, tree, shared, kind, first, opts, reportsAt, own = {
|
|
|
307
309
|
};
|
|
308
310
|
return { agent: agentId, model, effort, viewMax: sizes.read, viewMin: sizes.min, viewLift: sizes.max, parallel, stem, reportsDir, read, cost: () => cost, runs: () => runs, partial: () => partial, failed, progress };
|
|
309
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* The readers of a reading as asked (`own.with`): a reading service's (core/readprovider.ts kind "service":
|
|
314
|
+
* serviceReaders), else an agent's (readers()) — one shape for both, so a reading goes on as it is with either.
|
|
315
|
+
*/
|
|
316
|
+
export function readTeam(ctx, tree, shared, kind, first, opts, reportsAt, own = {}) {
|
|
317
|
+
const p = own.with ? readProvider(own.with.agent, ctx.env) : undefined;
|
|
318
|
+
if (p?.kind === "service")
|
|
319
|
+
return serviceReaders(ctx, tree, shared, kind, p, opts, reportsAt, own);
|
|
320
|
+
return readers(ctx, tree, shared, kind, first, opts, reportsAt, own);
|
|
321
|
+
}
|
|
322
|
+
/** The longest side of an image a service is given where it says none: the original's, as it is (never enlarged). */
|
|
323
|
+
const SERVICE_MAX_SIDE = 12_000;
|
|
324
|
+
/** The minutes a service may take for one reader (all its pages) where --minutes says none. */
|
|
325
|
+
const SERVICE_MINUTES = 10;
|
|
326
|
+
/** What the research knows of a source read again, as a service is told it (never a transcript or a name). */
|
|
327
|
+
function contextOf(about) {
|
|
328
|
+
if (!about)
|
|
329
|
+
return {};
|
|
330
|
+
return { ...(about.kind ? { kind: about.kind } : {}), ...(about.language ? { language: about.language } : {}), ...(about.date ? { date: about.date } : {}), ...(about.locator ? { locator: about.locator } : {}) };
|
|
331
|
+
}
|
|
332
|
+
/** The place of the lines of a view on its page: their box (fractions of the view) of the whole page. */
|
|
333
|
+
function onPage(view, box) {
|
|
334
|
+
const part = view.shows ?? view.region;
|
|
335
|
+
return part ? within(part, box) : box;
|
|
336
|
+
}
|
|
337
|
+
/** Where all the lines of a view stand together (fractions of the view), none when a line says not where. */
|
|
338
|
+
function around(lines) {
|
|
339
|
+
if (!lines.length || lines.some((l) => !l.box))
|
|
340
|
+
return undefined;
|
|
341
|
+
const x0 = Math.min(...lines.map((l) => l.box[0]));
|
|
342
|
+
const y0 = Math.min(...lines.map((l) => l.box[1]));
|
|
343
|
+
const x1 = Math.max(...lines.map((l) => l.box[0] + l.box[2]));
|
|
344
|
+
const y1 = Math.max(...lines.map((l) => l.box[1] + l.box[3]));
|
|
345
|
+
const r = (n) => Math.round(n * 10000) / 10000;
|
|
346
|
+
return [r(x0), r(y0), r(Math.min(1, x1) - x0), r(Math.min(1, y1) - y0)];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* The readers of a reading service: each page's view given to it alone in its own work folder (`read()`), what it
|
|
350
|
+
* read written as a reader's report of today's form — the document block (legible), one entry of each page with its
|
|
351
|
+
* transcript and where it stands, the done line — and its lines with where they stand beside it (<report>.lines.json,
|
|
352
|
+
* fractions of the page). A service reads the transcript alone: no translation, no people (core/readprovider.ts).
|
|
353
|
+
*/
|
|
354
|
+
function serviceReaders(ctx, tree, shared, kind, p, opts, reportsAt, own) {
|
|
355
|
+
refuseInArchive(tree, `strom ${kind}`);
|
|
356
|
+
refuseReadersWhenFinishing(tree.root, ctx.env);
|
|
357
|
+
const ready = p.ready(ctx.env);
|
|
358
|
+
if (!ready.ready || !p.read)
|
|
359
|
+
throw new UsageError(`${p.title} cannot read now (${ready.why ?? "it reads nothing"})`, { code: "read.agent", params: { agent: p.id, why: ready.why ?? "" }, hint: "another reader: --blind-agent <agent>" });
|
|
360
|
+
const readOne = p.read.bind(p);
|
|
361
|
+
const model = own.with?.model || undefined;
|
|
362
|
+
const minutesSaid = opts.minutes === undefined ? undefined : Number(opts.minutes);
|
|
363
|
+
if (minutesSaid !== undefined && !(minutesSaid > 0))
|
|
364
|
+
throw new UsageError(`invalid --minutes "${String(opts.minutes)}"`, { hint: "the minutes one reader may take, e.g. 10" });
|
|
365
|
+
const minutes = minutesSaid ?? SERVICE_MINUTES;
|
|
366
|
+
const reportsDir = reportsAt ?? path.join(tree.root, "notes", "readings");
|
|
367
|
+
fs.mkdirSync(reportsDir, { recursive: true });
|
|
368
|
+
const day = new Date().toISOString().slice(0, 10);
|
|
369
|
+
const stem = own.stem ?? claimStem(tree.root, kind, `${day}-${kind}`, (s) => fs.existsSync(path.join(reportsDir, `${s}-1-1.md`)));
|
|
370
|
+
const progress = (s) => (ctx.json ? ctx.io.stderr : ctx.io.stdout)(s + "\n");
|
|
371
|
+
const parallel = opts.parallel === undefined ? 3 : Math.max(1, Number(opts.parallel) || 1);
|
|
372
|
+
let cost = 0;
|
|
373
|
+
let runs = 0;
|
|
374
|
+
let partial = false;
|
|
375
|
+
const failed = [];
|
|
376
|
+
const read = async (name, views, title, _prompt, more = {}) => {
|
|
377
|
+
const report = path.join(reportsDir, `${stem}-${name}.md`);
|
|
378
|
+
const work = readerRoomDir(shared, `${stem}-${name}`);
|
|
379
|
+
fs.writeFileSync(report, more.head ?? `# ${title}\nStrom: ${VERSION}\nReader: ${p.id} (service)\n\n`);
|
|
380
|
+
const pages = more.doc?.pages ?? views.map((v, i) => ({ n: i + 1, view: v }));
|
|
381
|
+
const startedAt = Date.now();
|
|
382
|
+
const stop = new AbortController();
|
|
383
|
+
const timer = setTimeout(() => stop.abort(), minutes * 60_000);
|
|
384
|
+
timer.unref?.();
|
|
385
|
+
const onCancel = () => stop.abort();
|
|
386
|
+
more.signal?.addEventListener("abort", onCancel, { once: true });
|
|
387
|
+
const entries = [];
|
|
388
|
+
const kept = [];
|
|
389
|
+
const unreadable = [];
|
|
390
|
+
let outcome = "ok";
|
|
391
|
+
let why;
|
|
392
|
+
let resets;
|
|
393
|
+
let said;
|
|
394
|
+
let usd;
|
|
395
|
+
let credits;
|
|
396
|
+
let costPartial = false;
|
|
397
|
+
try {
|
|
398
|
+
for (const view of pages) {
|
|
399
|
+
if (stop.signal.aborted)
|
|
400
|
+
break;
|
|
401
|
+
const image = path.join(work, `page-${view.n}${path.extname(view.view) || ".jpg"}`);
|
|
402
|
+
fs.copyFileSync(view.view, image);
|
|
403
|
+
let out;
|
|
404
|
+
try {
|
|
405
|
+
const ended = new Promise((resolve) => stop.signal.addEventListener("abort", () => resolve({ outcome: "stopped", transcript: "", lines: [] }), { once: true }));
|
|
406
|
+
out = await Promise.race([readOne({ image, page: view.n, ...(view.region ? { region: view.region } : {}), context: contextOf(more.doc?.source), ...(model ? { model } : {}) }, { env: ctx.env, work, signal: stop.signal }), ended]);
|
|
407
|
+
}
|
|
408
|
+
catch (e) {
|
|
409
|
+
out = { outcome: "error", transcript: "", lines: [], why: e instanceof Error ? e.message : String(e) };
|
|
410
|
+
}
|
|
411
|
+
if (out.model)
|
|
412
|
+
said = out.model;
|
|
413
|
+
if (out.cost) {
|
|
414
|
+
if (out.cost.unit === "usd")
|
|
415
|
+
usd = (usd ?? 0) + out.cost.amount;
|
|
416
|
+
else
|
|
417
|
+
credits = (credits ?? 0) + out.cost.amount;
|
|
418
|
+
if (out.cost.partial)
|
|
419
|
+
costPartial = true;
|
|
420
|
+
}
|
|
421
|
+
if (out.outcome === "unreadable") {
|
|
422
|
+
unreadable.push(out.why ?? "other");
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (out.outcome !== "ok") {
|
|
426
|
+
outcome = out.outcome === "stopped" && !more.signal?.aborted ? "timeout" : out.outcome;
|
|
427
|
+
why = out.why;
|
|
428
|
+
resets = out.resets;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
if (!out.transcript.trim() && !out.lines.length) {
|
|
432
|
+
unreadable.push("other");
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
// its text regions (a register's entries) each an entry, in their order; none said: all its lines one entry
|
|
436
|
+
const blocks = out.lines.length && out.lines.every((l) => l.block !== undefined) ? [...new Set(out.lines.map((l) => l.block))].sort((a, b) => a - b).map((k) => out.lines.filter((l) => l.block === k)) : [out.lines];
|
|
437
|
+
for (const ls of blocks) {
|
|
438
|
+
const text = blocks.length > 1 ? ls.map((l) => l.text).join(" | ") : out.transcript;
|
|
439
|
+
if (!text.trim())
|
|
440
|
+
continue;
|
|
441
|
+
const box = around(ls);
|
|
442
|
+
entries.push(`## Entry e${entries.length + 1} · page ${view.n}\n${box ? `region: ${box.join(",")}\n` : ""}transcript: ${text.replace(/\s*\n\s*/gu, " | ")}\n`);
|
|
443
|
+
}
|
|
444
|
+
kept.push({ page: view.n, lines: out.lines.map((l) => ({ text: l.text, ...(l.box ? { box: onPage(view, l.box) } : {}), ...(l.confidence !== undefined ? { confidence: l.confidence } : {}), ...(l.block !== undefined ? { block: l.block } : {}) })) });
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
finally {
|
|
448
|
+
clearTimeout(timer);
|
|
449
|
+
more.signal?.removeEventListener("abort", onCancel);
|
|
450
|
+
leaveReaderRoom(work);
|
|
451
|
+
}
|
|
452
|
+
if (outcome === "ok" && stop.signal.aborted)
|
|
453
|
+
outcome = more.signal?.aborted ? "stopped" : "timeout";
|
|
454
|
+
const legible = !unreadable.length ? "yes" : entries.length ? "partly" : "no";
|
|
455
|
+
const body = [`## Document\nlegible: ${legible}\n${legible !== "yes" ? `why: ${unreadable[0]}\n` : ""}`, ...entries, ...(outcome === "ok" ? [`done: ${entries.length} entries\n`] : [])].join("\n");
|
|
456
|
+
fs.appendFileSync(report, body);
|
|
457
|
+
if (kept.length)
|
|
458
|
+
fs.writeFileSync(linesPathOf(report), JSON.stringify({ protocol: 1, provider: p.id, kind: "service", ...(said ?? model ? { model: said ?? model } : {}), pages: kept }, null, 2) + "\n");
|
|
459
|
+
const ranMs = Date.now() - startedAt;
|
|
460
|
+
recordReader(tree, ctx.env, {
|
|
461
|
+
reader: `${kind}-${stem}-${name}`,
|
|
462
|
+
kind,
|
|
463
|
+
agent: p.id,
|
|
464
|
+
provider: "service",
|
|
465
|
+
key: model ? `${p.id} ${model}` : p.id,
|
|
466
|
+
model,
|
|
467
|
+
reported: said,
|
|
468
|
+
views: pages.length,
|
|
469
|
+
viewFiles: pages.map((v) => path.basename(v.view)),
|
|
470
|
+
px: pages.reduce((n, v) => {
|
|
471
|
+
const s = imageSizeOfFile(v.view);
|
|
472
|
+
return n + (s ? s.width * s.height : 0);
|
|
473
|
+
}, 0),
|
|
474
|
+
outcome,
|
|
475
|
+
usd,
|
|
476
|
+
...(credits !== undefined ? { credits } : {}),
|
|
477
|
+
...(costPartial ? { usdPartial: true } : {}),
|
|
478
|
+
ms: ranMs,
|
|
479
|
+
wallMs: ranMs,
|
|
480
|
+
minutes,
|
|
481
|
+
minutesFrom: minutesSaid !== undefined ? "option" : "default",
|
|
482
|
+
report: tree.relative(report),
|
|
483
|
+
});
|
|
484
|
+
cost += usd ?? 0;
|
|
485
|
+
runs++;
|
|
486
|
+
if (costPartial || (usd === undefined && credits === undefined))
|
|
487
|
+
partial = true;
|
|
488
|
+
if (outcome !== "ok")
|
|
489
|
+
failed.push(`${name} (${outcome === "timeout" ? ui(readersLang(ctx, tree), "ui.read.failed.timeout", { minutes }) : outcome}${why && outcome !== "timeout" ? `: ${why}` : ""})`);
|
|
490
|
+
return { report, text: fs.readFileSync(report, "utf8"), outcome, ...(usd !== undefined ? { costUsd: usd } : {}), ...(costPartial ? { costPartial: true } : {}), ...(credits !== undefined ? { credits } : {}), ...(resets ? { resumeAt: resets } : {}) };
|
|
491
|
+
};
|
|
492
|
+
return { agent: p.id, kind: "service", model, effort: undefined, viewMax: p.maxSide ?? SERVICE_MAX_SIDE, viewMin: 1, viewLift: 0, parallel, stem, reportsDir, read, cost: () => cost, runs: () => runs, partial: () => partial, failed, progress };
|
|
493
|
+
}
|
package/dist/commands/session.js
CHANGED
|
@@ -15,7 +15,7 @@ import { register } from "../cli/registry.js";
|
|
|
15
15
|
import { ui } from "../cli/ui.js";
|
|
16
16
|
import { addressesPerson } from "../core/impersonal.js";
|
|
17
17
|
import { counted, lines, shellArg, table, truncate } from "../cli/format.js";
|
|
18
|
-
import { NeedsConsentError, UsageError, StromError } from "../core/errors.js";
|
|
18
|
+
import { NeedsConsentError, TaskTaken, UsageError, StromError } from "../core/errors.js";
|
|
19
19
|
import { closeSession, costPartial, currentSession, openSessions, othersAtWork, sessionCost, sessionNote, startSession, whichSession, withReaders } from "../core/session.js";
|
|
20
20
|
import { reviveLive } from "../core/live.js";
|
|
21
21
|
import { cutDenied, DENIED_KEPT, DENIED_KEPT_CHARS } from "../core/report.js";
|
|
@@ -1036,6 +1036,10 @@ register(updatedDuringRun({
|
|
|
1036
1036
|
// The plan's limits as the agent said them last (Claude Code), for the gate; and the window a cap of the gate holds.
|
|
1037
1037
|
let lastLimits;
|
|
1038
1038
|
let watch;
|
|
1039
|
+
// tasks another agent took between reading the queue and starting the session (core/session.ts TaskTaken): each
|
|
1040
|
+
// time the next free one, the gate not asked again for it — a bound only against a loop nobody would see end
|
|
1041
|
+
let collisions = 0;
|
|
1042
|
+
let retaken = false;
|
|
1039
1043
|
let stopCode = "done";
|
|
1040
1044
|
let stopValues = {};
|
|
1041
1045
|
// The first Ctrl-C while a session works: it is asked to finish (the agent writes down what it found and closes
|
|
@@ -1199,7 +1203,7 @@ register(updatedDuringRun({
|
|
|
1199
1203
|
// itself. Tasks the user started themselves: asked once, and the user decides when it would not start.
|
|
1200
1204
|
// A gate with a cap (the user's own hard stop, its answer's "watch") is asked before every session, also of the
|
|
1201
1205
|
// tasks the user started: there only its hard stop counts, and no "start anyway" goes past it.
|
|
1202
|
-
if (gate && (!gateAnswered || watch)) {
|
|
1206
|
+
if (gate && (!gateAnswered || watch) && !retaken) {
|
|
1203
1207
|
const facts = { tree: root, lang, agent: runnerId, model: models.lead, sessions: report.length, costUsd: report.reduce((a, r) => a + (r.costUsd ?? 0), 0), nextTask: task.id, limits: lastLimits };
|
|
1204
1208
|
const said = askGate(gate, runEnv, facts);
|
|
1205
1209
|
const asked = gateRecord(gate, said, { ...facts, run: worker });
|
|
@@ -1286,7 +1290,22 @@ register(updatedDuringRun({
|
|
|
1286
1290
|
else
|
|
1287
1291
|
noted("go");
|
|
1288
1292
|
}
|
|
1289
|
-
|
|
1293
|
+
let session;
|
|
1294
|
+
try {
|
|
1295
|
+
session = startSession(tree, { task, ...(research ? { research: research.id } : {}), runner: runnerId, ...(models.lead ? { model: models.lead } : {}), ...(said.effort ? { effort: said.effort } : {}) });
|
|
1296
|
+
}
|
|
1297
|
+
catch (e) {
|
|
1298
|
+
// The queue is read outside the tree's lock: a run beside this one or a conversation may have taken the task
|
|
1299
|
+
// meanwhile. Never the end of the run — the next free task (a task the user named: left out, as when held).
|
|
1300
|
+
if (!(e instanceof TaskTaken) || ++collisions > 100)
|
|
1301
|
+
throw e;
|
|
1302
|
+
out(ui(lang, "ui.run.skip.held", { task: task.id }));
|
|
1303
|
+
retaken = true;
|
|
1304
|
+
if (i >= picked.length)
|
|
1305
|
+
i--;
|
|
1306
|
+
continue;
|
|
1307
|
+
}
|
|
1308
|
+
retaken = false;
|
|
1290
1309
|
commitNow(tree, `${session.id} session started on ${task.id}`);
|
|
1291
1310
|
// what the gate answered before it (the waits too), at the head of the session's log
|
|
1292
1311
|
if (gateTrail.length) {
|
package/dist/core/document.js
CHANGED
|
@@ -883,7 +883,7 @@ function pairByName(mine, theirs) {
|
|
|
883
883
|
* and order (given name, surname), the events by type and order (date, place). Where they differ is a variant of the
|
|
884
884
|
* entry; an entry only one of them has differs whole. of: each blind entry (its index) → the first one's it was held against.
|
|
885
885
|
*/
|
|
886
|
-
export function compareReadings(first, blind) {
|
|
886
|
+
export function compareReadings(first, blind, o = {}) {
|
|
887
887
|
let all = true;
|
|
888
888
|
const pairs = pairEntries(first, blind);
|
|
889
889
|
const of = new Map();
|
|
@@ -899,6 +899,9 @@ export function compareReadings(first, blind) {
|
|
|
899
899
|
else {
|
|
900
900
|
for (const d of wordDiff(e.transcript, b.transcript))
|
|
901
901
|
variants.push({ field: "transcript", ...d });
|
|
902
|
+
}
|
|
903
|
+
// a reading service read one of the two (core/readprovider.ts: the transcript alone): only the transcripts compared
|
|
904
|
+
if (b && !o.transcriptOnly) {
|
|
902
905
|
const groups = (ps) => {
|
|
903
906
|
const m = new Map();
|
|
904
907
|
for (const p of ps)
|
|
@@ -1164,6 +1167,14 @@ export function cancelPath(root, id) {
|
|
|
1164
1167
|
export function reportPath(root, id, n) {
|
|
1165
1168
|
return path.join(root, "notes", "readings", `${id}-${n}.md`);
|
|
1166
1169
|
}
|
|
1170
|
+
/** The lines a reading service read, with where they stand, beside its report: notes/readings/<id>-<n>.lines.json. */
|
|
1171
|
+
export function linesPath(root, id, n) {
|
|
1172
|
+
return linesPathOf(reportPath(root, id, n));
|
|
1173
|
+
}
|
|
1174
|
+
/** The file of a report's lines beside it (<report>.md → <report>.lines.json). */
|
|
1175
|
+
export function linesPathOf(report) {
|
|
1176
|
+
return report.replace(/\.md$/u, "") + ".lines.json";
|
|
1177
|
+
}
|
|
1167
1178
|
export function resultPath(root, id) {
|
|
1168
1179
|
return path.join(root, "notes", "readings", `${id}.json`);
|
|
1169
1180
|
}
|
|
@@ -1315,7 +1326,8 @@ export function buildResult(tree, s) {
|
|
|
1315
1326
|
let blind;
|
|
1316
1327
|
if (blindRan && s.readers > 1 && firstRead) {
|
|
1317
1328
|
const blindEntries = entriesOf(blinds, true);
|
|
1318
|
-
|
|
1329
|
+
// a reading service read one of them (the transcript alone, no people): only their transcripts held against each other
|
|
1330
|
+
const c = compareReadings(entries, blindEntries, { transcriptOnly: [...firsts, ...blinds].some((r) => r?.kind === "service") });
|
|
1319
1331
|
entries = c.entries;
|
|
1320
1332
|
agree = c.agree;
|
|
1321
1333
|
if (blindEntries.length)
|
|
@@ -1344,7 +1356,9 @@ export function buildResult(tree, s) {
|
|
|
1344
1356
|
const ran = (firsts.some(said) ? 1 : 0) + (blinds.some(said) ? 1 : 0);
|
|
1345
1357
|
const who = whoRead(s, [firsts, blinds], (rs) => rs.some(said), s.state === "reading" || s.state === "queued");
|
|
1346
1358
|
const usd = s.reports.reduce((n, r) => n + (r.usd ?? 0), 0);
|
|
1347
|
-
|
|
1359
|
+
// a service says what it cost in its own credits, not in dollars: no reason to say the dollars are "at least"
|
|
1360
|
+
const partial = s.reports.some((r) => r.outcome !== undefined && ((r.usd === undefined && r.credits === undefined) || r.partial));
|
|
1361
|
+
const credits = s.reports.some((r) => r.credits !== undefined) ? Math.round(s.reports.reduce((n, r) => n + (r.credits ?? 0), 0) * 100) / 100 : undefined;
|
|
1348
1362
|
return {
|
|
1349
1363
|
id: s.id,
|
|
1350
1364
|
state: s.state,
|
|
@@ -1365,7 +1379,7 @@ export function buildResult(tree, s) {
|
|
|
1365
1379
|
...(incomplete.length ? { incomplete: [...new Set(incomplete)].sort((a, b) => a - b) } : {}),
|
|
1366
1380
|
...(s.persons?.length ? { persons: s.persons } : {}),
|
|
1367
1381
|
...(s.note ? { note: s.note } : {}),
|
|
1368
|
-
...(usd || s.reports.some((r) => r.usd !== undefined) ? { cost: { amount: Math.round(usd * 100) / 100, currency: "USD", ...(partial ? { partial: true } : {}) } } : {}),
|
|
1382
|
+
...(usd || s.reports.some((r) => r.usd !== undefined) || credits !== undefined ? { cost: { amount: Math.round(usd * 100) / 100, currency: "USD", ...(partial ? { partial: true } : {}), ...(credits !== undefined ? { credits } : {}) } } : {}),
|
|
1369
1383
|
...(s.error ? { error: s.error } : {}),
|
|
1370
1384
|
...(s.failure ? { failure: s.failure } : {}),
|
|
1371
1385
|
};
|
|
@@ -1427,7 +1441,11 @@ function whoRead(s, reports, read, atWork) {
|
|
|
1427
1441
|
const effort = r ? r.effort : asked?.effort;
|
|
1428
1442
|
const state = readerState(s, reports[i], read, atWork);
|
|
1429
1443
|
const secs = state === "done" ? readerSecs(reports[i]) : undefined;
|
|
1430
|
-
|
|
1444
|
+
// a reading service: said so, and the credits of its account it cost
|
|
1445
|
+
const service = r ? r.kind === "service" : false;
|
|
1446
|
+
const mine = reports[i].filter((x) => !!x && x.credits !== undefined);
|
|
1447
|
+
const credits = mine.length ? Math.round(mine.reduce((n, x) => n + x.credits, 0) * 100) / 100 : undefined;
|
|
1448
|
+
out.push({ agent, ...(model ? { model } : {}), ...(effort ? { effort } : {}), ...(ended && !read(reports[i]) ? { ran: false } : {}), ...(state ? { state } : {}), ...(secs !== undefined ? { secs } : {}), ...(service ? { kind: "service" } : {}), ...(credits !== undefined ? { credits } : {}) });
|
|
1431
1449
|
}
|
|
1432
1450
|
return out;
|
|
1433
1451
|
}
|
package/dist/core/errors.js
CHANGED
|
@@ -87,6 +87,20 @@ export class DirectionExists extends UsageError {
|
|
|
87
87
|
return { ...super.toJSON(), existing: this.existing };
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* A task another agent's session holds already: taken after the one who asked read the queue (a run beside it, a
|
|
92
|
+
* conversation). strom run takes the next free task instead; the session in `session`.
|
|
93
|
+
*/
|
|
94
|
+
export class TaskTaken extends UsageError {
|
|
95
|
+
task;
|
|
96
|
+
session;
|
|
97
|
+
constructor(task, session, agent) {
|
|
98
|
+
super(`${task} is being worked on in session ${session}${agent ? ` (${agent})` : ""}`, { hint: "take another task: strom session start (the next free one)" });
|
|
99
|
+
this.name = "TaskTaken";
|
|
100
|
+
this.task = task;
|
|
101
|
+
this.session = session;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
90
104
|
/**
|
|
91
105
|
* A file or folder that is not there, the same words wherever a path was given (a person's in their language: ui.error.fs.missing).
|
|
92
106
|
*/
|
package/dist/core/readchoice.js
CHANGED
|
@@ -150,5 +150,8 @@ export function whoForApp(who, full) {
|
|
|
150
150
|
...(r.ran === false ? { ran: false } : {}),
|
|
151
151
|
...(r.state ? { state: r.state } : {}),
|
|
152
152
|
...(r.secs !== undefined ? { secs: r.secs } : {}),
|
|
153
|
+
// a reading service read (the transcript alone) and the credits of its account it cost: an older app leaves them
|
|
154
|
+
...(r.kind ? { kind: r.kind } : {}),
|
|
155
|
+
...(r.credits !== undefined ? { credits: r.credits } : {}),
|
|
153
156
|
}));
|
|
154
157
|
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// A provider of reading: who reads a scan for strom. One contract for both kinds:
|
|
2
|
+
//
|
|
3
|
+
// - "agent": a run of an AI agent through its runner (src/runners) — it is given a prompt with the paths of its views
|
|
4
|
+
// and writes its report in Markdown (core/document.ts docPrompt, parseDocReport). Every agent of RUNNERS is one;
|
|
5
|
+
// their readers stay what they were (commands/readers.ts readers()).
|
|
6
|
+
// - "service": a reading service (a handwriting recognition service, HTR) — it is given one image and what the
|
|
7
|
+
// research knows of the source (never its transcript, never a name), and gives back a transcript and its lines with
|
|
8
|
+
// where they stand. No prompt, no translation, no people: it reads the transcript alone (can).
|
|
9
|
+
//
|
|
10
|
+
// A service reads through `read()`; strom writes what it gives as a reader's report of today's form (only the
|
|
11
|
+
// transcript: commands/readers.ts serviceReaders), so comparing readers, holding a reading against a source's
|
|
12
|
+
// transcript, the grade of a reading and the bridge go on as they are. Its lines are kept beside the report
|
|
13
|
+
// (notes/readings/<D>-<n>.lines.json).
|
|
14
|
+
//
|
|
15
|
+
// The contract is made to run later as a plugin through the connectors as well (JSON lines, its input a file in its
|
|
16
|
+
// own work folder): `requestLine` is what such a plugin is given on its stdin, `parseReply` reads what it says on its
|
|
17
|
+
// stdout — {"line": {…}} for each line, then {"done": {…}} (or {"error": {…}}). The fake service of the tests
|
|
18
|
+
// (STROM_READ_FAKE) already reads through them: its answer file is such a reply.
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { RUNNERS } from "../runners/index.js";
|
|
22
|
+
import { AGENTS, findAgent } from "./which.js";
|
|
23
|
+
import { BUILTIN_MODELS } from "../agents/models.js";
|
|
24
|
+
export const READ_OUTCOMES = ["ok", "unreadable", "auth", "limit", "timeout", "stopped", "error"];
|
|
25
|
+
// ── the agents ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
26
|
+
/** An agent of RUNNERS as a provider of reading: it reads all a document says, through its runner. */
|
|
27
|
+
function agentProvider(id) {
|
|
28
|
+
const known = AGENTS.find((a) => a.id === id);
|
|
29
|
+
return {
|
|
30
|
+
id,
|
|
31
|
+
kind: "agent",
|
|
32
|
+
title: known?.name ?? id,
|
|
33
|
+
can: ["transcript", "translate", "persons"],
|
|
34
|
+
// the script runner of the tests is always here; an agent when its CLI is on PATH
|
|
35
|
+
ready: (env) => (!known || findAgent(known.command, env) ? { ready: true } : { ready: false, why: "not-installed" }),
|
|
36
|
+
models: () => (BUILTIN_MODELS[id] ?? []).map((m) => ({ id: m.id, name: m.label ?? m.id })),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// ── the protocol of a service (a plugin later: JSON lines) ───────────────────────────────────────────────────────
|
|
40
|
+
/** Version of the request and reply a service is given and gives (grows only: a field it does not know it leaves). */
|
|
41
|
+
export const READ_PROTOCOL = 1;
|
|
42
|
+
/** The request a service is given, as one JSON line: its image by its name in its own work folder. */
|
|
43
|
+
export function requestLine(input, work) {
|
|
44
|
+
const rel = path.relative(work, input.image);
|
|
45
|
+
const image = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? rel.split(path.sep).join("/") : input.image;
|
|
46
|
+
return JSON.stringify({ read: { protocol: READ_PROTOCOL, ...input, image } });
|
|
47
|
+
}
|
|
48
|
+
const isBox = (v) => Array.isArray(v) && v.length === 4 && v.every((n) => typeof n === "number" && Number.isFinite(n) && n >= -0.001 && n <= 1.001);
|
|
49
|
+
const clamp = (b) => b.map((n) => Math.round(Math.min(1, Math.max(0, n)) * 10000) / 10000);
|
|
50
|
+
/** Text of a service as strom keeps it: NFC, no control characters (tabs and line ends spaces), trimmed. */
|
|
51
|
+
function cleanText(v, max = 4000) {
|
|
52
|
+
return typeof v === "string" ? v.normalize("NFC").replace(/[\p{Cc}]/gu, " ").replace(/ {2,}/gu, " ").trim().slice(0, max) : "";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* What a service said (its reply: JSON lines {"line": {text, box?, confidence?}}, then {"done": {transcript?, model?,
|
|
56
|
+
* cost?, unreadable?}} or {"error": {outcome?, why?, resets?}}) as a ReadOutput. A line that is no JSON, of no kind
|
|
57
|
+
* known, or a box out of the page is left out — never a reason to fail; no "done" and no "error": an error.
|
|
58
|
+
*/
|
|
59
|
+
export function parseReply(text) {
|
|
60
|
+
const lines = [];
|
|
61
|
+
let done;
|
|
62
|
+
let error;
|
|
63
|
+
for (const raw of text.split("\n")) {
|
|
64
|
+
if (!raw.trim())
|
|
65
|
+
continue;
|
|
66
|
+
let msg;
|
|
67
|
+
try {
|
|
68
|
+
msg = JSON.parse(raw);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!msg || typeof msg !== "object" || Array.isArray(msg))
|
|
74
|
+
continue;
|
|
75
|
+
const m = msg;
|
|
76
|
+
const line = m.line;
|
|
77
|
+
if (line && typeof line === "object") {
|
|
78
|
+
const t = cleanText(line.text);
|
|
79
|
+
if (!t)
|
|
80
|
+
continue;
|
|
81
|
+
const c = typeof line.confidence === "number" && line.confidence >= 0 && line.confidence <= 1 ? Math.round(line.confidence * 1000) / 1000 : undefined;
|
|
82
|
+
const block = typeof line.block === "number" && Number.isInteger(line.block) && line.block >= 0 && line.block < 1000 ? line.block : undefined;
|
|
83
|
+
lines.push({ text: t, ...(isBox(line.box) ? { box: clamp(line.box) } : {}), ...(c !== undefined ? { confidence: c } : {}), ...(block !== undefined ? { block } : {}) });
|
|
84
|
+
}
|
|
85
|
+
else if (m.done && typeof m.done === "object")
|
|
86
|
+
done = m.done;
|
|
87
|
+
else if (m.error && typeof m.error === "object")
|
|
88
|
+
error = m.error;
|
|
89
|
+
}
|
|
90
|
+
if (error || !done) {
|
|
91
|
+
const o = cleanText(error?.outcome, 20);
|
|
92
|
+
const outcome = READ_OUTCOMES.includes(o) && o !== "ok" ? o : "error";
|
|
93
|
+
const why = cleanText(error?.why, 300) || (done ? "" : "the service said nothing of an end");
|
|
94
|
+
const resets = cleanText(error?.resets, 40);
|
|
95
|
+
return { outcome, transcript: "", lines: [], ...(why ? { why } : {}), ...(resets ? { resets } : {}) };
|
|
96
|
+
}
|
|
97
|
+
const unreadable = cleanText(done.unreadable, 40);
|
|
98
|
+
const transcript = cleanText(done.transcript, 40_000) || lines.map((l) => l.text).join(" | ");
|
|
99
|
+
const model = cleanText(done.model, 80);
|
|
100
|
+
const c = done.cost;
|
|
101
|
+
const cost = c && typeof c.amount === "number" && Number.isFinite(c.amount) && c.amount >= 0 && (c.unit === "usd" || c.unit === "credits") ? { amount: c.amount, unit: c.unit, ...(c.partial === true ? { partial: true } : {}) } : undefined;
|
|
102
|
+
return {
|
|
103
|
+
outcome: unreadable ? "unreadable" : "ok",
|
|
104
|
+
transcript: unreadable ? "" : transcript,
|
|
105
|
+
lines: unreadable ? [] : lines,
|
|
106
|
+
...(model ? { model } : {}),
|
|
107
|
+
...(cost ? { cost } : {}),
|
|
108
|
+
...(unreadable ? { why: unreadable } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// ── the fake service of the tests ─────────────────────────────────────────────────────────────────────────────────
|
|
112
|
+
/**
|
|
113
|
+
* A service for tests without a network (as the script runner is an agent for them): STROM_READ_FAKE names its reply
|
|
114
|
+
* (a file of JSON lines, parseReply), given back for every image; STROM_READ_FAKE_LOG, when set, gets each request
|
|
115
|
+
* line it was given (and the image's size), for a test to look at. There only while STROM_READ_FAKE is set — never
|
|
116
|
+
* offered to the Strom app (core/readchoice.ts offers the agents installed here).
|
|
117
|
+
*/
|
|
118
|
+
const fakeService = {
|
|
119
|
+
id: "fake",
|
|
120
|
+
kind: "service",
|
|
121
|
+
title: "Fake reading service",
|
|
122
|
+
can: ["transcript"],
|
|
123
|
+
ready: (env) => (env.STROM_READ_FAKE && fs.existsSync(env.STROM_READ_FAKE) ? { ready: true } : { ready: false, why: "not-set" }),
|
|
124
|
+
models: () => [{ id: "", name: "" }],
|
|
125
|
+
async read(input, o) {
|
|
126
|
+
const request = requestLine(input, o.work);
|
|
127
|
+
if (o.env.STROM_READ_FAKE_LOG)
|
|
128
|
+
fs.appendFileSync(o.env.STROM_READ_FAKE_LOG, JSON.stringify({ ...JSON.parse(request), bytes: fs.statSync(input.image).size, inWork: path.dirname(input.image) === o.work }) + "\n");
|
|
129
|
+
if (o.signal?.aborted)
|
|
130
|
+
return { outcome: "stopped", transcript: "", lines: [] };
|
|
131
|
+
return parseReply(fs.readFileSync(o.env.STROM_READ_FAKE, "utf8"));
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
// ── the registry ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
/** The services strom reads with (a reading service of its own comes here: one module each). */
|
|
136
|
+
const SERVICES = [];
|
|
137
|
+
/** Every provider of reading here: the agents of RUNNERS, the services, the fake one while a test sets it. */
|
|
138
|
+
export function readProviders(env) {
|
|
139
|
+
return [...Object.keys(RUNNERS).map(agentProvider), ...SERVICES, ...(env.STROM_READ_FAKE ? [fakeService] : [])];
|
|
140
|
+
}
|
|
141
|
+
/** The provider of reading of an id, none when there is no such. */
|
|
142
|
+
export function readProvider(id, env) {
|
|
143
|
+
return readProviders(env).find((p) => p.id === id);
|
|
144
|
+
}
|
|
145
|
+
/** Whether a reader of this id is a service (reads the transcript alone). */
|
|
146
|
+
export function isService(id, env) {
|
|
147
|
+
return !!id && readProvider(id, env)?.kind === "service";
|
|
148
|
+
}
|
package/dist/core/session.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// and a command finds its own by what it names (a task, a session, a research).
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import path from "node:path";
|
|
13
|
-
import { UsageError } from "./errors.js";
|
|
13
|
+
import { TaskTaken, UsageError } from "./errors.js";
|
|
14
14
|
import { now, VERSION } from "./tree.js";
|
|
15
15
|
import { makeNote, makeNotes } from "./actions.js";
|
|
16
16
|
import { detectAgent } from "./which.js";
|
|
@@ -157,9 +157,7 @@ export function startSession(tree, opts) {
|
|
|
157
157
|
});
|
|
158
158
|
const taken = opts.task ? othersAtWork(tree, tree.env, opts.runner).sessions.find((s) => s.task === opts.task.id) : undefined;
|
|
159
159
|
if (taken)
|
|
160
|
-
throw new
|
|
161
|
-
hint: "take another task: strom session start (the next free one)",
|
|
162
|
-
});
|
|
160
|
+
throw new TaskTaken(opts.task.id, taken.id, taken.agent);
|
|
163
161
|
const task = opts.task ? (tree.get(opts.task.id) ?? opts.task) : undefined;
|
|
164
162
|
const agent = detectAgent(tree.env) ?? (opts.runner && opts.runner !== "script" ? opts.runner : undefined);
|
|
165
163
|
// the model strom started the agent with (strom run, strom chat): what it read with, for a later review
|
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.36.0-beta.
|
|
35
|
+
export const VERSION = "1.36.0-beta.6";
|
|
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
|