strom-research 1.35.0 → 1.36.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.cs.md +45 -0
  2. package/CHANGELOG.de.md +53 -0
  3. package/CHANGELOG.md +48 -0
  4. package/CHANGELOG.pl.md +47 -0
  5. package/assets/lang/cs.json +47 -5
  6. package/assets/lang/de.json +47 -5
  7. package/assets/lang/pl.json +46 -4
  8. package/assets/plugins/gates/claude-usage/gate.ts +94 -16
  9. package/dist/cli/help.js +2 -2
  10. package/dist/cli/menu-links.js +58 -11
  11. package/dist/cli/menu-settings.js +19 -0
  12. package/dist/cli/menu-waiting.js +50 -1
  13. package/dist/cli/ui.js +41 -5
  14. package/dist/commands/analysis.js +20 -1
  15. package/dist/commands/guide.js +4 -1
  16. package/dist/commands/index.js +1 -0
  17. package/dist/commands/intake.js +32 -9
  18. package/dist/commands/links.js +10 -6
  19. package/dist/commands/media.js +166 -32
  20. package/dist/commands/setup.js +6 -0
  21. package/dist/commands/sourceretract.js +139 -0
  22. package/dist/commands/sources.js +42 -13
  23. package/dist/commands/sync.js +5 -3
  24. package/dist/commands/tasks.js +37 -9
  25. package/dist/commands/verify.js +7 -4
  26. package/dist/core/actions.js +11 -9
  27. package/dist/core/busy.js +9 -0
  28. package/dist/core/changelog.js +17 -0
  29. package/dist/core/config.js +7 -0
  30. package/dist/core/evidence.js +16 -0
  31. package/dist/core/import.js +9 -3
  32. package/dist/core/inboxwait.js +133 -15
  33. package/dist/core/inboxwatch.js +5 -4
  34. package/dist/core/links.js +13 -2
  35. package/dist/core/live.js +368 -33
  36. package/dist/core/material.js +12 -5
  37. package/dist/core/materialdelete.js +97 -23
  38. package/dist/core/media.js +4 -0
  39. package/dist/core/origin.js +16 -6
  40. package/dist/core/phrases.js +6 -0
  41. package/dist/core/queue.js +12 -4
  42. package/dist/core/report.js +1 -1
  43. package/dist/core/samescan.js +359 -0
  44. package/dist/core/sort.js +1 -1
  45. package/dist/core/sourcefields.js +16 -0
  46. package/dist/core/sourceretract.js +531 -0
  47. package/dist/core/sync.js +152 -7
  48. package/dist/core/taskaudit.js +104 -6
  49. package/dist/core/taskkind.js +58 -0
  50. package/dist/core/tree.js +1 -1
  51. package/dist/core/verify.js +12 -6
  52. package/dist/core/verifyfacts.js +7 -0
  53. package/dist/core/waiting.js +22 -3
  54. package/dist/core/waitkept.js +2 -0
  55. package/dist/gedcom/export.js +32 -9
  56. package/dist/gedcom/validate.js +8 -3
  57. package/dist/image/index.js +6 -3
  58. package/dist/image/jpeg-decode.js +80 -21
  59. package/package.json +4 -1
@@ -445,6 +445,7 @@ register({
445
445
  let applied = 0;
446
446
  let skipped = [];
447
447
  let proposed = [];
448
+ let retracted = [];
448
449
  let written = plan;
449
450
  tree.withTreeLock(() => {
450
451
  // what another process wrote meanwhile counts: the changes again, now that the tree is ours — the ones picked by
@@ -495,10 +496,11 @@ register({
495
496
  form: "authored",
496
497
  }, (sid) => `+${sid} source "${path.basename(file)}" (sync)`);
497
498
  // not the person's sync: a change of the user's or an imported tree's value only proposed (the user decides)
498
- const { applied: done, changes, skipped: left, asked, proposed: open } = applySync(tree, fresh, now1, source, only, { decidePerson: ctx.settings.hypothesesDecide(tree.config) === "person", input: made.id });
499
+ const { applied: done, changes, skipped: left, asked, proposed: open, retracted: gone } = applySync(tree, fresh, now1, source, only, { decidePerson: ctx.settings.hypothesesDecide(tree.config) === "person", input: made.id });
499
500
  applied = changes;
500
501
  skipped = left;
501
502
  proposed = open ?? [];
503
+ retracted = gone ?? [];
502
504
  input = update(tree, made.id, "input", (i) => ({ ...i, source: source.id, sync: { ...(fresh.head ? { head: fresh.head } : {}), edits: edits, applied: done, ...(asked ? { asked } : {}) } }), {
503
505
  op: "input.sync",
504
506
  summary: `${made.id} synced: ${changes} change(s)${fresh.head ? ` against ${fresh.head.slice(0, 8)}` : ""}`,
@@ -514,7 +516,7 @@ register({
514
516
  // a send of the app waited in the inbox: written now (the app hears it through the bridge)
515
517
  // the app's files it wrote, with the records they are (the bridge's answer: `media`)
516
518
  const media = mediaWritten(written.changes, skipped);
517
- settleReceived(tree.root, file, { state: "written", input: input.id, kept: written.changes.filter((c) => c.kept).length, notWritten: notWrittenList(written.changes), skipped, media }, input.sync?.applied ?? []);
519
+ settleReceived(tree.root, file, { state: "written", input: input.id, kept: written.changes.filter((c) => c.kept).length, notWritten: notWrittenList(written.changes), skipped, media, ...(retracted.length ? { retracted } : {}) }, input.sync?.applied ?? []);
518
520
  // each send of the app a little more history: packed in the background once it has grown
519
521
  compactSoon(tree.root, ctx.env);
520
522
  // a question to the person is no change of the research: counted as what it is
@@ -526,7 +528,7 @@ register({
526
528
  : ui(lang, "ui.sync.done", { n: changed, file: path.basename(file), input: input.id }), asks > 0 && changed > 0 ? ui(lang, "ui.sync.done.asked", { q: asks }) : undefined, ...skipped.map((x) => ui(lang, "ui.sync.skipped", { n: x.n, why: skippedWhy(x, lang) })), ...(proposed.length
527
529
  ? [`${proposed.length} change(s) of the user's or an imported family tree's values proposed, not written — the user decides (strom conflict list):`, ...proposed.map((x) => ` change ${x.n}: ${x.line}`)]
528
530
  : [])),
529
- data: { input: input.id, ...decoding, applied: input.sync?.applied ?? [], changes: written.changes, conflicts: syncConflicts(tree, input.id), ...(skipped.length ? { skipped } : {}), ...(proposed.length ? { proposed } : {}), ...(media.length ? { media } : {}) },
531
+ data: { input: input.id, ...decoding, applied: input.sync?.applied ?? [], changes: written.changes, conflicts: syncConflicts(tree, input.id), ...(skipped.length ? { skipped } : {}), ...(proposed.length ? { proposed } : {}), ...(media.length ? { media } : {}), ...(retracted.length ? { retracted } : {}) },
530
532
  };
531
533
  },
532
534
  }, {
@@ -49,6 +49,7 @@ import { applyAuditFix, auditOf, auditTasks, audited, bookIndex, changesSaid, fi
49
49
  import { head } from "../core/git.js";
50
50
  import { takeWaiting } from "./media.js";
51
51
  import { BOOKS_MIN_TASKS, bookOfTask, bookRows, booksOfTask, liveBook, minTasksOf, needsBooks, sameBookLine, tasksOfBook } from "../core/books.js";
52
+ import { parseTaskKind, TASK_KINDS, taskKind } from "../core/taskkind.js";
52
53
  function written(tree) {
53
54
  return lines(...tree.written.map((o) => o.summary));
54
55
  }
@@ -764,12 +765,13 @@ register({
764
765
  { name: "all", type: "boolean", description: "every task, whatever its state (the same as --state all)" },
765
766
  { name: "research", type: "string", value: "<G…>", description: "only this research" },
766
767
  { name: "level", type: "string", value: "<level>", description: "only this level" },
768
+ { name: "kind", type: "string", value: "<kind>", description: `only this kind of work: ${TASK_KINDS.join(", ")} (verify: every verification against the originals)` },
767
769
  { name: "about", type: "string", value: "<who>", description: "only tasks about this person/record (also X…, H…)" },
768
770
  { name: "off-tree", type: "boolean", description: "the open tasks that wait out of the queue: about people nothing links to the tree yet" },
769
771
  { name: "book", type: "string", value: "<B…>", description: "the tasks that need this book (open, at work, parked, waiting — open first; with --state only those): strom task books" },
770
772
  { name: "full", type: "boolean", description: "--json: whole records instead of one row each" },
771
773
  ],
772
- examples: ["strom task list", "strom task list --state waiting", "strom task list --book B0001"],
774
+ examples: ["strom task list", "strom task list --state waiting", "strom task list --kind verify", "strom task list --book B0001"],
773
775
  run(ctx, input) {
774
776
  const tree = ctx.tree();
775
777
  if (input.opts.all && input.opts.state !== undefined && input.opts.state !== "all")
@@ -777,6 +779,9 @@ register({
777
779
  // --all: what --state all lists
778
780
  const opts = input.opts.all ? { ...input.opts, state: "all" } : input.opts;
779
781
  const research = typeof opts.research === "string" ? resolveResearch(tree, opts.research).id : undefined;
782
+ const kind = opts.kind === undefined ? undefined : parseTaskKind(String(opts.kind));
783
+ if (opts.kind !== undefined && !kind)
784
+ throw new UsageError(`no kind of work ${String(opts.kind)}: ${TASK_KINDS.join(", ")}`, { code: "task.kind", hint: "strom task list --kind verify" });
780
785
  let all;
781
786
  const why = new Map();
782
787
  const ranks = new Map();
@@ -822,10 +827,12 @@ register({
822
827
  const id = subjects(tree, [String(opts.about)])[0];
823
828
  all = all.filter((t) => t.subject.includes(id));
824
829
  }
830
+ if (kind)
831
+ all = all.filter((t) => taskKind(t) === kind);
825
832
  // a page at most LIST_PAGE_MAX rows, whatever --limit says: under ~20 kB
826
833
  const page = paginate(all, Math.min(ctx.limit, LIST_PAGE_MAX), ctx.page);
827
834
  // the queue says what waits out of it for a link to the tree
828
- const held = !opts.state && !opts["off-tree"] && !opts.about && !book ? tree.list("task").filter((t) => t.state === "open" && off(t)).length : 0;
835
+ const held = !opts.state && !opts["off-tree"] && !opts.about && !book && !kind ? tree.list("task").filter((t) => t.state === "open" && off(t)).length : 0;
829
836
  if (book)
830
837
  return {
831
838
  text: lines(`${book.id} ${book.title}${book.url ? ` · ${book.url}` : ""}`, all.length ? lines(table(page.items.map(taskLine)), moreLine(page, `strom task list --book ${book.id}`)) : "no task needs it now"),
@@ -1193,7 +1200,7 @@ register({
1193
1200
  options: [
1194
1201
  // the sheet of a brief shows the placeholder: how to write it, where the agent writes it (a live run: "Otevřete …")
1195
1202
  { name: "on", type: "string", value: "<for the user: impersonal, research language>", description: "what it waits for, for the user: which book, its link, which images" },
1196
- { name: "images", type: "string", value: "<B…:n-m>", description: "the images the user saves by hand, numbered as the portal's viewer counts them (B0001:40-69, B0001:9,12)" },
1203
+ { name: "images", type: "string", value: "<B…:n-m>", multiple: true, description: "the images of one book the user saves by hand, numbered as the portal's viewer counts them (B0001:40-69, B0001:9,12); again, more of the same book — another book's images: a task of its own (one book per task)" },
1197
1204
  { name: "check", type: "string", value: "<URL>", description: "a site for the user to check (one strom may not read): only after another way was tried and the blocked way recorded (strom search add)" },
1198
1205
  // --images and --check say the kind themselves: --kind is for a wait of neither
1199
1206
  ...WAIT_OPTIONS.map((o) => (o.name === "kind" ? { ...o, description: `${o.description} — not with --images or --check: they say the kind themselves` } : o)),
@@ -1218,12 +1225,33 @@ register({
1218
1225
  if (opts.check !== undefined)
1219
1226
  awaitsCheck = { url: checkUrl(ctx, tree, normId(args[0], "task"), String(opts.check)), ask: on };
1220
1227
  if (opts.images !== undefined) {
1221
- const m = /^\s*([Bb]\d+)\s*:\s*(.+)$/.exec(String(opts.images));
1222
- const nums = m ? parseImageList(m[2]) : undefined;
1223
- if (!m || !nums)
1224
- throw new UsageError(`--images: a record set and its image numbers, e.g. B0001:40-45 or B0001:9,12 — not "${opts.images}"`);
1225
- b = requireRecord(tree, m[1], "recordset");
1226
- awaits = { recordset: b.id, images: runs(nums), folder: inboxFolderFor(b) };
1228
+ // --images again, or a comma before another ID ("B0001:50-52,B0002:3"): the same book's images joined, as a comma
1229
+ // joins them in one (B0001:9,12); images of another book refused — one book per task, never the last one taken
1230
+ const given = (Array.isArray(opts.images) ? opts.images : [opts.images]).map(String);
1231
+ const books = new Map();
1232
+ for (const one of given.flatMap((v) => v.split(/,\s*(?=[Bb]\d+\s*:)/u))) {
1233
+ const m = /^\s*([Bb]\d+)\s*:\s*(.+)$/u.exec(one);
1234
+ const nums = m ? parseImageList(m[2]) : undefined;
1235
+ if (!m || !nums)
1236
+ throw new UsageError(`--images: a record set and its image numbers, e.g. B0001:40-45 or B0001:9,12 — not "${one}"`);
1237
+ const rb = requireRecord(tree, m[1], "recordset");
1238
+ const key = liveBook(tree, rb.id)?.id ?? rb.id;
1239
+ const had = books.get(key);
1240
+ if (had)
1241
+ for (const n of nums)
1242
+ had.nums.add(n);
1243
+ else
1244
+ books.set(key, { b: rb, nums: new Set(nums) });
1245
+ }
1246
+ if (books.size > 1) {
1247
+ const ids = [...books.keys()];
1248
+ throw new UsageError(`--images: images of ${ids.join(", ")} — one book per task`, {
1249
+ hint: `--images ${ids[0]}:<numbers> here; each other book a task of its own: strom task add "<what>" --where ${ids[1]} … --anyway, then strom task wait <its T…> --images ${ids[1]}:<numbers> --on "…"`,
1250
+ });
1251
+ }
1252
+ const [one] = books.values();
1253
+ b = one.b;
1254
+ awaits = { recordset: b.id, images: runs([...one.nums].sort((x, y) => x - y)), folder: inboxFolderFor(b) };
1227
1255
  }
1228
1256
  if (b && wait?.book) {
1229
1257
  // --images names its book itself: the same one only repeats it
@@ -6,6 +6,7 @@ import { register } from "../cli/registry.js";
6
6
  import { lines } from "../cli/format.js";
7
7
  import { ui } from "../cli/ui.js";
8
8
  import { UsageError, StromError } from "../core/errors.js";
9
+ import { workingNow } from "../core/busy.js";
9
10
  import { BULK_ORDERS, BULK_SCOPES, emptyFunnel, taskPlaces, verifyAsk, verifyStop, verifyCandidates, verifyBulk, verifyConfirmAll, verifyCounts, verifyFactDone } from "../core/verify.js";
10
11
  import { displayName, resolvePerson } from "../core/people.js";
11
12
  import { actsAsArchive, refuseInArchive } from "../core/state.js";
@@ -128,13 +129,14 @@ register({
128
129
  "low priority: after the lines' work, now and then one first. A line (--of G…), a lineage (--of P…: its founder\n" +
129
130
  "and who carries it on through the sons) or the tree. A family tree's leads too (facts of an imported family\n" +
130
131
  "tree, no original read): the record their citation names looked for first, a task of its own (dearer: two\n" +
131
- "sessions). --try n: the first n people; --budget: as many as the estimate fits (once sessions were measured\n" +
132
+ "sessions). --try n: the first n people, first in the queue (a try, as strom verify facts puts a person first);\n" +
133
+ "--budget: as many as the estimate fits (once sessions were measured\n" +
132
134
  "here). --dry-run: the counts (--json how: read, search) and the estimate, nothing written.",
133
135
  options: [
134
136
  { name: "scope", type: "string", value: "<line|lineage|tree>", description: "what: a line (G…), a lineage (its founder P…), the whole tree" },
135
137
  { name: "of", type: "string", value: "<G…|P…>", description: "the line (G…) or the lineage's founder (P…)" },
136
138
  { name: "order", type: "string", value: "<ancestors|weakest|oldest>", description: "who first: the nearest ancestors (default), the weakest facts, the longest unverified" },
137
- { name: "try", type: "string", value: "<n>", description: "only the first n people: a try before the rest" },
139
+ { name: "try", type: "string", value: "<n>", description: "only the first n people, first in the queue: a try before the rest" },
138
140
  { name: "budget", type: "string", value: "<usd>", description: "only as many people as the estimate fits in this amount (USD)" },
139
141
  ],
140
142
  examples: ["strom verify bulk --scope tree --dry-run", "strom verify bulk --scope line --of G0001 --try 3", "strom verify bulk --scope lineage --of P0001 --order weakest --budget 20"],
@@ -160,8 +162,9 @@ register({
160
162
  });
161
163
  const lang = tree.lang;
162
164
  return {
163
- text: lines(ui(lang, dry ? "ui.verify.bulk.would" : "ui.verify.bulk.queued", { people: r.people, facts: r.facts }), r.how.search ? ui(lang, "ui.verify.bulk.search", { n: r.how.search }) : undefined, estimateLine(lang, r.estimate), r.left ? ui(lang, "ui.verify.bulk.left", { n: r.left }) : undefined),
164
- data: { dryRun: dry, ...r },
165
+ text: lines(ui(lang, dry ? "ui.verify.bulk.would" : r.first ? "ui.verify.bulk.first" : "ui.verify.bulk.queued", { people: r.people, facts: r.facts }), r.how.search ? ui(lang, "ui.verify.bulk.search", { n: r.how.search }) : undefined, estimateLine(lang, r.estimate), r.left ? ui(lang, "ui.verify.bulk.left", { n: r.left }) : undefined),
166
+ // working: an agent at work in the research now (a run, a session) — a try waits for the next session either way
167
+ data: { dryRun: dry, ...r, working: workingNow(tree) },
165
168
  };
166
169
  },
167
170
  });
@@ -4,7 +4,7 @@ import { DirectionExists, UsageError } from "./errors.js";
4
4
  import { workOrder } from "./order.js";
5
5
  import { normalizeDate, reversedRange } from "./gdate.js";
6
6
  import { normalizeAge } from "./age.js";
7
- import { checkStatus, defaultStatus } from "./evidence.js";
7
+ import { checkStatus, citableSource, defaultStatus } from "./evidence.js";
8
8
  import { clearRemoved, refuseRemoved } from "./citeorder.js";
9
9
  import { eventKind, FAMILY_EVENT_KINDS, NOTE_MAX, STATUSES, treeNoteText, PARTICIPANT_ROLES, NAME_KINDS, RECORD_TYPES, } from "./model.js";
10
10
  import { cleanTitle, displayName, familiesAsChild, familiesAsPartner, gedcomName, gedcomTitledName, closesCircle, isAncestorOf, isBirthFamily, keepSides, notAName, parseName, primaryName, sameName, slashInName, withoutMark } from "./people.js";
@@ -162,8 +162,7 @@ export function parseParticipant(tree, spec, o = {}) {
162
162
  return p;
163
163
  }
164
164
  function checkCitation(tree, c) {
165
- if (tree.get(c.source)?.type !== "source")
166
- throw new UsageError(`no source ${c.source}`, { hint: 'strom source add "<title>" …', code: "record.none", params: { kind: "source", id: c.source } });
165
+ citableSource(tree, c.source);
167
166
  }
168
167
  /** A list of citations with one more; the same place of the same source twice is refused. */
169
168
  function withCitation(list, c, what) {
@@ -184,8 +183,7 @@ export function makeEvent(tree, input, forFamily = false) {
184
183
  });
185
184
  const citations = input.citations ?? [];
186
185
  for (const c of citations)
187
- if (tree.get(c.source)?.type !== "source")
188
- throw new UsageError(`no source ${c.source}`, { hint: 'strom source add "<title>" …', code: "record.none", params: { kind: "source", id: c.source } });
186
+ citableSource(tree, c.source);
189
187
  const status = parseStatus(input.status, defaultStatus(tree, citations));
190
188
  checkStatus(tree, status, citations);
191
189
  if (forFamily && input.age?.trim())
@@ -644,9 +642,7 @@ export function notRetracted(tree, eventId, what) {
644
642
  */
645
643
  export function citeEvent(tree, eventId, citation, status, reason) {
646
644
  notRetracted(tree, eventId, "cite");
647
- const src = tree.get(citation.source);
648
- if (!src || src.type !== "source")
649
- throw new UsageError(`no source ${citation.source}`, { hint: 'strom source add "<title>" …', code: "record.none", params: { kind: "source", id: citation.source } });
645
+ citableSource(tree, citation.source);
650
646
  const newStatus = status === undefined ? undefined : parseStatus(status, "lead");
651
647
  const why = reason?.trim();
652
648
  const { main: _main, ...plain } = citation;
@@ -1189,9 +1185,15 @@ export function setStory(tree, id, input) {
1189
1185
  for (const f of facts)
1190
1186
  findEventOwner(tree, f);
1191
1187
  const sources = [...new Set((input.sources ?? []).map((s) => s.trim().toUpperCase()))];
1192
- for (const s of sources)
1188
+ for (const s of sources) {
1193
1189
  if (tree.get(s)?.type !== "source")
1194
1190
  throw new UsageError(`no source ${s}`, { hint: "the background of place and time is recorded first: strom source add … --kind book|newspaper|web", code: "story.no-source", params: { kind: "source", id: s } });
1191
+ citableSource(tree, s);
1192
+ }
1193
+ // a source the person deleted is named by no new story (spec 117 R3): its ID in the text is refused as a citation is
1194
+ for (const s of sourcesNamed(tree, [input.title, text, input.note].filter(Boolean).join("\n")))
1195
+ if (tree.get(s)?.retracted?.reason === "deleted")
1196
+ citableSource(tree, s);
1195
1197
  return tree.withTreeLock(() => {
1196
1198
  const rec = tree.get(id);
1197
1199
  if (!rec || (rec.type !== "person" && rec.type !== "family"))
package/dist/core/busy.js CHANGED
@@ -22,3 +22,12 @@ export function busyIn(tree, now = Date.now()) {
22
22
  export function isBusy(b) {
23
23
  return b.sessions.length > 0 || b.runs > 0 || b.conversations > 0;
24
24
  }
25
+ /**
26
+ * Whether the research works now as the Strom app's "work on them now" asks (spec 065 K7.2): a run or a session at
27
+ * work — what the link work refuses to start beside (cli/menu-links.ts workRun); a conversation with no session open
28
+ * takes no task by itself.
29
+ */
30
+ export function workingNow(tree) {
31
+ const b = busyIn(tree);
32
+ return b.runs > 0 || b.sessions.length > 0;
33
+ }
@@ -602,6 +602,23 @@ export function changeLines(tree, ops, subject, lang, was, tasks) {
602
602
  say(phrase(lang, "log.task.file", { name: name(first), inputs: o.targets.slice(1).join(", ") }));
603
603
  continue;
604
604
  }
605
+ // a source the person deleted (spec 117 R9), and put back: its title and ID, the citations and stories it took
606
+ const deleted = o.op === "source.retract" ? /^(S\d+(?:, S\d+)*) deleted by the user[^:]*: (\d+) citation\(s\), (\d+) story\(ies\)/u.exec(o.summary) : undefined;
607
+ if (deleted) {
608
+ const ids = deleted[1].split(", ");
609
+ say(phrase(lang, "log.source.deleted", { name: ids.map((id) => name(id)).join(", "), id: ids.join(", "), cites: Number(deleted[2]), stories: Number(deleted[3]) }));
610
+ continue;
611
+ }
612
+ const restored = o.op === "source.restore" ? /^(S\d+(?:, S\d+)*) restored by the user: (\d+) citation\(s\) back/u.exec(o.summary) : undefined;
613
+ if (restored) {
614
+ const ids = restored[1].split(", ");
615
+ say(phrase(lang, "log.source.restored", { name: ids.map((id) => name(id)).join(", "), id: ids.join(", "), cites: Number(restored[2]) }));
616
+ continue;
617
+ }
618
+ if (o.op === "conflict.keep") {
619
+ say(phrase(lang, "log.conflict.keep", { name: name(first) }));
620
+ continue;
621
+ }
605
622
  // a conflict decided: the decision and why, first — the fact it took back or wrote is its effect (found in an
606
623
  // archive: "Odvoláno: …" alone in the history, the decision and its reason nowhere)
607
624
  if (o.op === "conflict.resolve") {
@@ -85,6 +85,8 @@ export const SETTINGS = [
85
85
  { key: "web.perHost", env: "", tree: true, kind: "number", description: `web requests to one site (its mirrors with it) in one session through an agent's own web fetch (default ${WEB_PER_HOST}; past ${WEB_SOFT} they go slower and the agent builds a connector): past it a run refuses and a conversation asks you, and more pages of that site go through strom fetch with a connector — only you raise it` },
86
86
  // Read from the config file only, changed by the user alone: the gate decides what working alone spends.
87
87
  { key: "run.gate", env: "", tree: false, kind: "plugin", description: "a condition on the agent working alone: the gate (plugins/gates/<name>) strom asks before each session of strom run — go on, wait or stop; its name, then what it is given (strom gate list; e.g. claude-usage 10: the Claude subscription's daily ration, 10 points in hand; claude-usage 10 --cap 95: and never past 95 % of the week, before every session of every run, no “start anyway”) — only you set it" },
88
+ // Read from the config file only, changed by the user alone: a standing yes to the agent's subscription or credit.
89
+ { key: "run.confirm", env: "", tree: false, kind: "choice", choices: ["ask", "no"], description: "the question before the agent starts from a link of the Strom app (a conversation, a task, the work on the queue, a conflict left to the agent, the identification of places): ask (default — said and asked in the terminal) or no (started at once, one line says so; what says a price in money, a consent, a deletion, a request sent and the gate run.gate still ask; an agent's own command is never let through) — every research on this computer, only you set it" },
88
90
  // Read from the config file only, changed by the user alone: how fast strom may take images of an archive whose
89
91
  // terms restrict automation, once the user allowed it slowly (core/terms.ts).
90
92
  { key: "archive.pace", env: "", tree: false, kind: "pace", description: "a person's pace for the images of an archive whose terms restrict automated access, once you allowed it slowly: seconds between two images, then requests to the archive an hour, its catalogue counted too (default \"10 120\"; auto: the default) — the service's own pace stays the slowest; one archive's own: strom allow host <host> --pace/--per-hour — only you set it" },
@@ -191,6 +193,7 @@ const FIELDS = {
191
193
  "excerpts.for": "excerptsFor",
192
194
  "excerpts.mb": "excerptsMb",
193
195
  "run.gate": "runGate",
196
+ "run.confirm": "runConfirm",
194
197
  "archive.pace": "archivePace",
195
198
  "read.app": "readApp",
196
199
  "tune.transcripts": "tuneTranscripts",
@@ -706,6 +709,10 @@ export class Settings {
706
709
  runGate() {
707
710
  return this.config.runGate || undefined;
708
711
  }
712
+ /** The question before the agent starts from a link of the Strom app: ask (the default) or no (the config file only, the person's). */
713
+ runConfirm() {
714
+ return this.config.runConfirm === "no" ? "no" : "ask";
715
+ }
709
716
  /** The readings of documents the Strom app may ask ("<an hour> <a day>"; the config file only, raised by the person alone). */
710
717
  readApp() {
711
718
  return this.config.readApp && this.config.readApp !== "auto" ? this.config.readApp : undefined;
@@ -68,6 +68,22 @@ export function quay(src, c) {
68
68
  return info === "primary" ? 3 : 2;
69
69
  return info === "primary" ? 2 : 1; // derivative: a copy, an index, a transcript
70
70
  }
71
+ /**
72
+ * A source a new citation may cite: the research's, not retracted — a source the person deleted (spec 117) is cited by
73
+ * nobody, agent or person, until it is restored (source.retracted); a duplicate merged away: its record instead.
74
+ */
75
+ export function citableSource(tree, id) {
76
+ const s = tree.get(id);
77
+ if (!s || s.type !== "source")
78
+ throw new UsageError(`no source ${id}`, { hint: 'strom source add "<title>" …', code: "record.none", params: { kind: "source", id } });
79
+ if (s.retracted)
80
+ throw new UsageError(`${id} is retracted${s.retracted.reason === "deleted" ? " (deleted by the person)" : `: ${s.retracted.reason}`} — nothing cites it`, {
81
+ hint: s.mergedInto ? `cite ${s.mergedInto}, the record it was merged into` : s.retracted.reason === "deleted" ? `only the person puts it back (strom source restore ${id}); cite another record` : "cite another record",
82
+ code: "source.retracted",
83
+ params: { id },
84
+ });
85
+ return s;
86
+ }
71
87
  /** The status a fact gets when none is given. */
72
88
  export function defaultStatus(tree, citations) {
73
89
  if (citations.length === 0)
@@ -255,10 +255,16 @@ export function importGedcom(tree, text, opts) {
255
255
  // the imports the app's file names (HEAD 1 _STROM_IMPORT Ix): each its own source, made once, cited by its values
256
256
  const appImports = fromApp.app ? importsOfHead(head) : undefined;
257
257
  const importSources = new Map();
258
+ // an import's source the person deleted (spec 117 J6): never made again — its values keep their origin, cite the file
259
+ const importsDeleted = new Set();
258
260
  const importSource = (key) => {
259
261
  let id = importSources.get(key);
260
- if (!id)
261
- importSources.set(key, (id = importSourceFor(tree, appImports.get(key), opts.input).source.id));
262
+ if (!id) {
263
+ const got = importSourceFor(tree, appImports.get(key), opts.input);
264
+ importSources.set(key, (id = got.source.id));
265
+ if (got.deleted)
266
+ importsDeleted.add(id);
267
+ }
262
268
  return id;
263
269
  };
264
270
  const originOf = (node, of = "fact") => {
@@ -266,7 +272,7 @@ export function importGedcom(tree, text, opts) {
266
272
  return mark ? originOfMark(mark, importSource(mark.key), of) : { ...stamp };
267
273
  };
268
274
  /** What a fact of the file cites: the import's source the app marks it with (and the file's for parts the user changed), else the file's. */
269
- const citesOf = (o, locator) => o.source && o.source !== source.id ? [{ source: o.source, locator }, ...(o.parts?.length ? [{ source: source.id, locator }] : [])] : [{ source: source.id, locator }];
275
+ const citesOf = (o, locator) => o.source && o.source !== source.id && !importsDeleted.has(o.source) ? [{ source: o.source, locator }, ...(o.parts?.length ? [{ source: source.id, locator }] : [])] : [{ source: source.id, locator }];
270
276
  const xrefToId = new Map();
271
277
  const pedi = new Map(); // person xref → family xref → PEDI
272
278
  const individuals = records.filter((x) => x.tag === "INDI" && x.xref);
@@ -11,10 +11,13 @@
11
11
  // a book still to be found (a place in words beside the book of the trail): no folder.
12
12
  //
13
13
  // The files of a folder are numbered by their names (the number the portal's viewer counts; a copy's suffix a file
14
- // manager added aside, "33 2.jpg"); named otherwise (a screenshot's time, a download's own name), by their order when
15
- // there are as many as images missing — never a file named by a number alone (B0408: "1.jpg" is image 1, not the 33
16
- // missing); else nothing is taken and it is said what is needed. A file is taken once it has settled (not written for SETTLE_MS): a large scan
17
- // being copied is never taken half.
14
+ // manager added aside, "33 2.jpg") — only a number the name gives unambiguously (personNumbers: one number, or one
15
+ // zero-padded counter among others; two numbers and no counter: not known); named with no number (a screenshot's date
16
+ // and time, a name with none), by their order when there are as many as images missing — never when any file of the
17
+ // batch has a number of its own (B0408: "1.jpg" is image 1, not the 33 missing); else nothing is taken and it is said
18
+ // what is needed. A folder is taken once the whole batch has settled (folderBusy): no file written for SETTLE_MS, no
19
+ // browser's download still running in it (.crdownload, .part, Safari's .download) — a large scan being copied, a batch
20
+ // half downloaded, is never taken half.
18
21
  //
19
22
  // The folder of a book the tasks still need, with no task waiting on it (spec 105 K1.4: "one download serves them
20
23
  // all"): its images are taken by the numbers in their names alone (never by their order: nothing says which images they
@@ -22,7 +25,7 @@
22
25
  // counted back. The tasks of the book then read them from disk.
23
26
  import fs from "node:fs";
24
27
  import path from "node:path";
25
- import { collectFiles, copyless, IMAGE_FILE_EXT, imageNumbers, inboxFolderFor, namedByNumber, numberInName, parseImageList } from "./media.js";
28
+ import { collectFiles, copyless, IMAGE_FILE_EXT, inboxFolderFor, numberInName, parseImageList } from "./media.js";
26
29
  import { waitKindOf } from "./waitkind.js";
27
30
  import { booksOfTask, needsBooks, waitTarget } from "./books.js";
28
31
  import { imageFileTimesOf } from "./knownterms.js";
@@ -83,17 +86,77 @@ export function folderFiles(dir) {
83
86
  }
84
87
  return files.sort((a, b) => path.basename(a).localeCompare(path.basename(b), undefined, { numeric: true }) || a.localeCompare(b));
85
88
  }
86
- /** The files of a folder still being written (changed less than SETTLE_MS ago). */
89
+ /** The files of a folder still being written (changed less than SETTLE_MS ago; empty, a browser's placeholder). */
87
90
  export function unsettled(files, now = Date.now()) {
88
91
  return files.filter((f) => {
89
92
  try {
90
- return now - fs.statSync(f).mtimeMs < SETTLE_MS;
93
+ const st = fs.statSync(f);
94
+ return now - st.mtimeMs < SETTLE_MS || (st.size === 0 && now - st.mtimeMs < STALLED_MS);
91
95
  }
92
96
  catch {
93
97
  return true;
94
98
  }
95
99
  });
96
100
  }
101
+ /** A browser's download not finished yet: Chrome's .crdownload, Firefox's .part, Safari's .download (a folder), a .tmp. */
102
+ export const DOWNLOADING = /\.(?:crdownload|part|partial|download|tmp)$/iu;
103
+ /** A download not written to for this long has stopped (a browser's failed or paused download): not waited for. */
104
+ export const STALLED_MS = 60_000;
105
+ /**
106
+ * The downloads a browser is still writing into a folder (DOWNLOADING; Safari's is a folder, its file inside): those
107
+ * written to within STALLED_MS — one stopped long ago holds nothing back. Their names.
108
+ */
109
+ export function downloadsIn(dir, now = Date.now()) {
110
+ let names;
111
+ try {
112
+ names = fs.readdirSync(dir);
113
+ }
114
+ catch {
115
+ return [];
116
+ }
117
+ return names.filter((name) => {
118
+ if (!DOWNLOADING.test(name.normalize("NFC")))
119
+ return false;
120
+ const p = path.join(dir, name);
121
+ try {
122
+ let at = fs.statSync(p).mtimeMs;
123
+ // a bundle (Safari): what is written is inside it
124
+ if (fs.statSync(p).isDirectory())
125
+ for (const f of collectFiles([p]))
126
+ at = Math.max(at, fs.statSync(f).mtimeMs);
127
+ return now - at < STALLED_MS;
128
+ }
129
+ catch {
130
+ return false;
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * How many things of a folder are still being written: its files not settled and the browser's downloads running in
136
+ * it (B0408: a batch half downloaded is never taken — the first file settled while the rest still came). 0: taken.
137
+ */
138
+ export function folderBusy(dir, files, now = Date.now()) {
139
+ return unsettled(files, now).length + downloadsIn(dir, now).length;
140
+ }
141
+ /**
142
+ * The image number each file's name gives unambiguously (B0408): a copy's suffix aside (copyless), one group of digits
143
+ * ("33", "IMG_0057", "snímek 8"), else the one zero-padded counter of three digits at least among other numbers (a
144
+ * portal's "…_00141_sign-4411.jpg"); two numbers and no such counter ("1784 33", a screenshot's date and time "2026-11-04
145
+ * 10.07"): not known.
146
+ */
147
+ export function personNumbers(files) {
148
+ return files.map((f) => {
149
+ const groups = copyless(f).match(/\p{Nd}+/gu) ?? [];
150
+ const digits = groups.map((g) => (/^[0-9]+$/u.test(g) ? g : undefined));
151
+ if (digits.some((g) => g === undefined))
152
+ return undefined; // digits of another script: not read as a number
153
+ if (digits.length === 1)
154
+ return Number(digits[0]);
155
+ // a counter of three digits at least (a date's "04", a time's "07" are no counter)
156
+ const padded = digits.filter((g) => g.length > 2 && g.startsWith("0"));
157
+ return padded.length === 1 ? Number(padded[0]) : undefined;
158
+ });
159
+ }
97
160
  /** By how much a portal's .jp2 names an image of this book (strom's list, imageFileTimes), when it says. */
98
161
  export function bookTimes(tree, b) {
99
162
  const book = typeof b === "string" ? tree.get(b) : b;
@@ -132,7 +195,7 @@ export function bookFolders(tree) {
132
195
  * taken, and what the files need is said.
133
196
  */
134
197
  export function numberBookFiles(files, recordset, times) {
135
- const all = imageNumbers(files).map((n, i) => (n === undefined || !times || path.extname(files[i]).toLowerCase() !== ".jp2" ? n : n % times === 0 ? n / times : undefined));
198
+ const all = personNumbers(files).map((n, i) => (n === undefined || !times || path.extname(files[i]).toLowerCase() !== ".jp2" ? n : n % times === 0 ? n / times : undefined));
136
199
  const named = files.map((file, i) => ({ file, n: all[i] })).filter((x) => x.n !== undefined && x.n > 0);
137
200
  const left = files.length - named.length;
138
201
  if (named.length)
@@ -144,19 +207,20 @@ export function numberBookFiles(files, recordset, times) {
144
207
  };
145
208
  }
146
209
  /**
147
- * The image number of each file: by the names when they say one each (and, of images asked for, at least one of those);
148
- * else by their order onto the images still missing when there are as many files and none is named by a number alone
149
- * (B0408: "1.jpg" of a task waiting for 33 was taken for 33 — a number a person named is never overruled by the order;
150
- * a portal's own name or a screenshot's date and time is); else why not. `times`: a portal's .jp2 counted back
151
- * (numberBookFiles).
210
+ * The image number of each file: by the names when they say one each, unambiguously (personNumbers; and, of images
211
+ * asked for, at least one of those); else by their order onto the images still missing when there are as many files
212
+ * and no file of them has a number of its own in its name (B0408: "1.jpg" of a task waiting for 33 was taken for 33 —
213
+ * a number in a name is never overruled by the order, a portal's own "kniha-00090.jpg" neither; a screenshot's date and
214
+ * time, a name with no number is); else why not. `times`: a portal's .jp2 counted back (numberBookFiles).
152
215
  */
153
216
  export function numberFiles(files, want, have, recordset, times) {
154
- const names = imageNumbers(files).map((n, i) => (n === undefined || !times || path.extname(files[i]).toLowerCase() !== ".jp2" ? n : n % times === 0 ? n / times : undefined));
217
+ const own = personNumbers(files);
218
+ const names = own.map((n, i) => (n === undefined || !times || path.extname(files[i]).toLowerCase() !== ".jp2" ? n : n % times === 0 ? n / times : undefined));
155
219
  const named = names.every((n) => n !== undefined && n > 0);
156
220
  if (named && (!want?.length || names.some((n) => want.includes(n))))
157
221
  return { numbers: names, by: "names" };
158
222
  const missing = (want ?? []).filter((n) => !have.has(n));
159
- if (want?.length && missing.length && files.length === missing.length && !files.some(namedByNumber))
223
+ if (want?.length && missing.length && files.length === missing.length && own.every((n) => n === undefined))
160
224
  return { numbers: missing, by: "order" };
161
225
  const said = names.filter((n) => n !== undefined);
162
226
  if (!want?.length)
@@ -257,3 +321,57 @@ export function numbersForTask(count, o) {
257
321
  return { numbers: [...o.missing], by: "order" };
258
322
  return { code: "waiting.image-unknown", missing: o.missing.length ? [...o.missing] : [...want] };
259
323
  }
324
+ /** The name a file of the inbox is set aside under (commands/media.ts takeFiles): its name, then what it is. */
325
+ const ASIDE = /^(.+)\.(same-as|other-than)-(M\p{N}+)$/u;
326
+ /**
327
+ * The files set aside in the folders of the research's books (only of a book of this research: the inbox is every
328
+ * research's), newest first — derived from the files themselves, nothing written: a file taken away is no question.
329
+ */
330
+ export function asideFiles(tree, shared) {
331
+ if (!shared)
332
+ return [];
333
+ const inbox = path.join(shared, "inbox");
334
+ let folders;
335
+ try {
336
+ folders = fs.readdirSync(inbox);
337
+ }
338
+ catch {
339
+ return [];
340
+ }
341
+ const books = new Map(tree.list("recordset").filter((b) => !b.retracted && !b.mergedInto).map((b) => [inboxFolderFor(b).normalize("NFC"), b.id]));
342
+ const out = [];
343
+ for (const folder of folders) {
344
+ const recordset = books.get(folder.normalize("NFC"));
345
+ if (!recordset)
346
+ continue;
347
+ let names;
348
+ try {
349
+ names = fs.readdirSync(path.join(inbox, folder));
350
+ }
351
+ catch {
352
+ continue;
353
+ }
354
+ for (const file of names) {
355
+ const m = ASIDE.exec(file.normalize("NFC"));
356
+ if (!m)
357
+ continue;
358
+ const media = tree.get(m[3]);
359
+ if (!media || media.retracted)
360
+ continue;
361
+ const p = path.join(inbox, folder, file);
362
+ let at;
363
+ try {
364
+ const st = fs.statSync(p);
365
+ if (!st.isFile())
366
+ continue;
367
+ at = st.mtime.toISOString();
368
+ }
369
+ catch {
370
+ continue;
371
+ }
372
+ const image = personNumbers([m[1]])[0];
373
+ out.push({ folder, file, path: p, name: m[1], recordset, ...(image !== undefined ? { image } : {}), kind: m[2] === "same-as" ? "same" : "other", media: media.id, at });
374
+ }
375
+ }
376
+ return out.sort((a, b) => b.at.localeCompare(a.at) || a.file.localeCompare(b.file));
377
+ }
@@ -3,14 +3,15 @@
3
3
  // whole inbox: images the person saves there by hand are taken as they come (strom media add --inbox --waiting, a strom
4
4
  // of the bridge's own writing as the person), and a task they complete comes back to the queue without a command.
5
5
  //
6
- // A file is taken once it has settled (not written for SETTLE_MS): a large scan being copied is never taken half. What
6
+ // A folder is taken once it has settled (no file written for SETTLE_MS, no browser's download running in it, B0408): a
7
+ // large scan being copied, a batch half downloaded, is never taken half. What
7
8
  // cannot be taken (named so its numbers are not known) is tried again only once the folder changes — never again and
8
9
  // again. The folders are looked at again every STROM_INBOX_POLL_MS (30 s): a task set waiting meanwhile, a watch a
9
10
  // system lost (a network drive, a folder made again), a change the system did not report.
10
11
  import fs from "node:fs";
11
12
  import path from "node:path";
12
13
  import { Tree } from "./tree.js";
13
- import { bookFolders, folderFiles, inboxWaits, SETTLE_MS, unsettled } from "./inboxwait.js";
14
+ import { bookFolders, folderBusy, folderFiles, inboxWaits, SETTLE_MS } from "./inboxwait.js";
14
15
  /** What lies in a folder: its files with their size and time, so a folder unchanged is not tried twice. */
15
16
  function signature(files) {
16
17
  return files
@@ -91,8 +92,8 @@ export function watchInbox(o) {
91
92
  tried.delete(dir);
92
93
  continue;
93
94
  }
94
- // still being written: looked at once it has settled
95
- if (unsettled(files, Date.now()).length) {
95
+ // still being written (a file, a browser's download of the batch): looked at once it has all settled
96
+ if (folderBusy(dir, files, Date.now())) {
96
97
  wait = settleMs;
97
98
  continue;
98
99
  }
@@ -116,8 +116,10 @@ export const LINK_PLACES_DOS = ["run"];
116
116
  export const LINK_EXPERIMENT_DOS = ["on", "off"];
117
117
  /**
118
118
  * What a link does with the queue (the Strom app's "work on the queue"): the agent working alone — for as long as there
119
- * is work (loop: strom run --loop, only under a gate) or n tasks settled (tasks: strom run --tasks n). What starts is
120
- * shown and started only on the person's yes in the terminal (the bridge never starts one).
119
+ * is work (loop: strom run --loop, only under a gate), n tasks settled (tasks: strom run --tasks n) or the tasks the link
120
+ * names (tasks with task=T…,T…: strom run --task, one session each — the app's "work on them now" after a try of the
121
+ * verification, spec 065 K7.2). What starts is shown and started only on the person's yes in the terminal (the bridge
122
+ * never starts one).
121
123
  */
122
124
  export const LINK_WORK_DOS = ["loop", "tasks"];
123
125
  /** The most tasks a link asks for (strom run --tasks: 1–100); none named: the app's default. */
@@ -411,6 +413,15 @@ function linkParts(text, scheme) {
411
413
  if (!q.has("do"))
412
414
  throw new LinkError("nothing to do named");
413
415
  const what = oneOf(q, "do", LINK_WORK_DOS);
416
+ if (q.has("task")) {
417
+ // the tasks named (feature work.tasks): only with do=tasks, never with n; IDs alone, at most LINK_WORK_MAX, each once
418
+ if (what !== "tasks" || q.has("n"))
419
+ throw new LinkError("task only with do=tasks, not with n");
420
+ const ids = (q.get("task") ?? "").split(",").map((x) => x.trim().toUpperCase());
421
+ if (!ids.length || ids.length > LINK_WORK_MAX || !ids.every((x) => TASK.test(x)))
422
+ throw new LinkError(`task is 1–${LINK_WORK_MAX} task IDs, T…,T…`);
423
+ return { action, tree: id, do: what, task: [...new Set(ids)].join(",") };
424
+ }
414
425
  if (!q.has("n"))
415
426
  return { action, tree: id, do: what };
416
427
  if (what !== "tasks")