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
package/dist/core/live.js CHANGED
@@ -23,7 +23,7 @@
23
23
  // working.helps.
24
24
  // work {gate, minutes} (features work.link, run.tasks; none in an archive or a research
25
25
  // waiting for its agent): before the Strom app's link work (strom-research://work?tree=…&do=loop|
26
- // tasks[&n=1..100], taken in the terminal on the person's yes — the bridge never starts an agent)
26
+ // tasks[&n=1..100 | &task=T…,T… — feature work.tasks: these tasks, one session each], taken in the terminal on the person's yes — the bridge never starts an agent)
27
27
  // the gate the agent works alone under as the settings name it (title and what it is given),
28
28
  // null with none set (the loop is not started then, n tasks are), and a session's minutes
29
29
  // (run.minutes). busy {sessions, runs} sees a run from its start, while it waits for its gate too.
@@ -52,7 +52,9 @@
52
52
  // research}; none for a task about nobody) — feature queue.own. Each in the queue says its place
53
53
  // in the whole queue (pos: 1 the next, the one at work first; none for one put aside), and
54
54
  // queueCounts {research: {G…: n}, branch: {B-P…: n}, next, parked} counts the queue's tasks by
55
- // the same research and branch GET /queue filters by — feature queue.page. The order is strom
55
+ // the same research and branch GET /queue filters by — feature queue.page; queueCounts.kind
56
+ // {verify|records|material|places|enrich|request|story|history|other: n} (only the kinds with
57
+ // a task) and each item's taskKind: the kind of the work (core/taskkind.ts) — feature queue.kind. The order is strom
56
58
  // run's (core/queue.ts runOrder): one story first at a story's turn, the tasks of history by
57
59
  // their pace; kind: story | history says such a task (none for the research's work)
58
60
  // GET <token>/tree.ged the tree for the Strom app, as it is now, each entry with its image (the settings excerpts.*);
@@ -143,7 +145,10 @@
143
145
  // citing them named in `people` too. `left` (feature material.left): {at, sort, why:
144
146
  // nothing-said|nothing-new|dropped, said?} — the last sort done that took it proposed nothing
145
147
  // of it (from the sorts kept here; a later proposal takes it off). `sameAs` (feature
146
- // material.sameAs): the oldest other file of the same content (SHA-256)
148
+ // material.sameAs): the oldest other file of the same content (SHA-256). ?trees=1 (feature
149
+ // material.trees, spec 117 K2.1): the family trees' files too, kind "tree" — an input of a family
150
+ // tree (GEDCOM, the app's JSON) with its bytes, never one a sync sent nor an old import without
151
+ // its file; `uses.of` via input only for a source standing. Without it: as before
147
152
  // GET <token>/material/<I…>/uses where the research uses a file (V10): {excerpts: [{source, recordset?, page?,
148
153
  // sha}], sources: [{id, title}], tasks: [{id, title, state}], of (as above)}; 404 material.file
149
154
  // POST <token>/material/assign the people files are of ({files: [I…] | batch, add: [P…], remove: [P…]}): strom
@@ -166,6 +171,16 @@
166
171
  // minutes); {files, confirm} → strom input delete: {files, deleted, impacts, head}. Impacts
167
172
  // changed since: 409 material.delete-changed {impacts}; no confirm that holds: 400 material.body;
168
173
  // 404 material.file, 403 material.readonly, 409 material.busy (+ Retry-After), 403 app.only.
174
+ // A family tree's file (feature material.trees, spec 117 K2.1–K2.3) as any file — one a source
175
+ // standing was made of (source.input, input.source) has impacts[].blockedBy [S…] and is deleted
176
+ // only with it: {files, confirm} alone 409 material.source-live {sources: [S…]} (params.sources
177
+ // "S…,S…"); {files, retractSources: [S…] (only of blockedBy), dryRun: true} → {files,
178
+ // retractSources, dryRun, impacts, sourceImpacts (as /source/retract's impacts), confirm} —
179
+ // one confirm over both; {files, retractSources, confirm} → strom input delete
180
+ // --retract-sources: the sources deleted first, the files taken back, one commit, only then the
181
+ // bytes (R7; a failure anywhere writes nothing): {files, deleted, retracted, impacts,
182
+ // sourceImpacts, head}; changed since: 409 material.delete-changed {impacts, sourceImpacts};
183
+ // a source unknown or deleted already: 404 source.unknown | 409 source.retracted {id}.
169
184
  // POST <token>/material/sort files sorted by readers of the research (V13, feature material.sort — only where
170
185
  // accepts.read is: never an archive nor a research waiting for its agent; live-sort.ts):
171
186
  // {ids: [I…] (1–50), text (≤ 2000 characters)} → 202 {id, state: "queued"}; sorted one at a time
@@ -194,6 +209,28 @@
194
209
  // files, filesDone, parts: [{id, part, state, files, filesDone?}], waiting?: {why: read.app |
195
210
  // limit | …, retry?}} (ended: cancelled when a part was cancelled, else done when a part is done, else failed);
196
211
  // POST …/<run-…>/cancel: its parts not done stopped, {id, state, cancelled}
212
+ // POST <token>/source/retract a source deleted by the person (spec 117 K1.1–K1.7, R4, J7; feature source.retract),
213
+ // in the app's dialog, in two steps: {sources: [S…] (1–50), dryRun: true} → {sources, dryRun:
214
+ // true, impacts: [{id, title, input?, counts: {persons: 0, names, events, families, stories},
215
+ // cites: [{owner, fact, event?, others, locator?, main?}], stories: [{owner, inText}], bare:
216
+ // [{owner, fact, event?}], lowered: [{owner, fact, event?, from, to}] (a bare one among them),
217
+ // conflicts: [{id, status, becomes: review|unchanged}], tasks: [{id, state, becomes: dropped|
218
+ // narrowed, heldBy?}], files: [I…], images, more: {…}}] (200 a list at most), confirm} (nothing
219
+ // written; confirm: signed by the bridge with the seal key over the sources and the impacts, 15
220
+ // minutes); {sources, confirm} → strom source retract --confirm (checked again under the
221
+ // tree's lock): {sources, retracted, impacts, head}. Impacts changed since: 409
222
+ // source.retract-changed {impacts}; no confirm that holds, a body it cannot read, more than
223
+ // 50: 400 source.body; 404 source.unknown {id}; 409 source.retracted {id}; 403 source.readonly
224
+ // (+ reasonCode; not sealed here: no confirm); 409 source.busy (+ Retry-After); 500
225
+ // source.failed. No queue an agent could write to.
226
+ // POST <token>/source/restore sources the person deleted put back ({sources: [S…] (1–50)}): strom source restore;
227
+ // {restored, citations, skipped: [{source, owner, fact, event?, why: gone|already|main}],
228
+ // raised, tasks, conflicts, head}. 409 source.notRetracted {id} | source.notRestorable {id,
229
+ // why: merged|other}, otherwise as /source/retract.
230
+ // POST <token>/conflict/keep a decided conflict marked for review (a deleted source it stood on) kept as decided
231
+ // ({conflict: X…}): strom conflict keep; {conflict, head}. 404 conflict.unknown {id}, 409
232
+ // conflict.notMarked {id} (open, or no mark), 400 source.body, 403 source.readonly, 409
233
+ // source.busy (+ Retry-After), 500 source.failed.
197
234
  // Every write of the app's (these, PUT /media, /batch/<id>/done, /waiting, /group) answers
198
235
  // `head` after it and `parent`, the head just before it (nothing written: parent = head) —
199
236
  // the app takes head as its version only when parent is the head it knew
@@ -399,7 +436,9 @@
399
436
  // bulk), after the lines' work; a family tree's leads too, their record looked for — {ok,
400
437
  // people, facts, how: {read, search} (of the facts), tasks (not dry), left, estimate, head,
401
438
  // parent}; 400 verify.invalid, 404 verify.unknown, 409 verify.archive | verify.nothing, 503
402
- // research.busy (feature verify.bulk)
439
+ // research.busy (feature verify.bulk). Not dry: first (a try's tasks first in the queue, as
440
+ // the person's "verify" — spec 065 K7.1) and working (a run or a session at work now: the app
441
+ // offers the link work?do=tasks&task=<tasks> only when false — K7.2) — feature verify.tryFirst
403
442
  // POST <token>/verify/stop {"scope"?: "all"|"bulk"}: the user stops the verification (strom verify stop [--bulk]) —
404
443
  // the tasks nobody started dropped, one at work goes on, their facts not queued again by
405
444
  // themselves — {ok, dropped, facts, head, parent}; nothing to stop: dropped 0, nothing written;
@@ -506,7 +545,9 @@
506
545
  // GET <token>/offline/<B-…> one branch and all its open tasks (those not taken too): {branch, tasks: [{id, text,
507
546
  // pos?, person?, own?}]}; 404 offline.none, 409 directions.archive, 503 research.busy
508
547
  // GET <token>/queue a page of the whole queue (feature queue.page): ?from=<0…> (among the tasks the filter
509
- // leaves) &count=<1…100, 50> &branch=B-P… &research=G… &state=next|parked — {items (as /status
548
+ // leaves) &count=<1…100, 50> &branch=B-P… &research=G… &state=next|parked &kind=<a kind of
549
+ // core/taskkind.ts: verify, records, material, places, enrich, request, story, history, other;
550
+ // feature queue.kind> — {items (as /status
510
551
  // queue[], with pos), total (what the filter leaves), from, next? (from of the next page), head};
511
552
  // in the order of the queue, those put aside after it without pos; an archive: none. 400
512
553
  // queue.query, 503 research.busy (+ Retry-After). &q=<1…100 characters> (feature queue.search):
@@ -533,6 +574,12 @@
533
574
  // books.minTasks … / queue.sameBook … --for-tree ("default": config unset --for-tree) — {books
534
575
  // {settings} (as /status books.settings), head, parent (head when nothing changed)}; feature
535
576
  // books; 400 books.body, 409 directions.archive, 503 research.busy
577
+ // POST <token>/books/aside {file (as /status books.aside lists it), do: discard|take|image, image?: n} (feature
578
+ // inbox.aside): strom media aside <file> --discard|--take|--image n — a file of a book's folder
579
+ // of the inbox set aside, not taken (the same file as another image: only discard; another scan
580
+ // than the image of its number: discard, take — it is that image, the one there withdrawn —, or
581
+ // image n) — {done, added, replaced, aside (the list now), head, parent}; 400 aside.body, 404
582
+ // aside.unknown {aside}, 409 aside.same | aside.taken | directions.archive, 503 research.busy
536
583
  // POST <token>/queue/<T…> {do: next|last|default}: strom task order --next|--last|--default (any open task; next
537
584
  // once, the last chosen first) — {task (as queue[]), was ({} or {own: next|last, at}: its turn
538
585
  // before), head, parent}; {do: restore, was: {} | {own, at}}: the turn put back exactly as it
@@ -614,6 +661,7 @@ import { adoptedAt, notWrittenList, adoptedEmpty, adoptionWait, noteAdoptAsked,
614
661
  import { isArchive, modeOf, settleArchive } from "./mode.js";
615
662
  import { actsAsArchive, kindOf, settleWaiting, stateOf } from "./state.js";
616
663
  import { forStory } from "./stories.js";
664
+ import { kindCounts, parseTaskKind, TASK_KINDS, taskKind } from "./taskkind.js";
617
665
  import { factMark, transcriptMark } from "./readers.js";
618
666
  import { raiseHypothesisLinkTasks, settleHypothesisLinks } from "./hypolinks.js";
619
667
  import { settleReaders } from "./readerfix.js";
@@ -626,7 +674,8 @@ import { ui } from "../cli/ui.js";
626
674
  import { DISK_FULL, EXIT, isDiskFull, StromError } from "./errors.js";
627
675
  import { acquireLock, liveHolder } from "./lock.js";
628
676
  import { checkAsked, checkEdit, material, MATERIAL_MOST_EDIT, MATERIAL_MOST_FILES, MATERIAL_MOST_PEOPLE, materialUses, peopleOf, workingCopyOf } from "./material.js";
629
- import { checkDeleteConfirm, deleteConfirm, DELETE_MOST_FILES, deleteImpacts } from "./materialdelete.js";
677
+ import { checkDeleteConfirm, checkRetractWith, deleteConfirm, DELETE_MOST_FILES, deleteImpacts, deleteSourceImpacts, refuseLiveSources } from "./materialdelete.js";
678
+ import { checkRetractConfirm, keepable, restorable, RETRACT_MOST, retractConfirm, retractImpacts } from "./sourceretract.js";
630
679
  import { cachedThumb, THUMB_SIZES } from "./thumbs.js";
631
680
  import { checkOriginalMeta, cleanIncoming, freeBytes, knownOriginal, materialWaiting, originalMax, ORIGINAL_RESERVE, ORIGINAL_TYPES, parseRegion } from "./originals.js";
632
681
  import { BATCH_ID, batchEstimate, batchLimits, batchPath, batchStatus, idleBatches, readBatch } from "./batches.js";
@@ -652,7 +701,7 @@ const EXCERPTS_AT_ONCE = 12;
652
701
  import { anyoneAtWork, liveWorkers, otherVersionsAtWork } from "./workers.js";
653
702
  import { widgetTree, widgetWriter } from "./widget.js";
654
703
  import { monthSpend, openSessions } from "./session.js";
655
- import { busyIn } from "./busy.js";
704
+ import { busyIn, workingNow } from "./busy.js";
656
705
  import { effectiveState, restoredTurn, runOrder, turnWas } from "./queue.js";
657
706
  import { humanTask } from "../cli/human.js";
658
707
  import { foldText } from "./text.js";
@@ -665,7 +714,7 @@ import { suggestSurnames } from "./surnames.js";
665
714
  import { judgePairs, pairsOf, PAIRS_MAX } from "./duplicates.js";
666
715
  import { askOf, qualityRev, readDismissed } from "./quality.js";
667
716
  import { BOOKS_MIN_TASKS, BOOKS_MIN_TASKS_MAX, configFile, DEFAULT_RUN_MINUTES, LIVE_IDLE_CHOICES, LIVE_IDLE_MAX_MINUTES, loadUserConfig, readStored, Settings } from "./config.js";
668
- import { folderFiles } from "./inboxwait.js";
717
+ import { asideFiles, folderFiles } from "./inboxwait.js";
669
718
  import { gateLabel } from "./gate.js";
670
719
  import { LINK_SCHEME, linkActions, linkHandlerState, linkHandlerStateLater, linkScheme, linkText } from "./links.js";
671
720
  import { handoffsNow } from "./handoffs.js";
@@ -1694,7 +1743,7 @@ export function tagMatches(req, tag) {
1694
1743
  .map((t) => t.trim().replace(/^W\//u, ""))
1695
1744
  .some((t) => t === "*" || t === tag);
1696
1745
  }
1697
- export const BRIDGE_FEATURES = ["sync.again", "sync.undoneSince", "sync.takenBack", "sync.conflictEdit", "sync.since", "sync.ids", "family.noCouple", "family.alone", "adopt.transfer", "adopt.empty", "material.list", "person.titles", "media.codes", "hypothesis.links", "status.recent", "spend.readers", "hypothesis.intree", "archive.permission", "task.check", "waiting.groups", "waiting.sent", "waiting.note", "batch.kept", "live.end", "whats.new", "terminal.choice", "person.marriedSurname", "phone", "read.now", "read.sync", "excerpt.get", "log.sources", "material.assign", "material.thumb", "seal.foreign", "tree.state", "disk.full", "tree.notDownloaded", "sync.removed", "tree.kind", "experiments", "experiments.off", "experiments.link", "experiments.split", "history.events", "history.hide", "experiments.pace", "history.first", "history.regions", "history.hide.all", "history.skip", "history.map", "history.delete", "history.delete.restore", "stories.history", "history.place", "surnames.suggest", "surnames.read", "lineage.read", "duplicates.judge", "quality.dismiss", "quality.read", "person.primary", "fixes.list", "fixes.towns", "history.back", "places.identify", "places.answer", "places.undo", "tasks.offLine", "status.busy", "history.kinds", "history.align", "places.nameKinds", "directions.edit", "directions.order", "directions.found", "directions.people", "directions.places", "offLine.branches", "queue.own", "story.sources", "queue.page", "status.parts", "waiting.answer", "browser.state", "working.place", "working.family", "working.helps", "hypotheses.decide", "sources.confirm", "read.sourceTask", "read.sourceTask.unsure", "read.choose", "read.choices.now", "read.source", "read.sourceEntry", "read.blindText", "read.kinds", "read.variantKind", "read.readerState", "live.idle", "live.stop", "live.start", "sources.proposal", "sources.proposal.undo", "origin", "origin.ids", "verify", "verify.bulk", "facts.confirm", "verify.stop", "ged.stale", "facts.confirm.value", "ged.etag", "ged.imagesByHash", "hypothesis.decide.link", "hypotheses.accept.link", "sources.fields", "sources.split", "queue.search", "queue.next", "work.link", "run.tasks", "event.share", "citations.order", "sync.notWritten.codes", "citations.main", "citations.remove", "books", "media.app", "material.links", "material.edit", "material.uses", "material.sort", "tasks.audit", "handoffs", "material.sourceOf", "material.left", "material.sameAs", "material.sortRun", "material.delete"];
1746
+ export const BRIDGE_FEATURES = ["sync.again", "sync.undoneSince", "sync.takenBack", "sync.conflictEdit", "sync.since", "sync.ids", "family.noCouple", "family.alone", "adopt.transfer", "adopt.empty", "material.list", "person.titles", "media.codes", "hypothesis.links", "status.recent", "spend.readers", "hypothesis.intree", "archive.permission", "task.check", "waiting.groups", "waiting.sent", "waiting.note", "batch.kept", "live.end", "whats.new", "terminal.choice", "person.marriedSurname", "phone", "read.now", "read.sync", "excerpt.get", "log.sources", "material.assign", "material.thumb", "seal.foreign", "tree.state", "disk.full", "tree.notDownloaded", "sync.removed", "tree.kind", "experiments", "experiments.off", "experiments.link", "experiments.split", "history.events", "history.hide", "experiments.pace", "history.first", "history.regions", "history.hide.all", "history.skip", "history.map", "history.delete", "history.delete.restore", "stories.history", "history.place", "surnames.suggest", "surnames.read", "lineage.read", "duplicates.judge", "quality.dismiss", "quality.read", "person.primary", "fixes.list", "fixes.towns", "history.back", "places.identify", "places.answer", "places.undo", "tasks.offLine", "status.busy", "history.kinds", "history.align", "places.nameKinds", "directions.edit", "directions.order", "directions.found", "directions.people", "directions.places", "offLine.branches", "queue.own", "story.sources", "queue.page", "status.parts", "waiting.answer", "browser.state", "working.place", "working.family", "working.helps", "hypotheses.decide", "sources.confirm", "read.sourceTask", "read.sourceTask.unsure", "read.choose", "read.choices.now", "read.source", "read.sourceEntry", "read.blindText", "read.kinds", "read.variantKind", "read.readerState", "live.idle", "live.stop", "live.start", "sources.proposal", "sources.proposal.undo", "origin", "origin.ids", "verify", "verify.bulk", "facts.confirm", "verify.stop", "ged.stale", "facts.confirm.value", "ged.etag", "ged.imagesByHash", "hypothesis.decide.link", "hypotheses.accept.link", "sources.fields", "sources.split", "queue.search", "queue.next", "work.link", "run.tasks", "queue.kind", "work.tasks", "verify.tryFirst", "event.share", "citations.order", "sync.notWritten.codes", "citations.main", "citations.remove", "books", "media.app", "material.links", "material.edit", "material.uses", "material.sort", "tasks.audit", "handoffs", "material.sourceOf", "material.left", "material.sameAs", "material.sortRun", "material.delete", "inbox.aside", "source.retract", "material.trees"];
1698
1747
  /** What only a research with its agent here does (accepts.read: none in an archive, nor where it waits for its agent). */
1699
1748
  const AGENT_FEATURES = new Set(["material.sort"]);
1700
1749
  const withoutAgent = (features) => features.filter((f) => !AGENT_FEATURES.has(f));
@@ -2213,7 +2262,7 @@ function whereInQueue(place, offLine, file, t, r) {
2213
2262
  }
2214
2263
  /** One task as the queue has it: ranked (in the queue: its place, its why, its own turn), else as it stands among the lines alone. */
2215
2264
  function queueItem(tree, place, offLine, file, state, t, r, pos) {
2216
- return { id: t.id, text: humanTask(tree, t.what, tree.lang), state, ...(pos ? { pos } : {}), ...personOf(t), ...whereInQueue(place, offLine, file, t, r), ...(r?.own ? { own: r.own } : {}), ...(r?.reason ? { why: r.reason } : {}), ...(forStory(t) ? { kind: "story" } : forHistory(t) ? { kind: "history" } : {}), ...bookPart(tree, t), ...(r?.sameBook ? { sameBook: r.sameBook } : {}) };
2265
+ return { id: t.id, text: humanTask(tree, t.what, tree.lang), state, ...(pos ? { pos } : {}), ...personOf(t), ...whereInQueue(place, offLine, file, t, r), ...(r?.own ? { own: r.own } : {}), ...(r?.reason ? { why: r.reason } : {}), ...(forStory(t) ? { kind: "story" } : forHistory(t) ? { kind: "history" } : {}), taskKind: taskKind(t), ...bookPart(tree, t), ...(r?.sameBook ? { sameBook: r.sameBook } : {}) };
2217
2266
  }
2218
2267
  function bookPart(tree, t) {
2219
2268
  const book = bookOfTask(tree, t);
@@ -2275,7 +2324,8 @@ function queueCounts(ranked, parked, rev) {
2275
2324
  if (r.branch)
2276
2325
  branch[r.branch] = (branch[r.branch] ?? 0) + 1;
2277
2326
  }
2278
- return { research, branch, next: ranked.length, parked, ...(rev ? { rev } : {}) };
2327
+ // by the kind of the work (feature queue.kind): only the kinds with a task, the same GET /queue?kind= filters by
2328
+ return { research, branch, kind: kindCounts(ranked.map((r) => r.task)), next: ranked.length, parked, ...(rev ? { rev } : {}) };
2279
2329
  }
2280
2330
  /** At most so many tasks in one page of GET /queue; so many when the app says none. */
2281
2331
  export const QUEUE_PAGE_MAX = 100;
@@ -2284,8 +2334,8 @@ const QUEUE_PAGE = 50;
2284
2334
  export const QUERY_MAX = 100;
2285
2335
  /** The query of GET /queue read, or why it is none (400 queue.query). */
2286
2336
  export function queueAsk(q) {
2287
- const shape = `?from=<0…>&count=<1…${QUEUE_PAGE_MAX}>&branch=B-P…&research=G…&state=next|parked&q=<1…${QUERY_MAX} characters> (each optional)`;
2288
- const known = new Set(["from", "count", "branch", "research", "state", "q", "app", "poll"]);
2337
+ const shape = `?from=<0…>&count=<1…${QUEUE_PAGE_MAX}>&branch=B-P…&research=G…&state=next|parked&kind=${TASK_KINDS.join("|")}&q=<1…${QUERY_MAX} characters> (each optional)`;
2338
+ const known = new Set(["from", "count", "branch", "research", "state", "kind", "q", "app", "poll"]);
2289
2339
  for (const k of q.keys())
2290
2340
  if (!known.has(k))
2291
2341
  return { bad: `unknown ${k}: ${shape}` };
@@ -2323,6 +2373,13 @@ export function queueAsk(q) {
2323
2373
  return { bad: `state=next|parked: ${shape}` };
2324
2374
  ask.state = st;
2325
2375
  }
2376
+ const kd = q.get("kind");
2377
+ if (kd !== null) {
2378
+ const k = parseTaskKind(kd);
2379
+ if (!k)
2380
+ return { bad: `kind=${TASK_KINDS.join("|")}: ${shape}` };
2381
+ ask.kind = k;
2382
+ }
2326
2383
  // what to find: never said back in a refusal (nor in the log — masked)
2327
2384
  const find = q.get("q");
2328
2385
  if (find !== null) {
@@ -2355,7 +2412,7 @@ export function queuePage(tree, settings, ask, h) {
2355
2412
  if (ask.state !== "next")
2356
2413
  for (const t of order.parked)
2357
2414
  entries.push({ t, where: whereInQueue(place, offLine, file, t) });
2358
- const left = entries.filter((e) => (!ask.branch || e.where.branch === ask.branch) && (!ask.research || e.where.research === ask.research));
2415
+ const left = entries.filter((e) => (!ask.branch || e.where.branch === ask.branch) && (!ask.research || e.where.research === ask.research) && (!ask.kind || taskKind(e.t) === ask.kind));
2359
2416
  // what the person searches for: among what the filters leave, in the order of the queue, then paged
2360
2417
  const found = ask.q === undefined ? undefined : searchQueue(tree, order, left, ask.q);
2361
2418
  const rows = found ? found.rows : left;
@@ -2537,7 +2594,8 @@ function booksSettings(tree, settings) {
2537
2594
  * /status books (spec 105, feature books): the settings, and the books — each one something waits on (the app's groups
2538
2595
  * by book), and those offered to download (offer) — the most tasks first, at most BOOKS_LIST_MAX (more: the rest). Each
2539
2596
  * as strom task books --json says it, without the task IDs and the folder's path; pending: the files lying in its folder
2540
- * not taken yet (only when any).
2597
+ * not taken yet (only when any). aside (feature inbox.aside, only when any): the files of the books' folders set aside,
2598
+ * not taken — a question each for the person (asideJson, POST /books/aside).
2541
2599
  */
2542
2600
  function booksStatus(tree, settings) {
2543
2601
  const shared = settings.shared()?.value;
@@ -2547,7 +2605,17 @@ function booksStatus(tree, settings) {
2547
2605
  const pending = shared ? folderFiles(path.join(shared, "inbox", r.folder)).length : 0;
2548
2606
  return { ...row, ...(pending ? { pending } : {}) };
2549
2607
  });
2550
- return { settings: booksSettings(tree, settings), list: shown, more: rows.length - shown.length };
2608
+ const aside = asideJson(tree, settings);
2609
+ return { settings: booksSettings(tree, settings), list: shown, more: rows.length - shown.length, ...(aside.length ? { aside } : {}) };
2610
+ }
2611
+ /**
2612
+ * The files of the books' folders of the inbox set aside, not taken (B0408, B0374; feature inbox.aside), newest first:
2613
+ * {file (as it lies in the book's folder, the key of the answer), name (the file's own name, as saved: what a person
2614
+ * reads), recordset, image?, kind: "same" (the same file as image `media`, registered under another number) | "other"
2615
+ * (another scan than `media`, the image of its number), media, at} — each a question for the person (POST /books/aside).
2616
+ */
2617
+ function asideJson(tree, settings) {
2618
+ return asideFiles(tree, settings.shared()?.value).map((a) => ({ file: a.file, name: a.name, recordset: a.recordset, ...(a.image !== undefined ? { image: a.image } : {}), kind: a.kind, media: a.media, at: a.at }));
2551
2619
  }
2552
2620
  /** The work off the lines without its branches (the answer to POST /offline): also for a research of one line, where nothing is off them. */
2553
2621
  function offLineSummary(tree, settings) {
@@ -3621,6 +3689,12 @@ export function serveLive(root, env) {
3621
3689
  batchDone(req, res, origin, decodeURIComponent(sub ?? ""));
3622
3690
  return;
3623
3691
  }
3692
+ // a decided conflict marked for review kept as decided (spec 117 J4): no decision of it — the decision stands as the
3693
+ // person made it, only the mark of a source they deleted goes (deciding it again stays the terminal's, below)
3694
+ if (req.method === "POST" && t === token && what === "conflict" && sub === "keep" && !act) {
3695
+ writeFor(req, res, origin, conflictKeep());
3696
+ return;
3697
+ }
3624
3698
  if (req.method === "POST" && t === token && what === "conflict" && sub && !act) {
3625
3699
  // the bridge cannot tell the app from an agent on this computer (the secret is in the research's folder, an Origin
3626
3700
  // is a header any program sets): a conflict is the person's to decide, in the terminal its link opens — refused
@@ -3648,6 +3722,11 @@ export function serveLive(root, env) {
3648
3722
  writeFor(req, res, origin, booksWrite());
3649
3723
  return;
3650
3724
  }
3725
+ // a file of a book's folder of the inbox set aside (B0408, B0374): the person's answer which one is the image
3726
+ if (req.method === "POST" && t === token && what === "books" && sub === "aside") {
3727
+ writeFor(req, res, origin, asideWrite());
3728
+ return;
3729
+ }
3651
3730
  // work off the lines: a branch's choice, the tree's, a task's own turn — each a strom command
3652
3731
  if (req.method === "POST" && t === token && what === "offline" && !act) {
3653
3732
  writeFor(req, res, origin, sub ? offlineBranchWrite(decoded(sub)) : offlineTreeWrite());
@@ -3669,6 +3748,11 @@ export function serveLive(root, env) {
3669
3748
  writeFor(req, res, origin, materialDelete());
3670
3749
  return;
3671
3750
  }
3751
+ // a source the person deletes, puts back; a decision kept without it (spec 117)
3752
+ if (req.method === "POST" && t === token && what === "source" && (sub === "retract" || sub === "restore") && !act) {
3753
+ writeFor(req, res, origin, sub === "retract" ? sourceRetract() : sourceRestore());
3754
+ return;
3755
+ }
3672
3756
  if (req.method === "POST" && t === token && what === "history" && sub === "hide" && !act) {
3673
3757
  writeFor(req, res, origin, historyHide());
3674
3758
  return;
@@ -3893,11 +3977,13 @@ export function serveLive(root, env) {
3893
3977
  const person = (q.get("person") ?? "").toUpperCase();
3894
3978
  const batch = q.get("batch") ?? "";
3895
3979
  const files = q.get("files");
3980
+ // the family trees' files too (spec 117 K2.1): only to an app that asks, never to an older one
3981
+ const trees = q.get("trees");
3896
3982
  const json = (code, body) => res.writeHead(code, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" }).end(JSON.stringify(body));
3897
- if ((q.has("person") && !/^P\d{1,9}$/.test(person)) || (q.has("batch") && !BATCH_ID.test(batch)) || (files !== null && files !== "0" && files !== "1"))
3898
- json(400, { ...refusal("?person=P… (a person of the research), ?batch=<the batch's mark>, ?files=0 (the batches only)", "material.query") });
3983
+ if ((q.has("person") && !/^P\d{1,9}$/.test(person)) || (q.has("batch") && !BATCH_ID.test(batch)) || (files !== null && files !== "0" && files !== "1") || (trees !== null && trees !== "0" && trees !== "1"))
3984
+ json(400, { ...refusal("?person=P… (a person of the research), ?batch=<the batch's mark>, ?files=0 (the batches only), ?trees=1 (the family trees' files too)", "material.query") });
3899
3985
  else
3900
- json(200, material(Tree.open(root, env), new Settings(env, {}).shared()?.value, { ...(person ? { person } : {}), ...(batch ? { batch } : {}), ...(files === "0" ? { files: false } : {}) }));
3986
+ json(200, material(Tree.open(root, env), new Settings(env, {}).shared()?.value, { ...(person ? { person } : {}), ...(batch ? { batch } : {}), ...(files === "0" ? { files: false } : {}), ...(trees === "1" ? { trees: true } : {}) }));
3901
3987
  }
3902
3988
  else if (what === "history" && !sub) {
3903
3989
  // what the ancestors lived through: read in an archive too, and in a research waiting for its agent
@@ -4216,6 +4302,8 @@ export function serveLive(root, env) {
4216
4302
  ...(data.skipped?.length ? { skipped: data.skipped } : {}),
4217
4303
  // the app's files it wrote (spec 108): each change with the place it is of and the record the file is (I…)
4218
4304
  ...(data.media?.length ? { media: data.media } : {}),
4305
+ // the research's sources the person deleted in the app, deleted with the send (spec 117 K1.4)
4306
+ ...(data.retracted?.length ? { retracted: data.retracted } : {}),
4219
4307
  // the sources that said they are an entry of a reading of a document (_STROM_READING): taken as the
4220
4308
  // research's reading, or not (why: a stable code) and so the app's own source as any
4221
4309
  ...(changes.some((c) => c.reading)
@@ -4887,12 +4975,15 @@ export function serveLive(root, env) {
4887
4975
  * {files, confirm}: the impacts again, the same as signed, written by strom input delete --confirm (which checks it once
4888
4976
  * more under the tree's lock). Refused: 400 material.body (no confirm that holds, a body it cannot read), 404
4889
4977
  * material.file, 409 material.delete-changed {impacts} (the research changed since the person saw the list), 403
4890
- * material.readonly, 409 material.busy (+ Retry-After).
4978
+ * material.readonly, 409 material.busy (+ Retry-After). A family tree's file a source standing was made of (spec 117
4979
+ * K2.2): only with that source deleted first (retractSources, one confirm over both: impacts and sourceImpacts), else
4980
+ * 409 material.source-live {sources}.
4891
4981
  */
4892
4982
  const materialDelete = () => {
4893
4983
  let ids = [];
4984
+ let with_ = [];
4894
4985
  const bad = (why) => ({ code: 400, body: refusal(why, "material.body") });
4895
- const changed = (impacts) => ({ code: 409, body: { ...refusal("the files would take other things with them than the list said: look at it again", "material.delete-changed"), impacts } });
4986
+ const changed = (impacts, sourceImpacts) => ({ code: 409, body: { ...refusal("the files would take other things with them than the list said: look at it again", "material.delete-changed"), impacts, ...(sourceImpacts ? { sourceImpacts } : {}) } });
4896
4987
  return {
4897
4988
  what: "the material: delete",
4898
4989
  codes: MATERIAL_CODES,
@@ -4907,6 +4998,10 @@ export function serveLive(root, env) {
4907
4998
  return bad("dryRun: true, or a confirm");
4908
4999
  if (!dry && typeof body.confirm !== "string")
4909
5000
  return bad("confirm: what the dry run answered (dryRun: true first)");
5001
+ // the sources made of a family tree's file, deleted with it (spec 117 K2.2): none, or 1–50 of them
5002
+ const given = body.retractSources === undefined || (Array.isArray(body.retractSources) && !body.retractSources.length) ? [] : sourceList(body.retractSources);
5003
+ if (!given)
5004
+ return bad(`retractSources: 1 to ${RETRACT_MOST} IDs of sources (S…) made of the files`);
4910
5005
  const shared = new Settings(env, {}).shared()?.value;
4911
5006
  let impacts;
4912
5007
  try {
@@ -4915,36 +5010,82 @@ export function serveLive(root, env) {
4915
5010
  catch (e) {
4916
5011
  return refusedAsked(e);
4917
5012
  }
5013
+ let sourceImpacts;
5014
+ try {
5015
+ checkRetractWith(impacts, given);
5016
+ sourceImpacts = deleteSourceImpacts(tree, given);
5017
+ }
5018
+ catch (e) {
5019
+ if (e instanceof StromError && e.code === "material.body")
5020
+ return bad(e.message);
5021
+ return sourceAsked(e);
5022
+ }
4918
5023
  if (!writableHere())
4919
5024
  return { code: 403, body: refusal("nothing can be written into the research on this computer", "material.readonly") };
4920
5025
  const key = tree.key;
4921
5026
  if (!key)
4922
5027
  return { code: 403, body: refusal("the research is not sealed on this computer", "material.readonly") };
4923
5028
  const asked = impacts.map((i) => i.id);
5029
+ const sources = sourceImpacts.map((s) => s.id);
5030
+ const both = sources.length ? { sources, impacts: sourceImpacts } : undefined;
4924
5031
  if (dry)
4925
- return { code: 200, body: { files: asked, dryRun: true, impacts, confirm: deleteConfirm(key, asked, impacts) } };
4926
- const said = checkDeleteConfirm(key, asked, impacts, body.confirm);
5032
+ return { code: 200, body: { files: asked, ...(both ? { retractSources: sources } : {}), dryRun: true, impacts, ...(both ? { sourceImpacts } : {}), confirm: deleteConfirm(key, asked, impacts, Date.now(), both) } };
5033
+ // a source standing made of a file and not deleted with it: never the file alone (the confirm aside)
5034
+ try {
5035
+ refuseLiveSources(impacts, sources);
5036
+ }
5037
+ catch (e) {
5038
+ return refusedAsked(e);
5039
+ }
5040
+ const said = checkDeleteConfirm(key, asked, impacts, body.confirm, Date.now(), both);
4927
5041
  if (said === "changed")
4928
- return changed(impacts);
5042
+ return changed(impacts, both ? sourceImpacts : undefined);
4929
5043
  if (said !== "ok")
4930
5044
  return bad("confirm: none that holds (signed by this bridge, at most 15 minutes old) — dryRun: true again");
4931
5045
  ids = asked;
5046
+ with_ = sources;
4932
5047
  this.stdin = ids.join("\n");
4933
- return { args: ["input", "delete", "--files-from", "-", `--confirm=${String(body.confirm)}`] };
5048
+ return { args: ["input", "delete", "--files-from", "-", ...(sources.length ? [`--retract-sources=${sources.join(",")}`] : []), `--confirm=${String(body.confirm)}`] };
4934
5049
  },
4935
5050
  done(_tree, data, head) {
4936
- return { files: Array.isArray(data.files) ? data.files : ids, deleted: Array.isArray(data.deleted) ? data.deleted : [], impacts: data.impacts ?? [], head };
5051
+ return {
5052
+ files: Array.isArray(data.files) ? data.files : ids,
5053
+ deleted: Array.isArray(data.deleted) ? data.deleted : [],
5054
+ ...(with_.length ? { retracted: Array.isArray(data.retracted) ? data.retracted : [] } : {}),
5055
+ impacts: data.impacts ?? [],
5056
+ ...(with_.length ? { sourceImpacts: data.sourceImpacts ?? [] } : {}),
5057
+ head,
5058
+ };
4937
5059
  },
4938
- refused(tree, code, why) {
5060
+ refused(tree, code, why, data) {
4939
5061
  if (code === "material.delete-changed") {
4940
5062
  let impacts = [];
5063
+ let sourceImpacts;
4941
5064
  try {
4942
5065
  impacts = deleteImpacts(tree, new Settings(env, {}).shared()?.value, ids);
4943
5066
  }
4944
5067
  catch {
4945
5068
  // the files are gone meanwhile: the list is empty
4946
5069
  }
4947
- return changed(impacts);
5070
+ if (with_.length)
5071
+ try {
5072
+ sourceImpacts = deleteSourceImpacts(tree, with_);
5073
+ }
5074
+ catch {
5075
+ // a source gone or deleted meanwhile: no list
5076
+ sourceImpacts = [];
5077
+ }
5078
+ return changed(impacts, sourceImpacts);
5079
+ }
5080
+ if (code === "material.source-live") {
5081
+ const params = data.params ?? {};
5082
+ const sources = String(params.sources ?? "").split(",").filter(Boolean);
5083
+ return { code: 409, body: { ...refusal(why, code, { sources: sources.join(",") }), sources } };
5084
+ }
5085
+ if (code.startsWith("source.")) {
5086
+ const r = sourceRefused(code, why, data.params ?? {});
5087
+ if (r)
5088
+ return r;
4948
5089
  }
4949
5090
  if (code === "material.body")
4950
5091
  return { code: 400, body: refusal(why, code) };
@@ -4956,6 +5097,154 @@ export function serveLive(root, env) {
4956
5097
  },
4957
5098
  };
4958
5099
  };
5100
+ /**
5101
+ * A source deleted by the person, put back, a decision kept without it (POST /source/retract | /source/restore,
5102
+ * POST /conflict/keep; spec 117) — the person's in the app, never a queue an agent could write to. Retract in two steps
5103
+ * as /material/delete: {sources, dryRun: true} answered here without a write, with the impacts and the bridge's
5104
+ * confirmation of them (signed with the seal key, 15 minutes); {sources, confirm}: written by strom source retract
5105
+ * --confirm, which checks it once more under the tree's lock. Refused: 400 source.body, 404 source.unknown |
5106
+ * conflict.unknown {id}, 409 source.retracted | source.notRetracted | source.notRestorable | conflict.notMarked {id},
5107
+ * 409 source.retract-changed {impacts}, 403 source.readonly, 409 source.busy (+ Retry-After), 500 source.failed.
5108
+ */
5109
+ const SOURCE_CODES = { badBody: "source.body", busy: "source.busy", failed: "source.failed" };
5110
+ const sourceStatus = {
5111
+ "source.body": 400,
5112
+ "source.unknown": 404,
5113
+ "conflict.unknown": 404,
5114
+ "source.retracted": 409,
5115
+ "source.notRetracted": 409,
5116
+ "source.notRestorable": 409,
5117
+ "conflict.notMarked": 409,
5118
+ };
5119
+ const sourceRefused = (code, why, params = {}) => {
5120
+ if (sourceStatus[code])
5121
+ return { code: sourceStatus[code], body: refusal(why, code, Object.fromEntries(Object.entries(params).map(([k, v]) => [k, String(v)]))) };
5122
+ if (code === "fs.no-permission" || code === "fs.sandboxed" || code === "git.unwritable" || code === "needs-consent" || code === "seal.other-key")
5123
+ return { code: 403, body: { ...refusal(why, "source.readonly"), reasonCode: code } };
5124
+ return undefined;
5125
+ };
5126
+ const sourceAsked = (e) => {
5127
+ if (e instanceof StromError && e.code && sourceStatus[e.code])
5128
+ return sourceRefused(e.code, e.message, e.params ?? {});
5129
+ throw e;
5130
+ };
5131
+ const readonly = (why) => ({ code: 403, body: refusal(why, "source.readonly") });
5132
+ const sourceList = (v) => (Array.isArray(v) && v.length && v.length <= RETRACT_MOST && v.every((x) => typeof x === "string" && x.length <= 40) ? v : undefined);
5133
+ const sourceRetract = () => {
5134
+ let ids = [];
5135
+ const bad = (why) => ({ code: 400, body: refusal(why, "source.body") });
5136
+ const changed = (impacts) => ({ code: 409, body: { ...refusal("deleting the source would take other things with it than the list said: look at it again", "source.retract-changed"), impacts } });
5137
+ return {
5138
+ what: "a source deleted",
5139
+ codes: SOURCE_CODES,
5140
+ max: 64 * 1024,
5141
+ ask(tree, body) {
5142
+ const sources = sourceList(body.sources);
5143
+ if (!sources)
5144
+ return bad(`sources: 1 to ${RETRACT_MOST} IDs of sources (S…)`);
5145
+ const dry = body.dryRun === true;
5146
+ if (!dry && body.dryRun !== undefined && body.dryRun !== false)
5147
+ return bad("dryRun: true, or a confirm");
5148
+ if (!dry && typeof body.confirm !== "string")
5149
+ return bad("confirm: what the dry run answered (dryRun: true first)");
5150
+ let impacts;
5151
+ try {
5152
+ impacts = retractImpacts(tree, sources);
5153
+ }
5154
+ catch (e) {
5155
+ return sourceAsked(e);
5156
+ }
5157
+ if (!writableHere())
5158
+ return readonly("nothing can be written into the research on this computer");
5159
+ const key = tree.key;
5160
+ if (!key)
5161
+ return readonly("the research is not sealed on this computer");
5162
+ const asked = impacts.map((i) => i.id);
5163
+ if (dry)
5164
+ return { code: 200, body: { sources: asked, dryRun: true, impacts, confirm: retractConfirm(key, asked, impacts) } };
5165
+ const said = checkRetractConfirm(key, asked, impacts, body.confirm);
5166
+ if (said === "changed")
5167
+ return changed(impacts);
5168
+ if (said !== "ok")
5169
+ return bad("confirm: none that holds (signed by this bridge, at most 15 minutes old) — dryRun: true again");
5170
+ ids = asked;
5171
+ this.stdin = ids.join("\n");
5172
+ return { args: ["source", "retract", "--sources-from", "-", `--confirm=${String(body.confirm)}`] };
5173
+ },
5174
+ done(_tree, data, head) {
5175
+ return { sources: Array.isArray(data.sources) ? data.sources : ids, retracted: Array.isArray(data.retracted) ? data.retracted : [], impacts: data.impacts ?? [], head };
5176
+ },
5177
+ refused(tree, code, why, data) {
5178
+ if (code === "source.retract-changed") {
5179
+ let impacts = [];
5180
+ try {
5181
+ impacts = retractImpacts(tree, ids);
5182
+ }
5183
+ catch {
5184
+ // a source gone or deleted meanwhile: no list
5185
+ }
5186
+ return changed(impacts);
5187
+ }
5188
+ return sourceRefused(code, why, data.params ?? {});
5189
+ },
5190
+ };
5191
+ };
5192
+ const sourceRestore = () => {
5193
+ let ids = [];
5194
+ return {
5195
+ what: "a source put back",
5196
+ codes: SOURCE_CODES,
5197
+ max: 16 * 1024,
5198
+ ask(tree, body) {
5199
+ const sources = sourceList(body.sources);
5200
+ if (!sources)
5201
+ return { code: 400, body: refusal(`sources: 1 to ${RETRACT_MOST} IDs of sources (S…)`, "source.body") };
5202
+ try {
5203
+ ids = restorable(tree, sources).map((s) => s.id);
5204
+ }
5205
+ catch (e) {
5206
+ return sourceAsked(e);
5207
+ }
5208
+ if (!writableHere())
5209
+ return readonly("nothing can be written into the research on this computer");
5210
+ this.stdin = ids.join("\n");
5211
+ return { args: ["source", "restore", "--sources-from", "-"] };
5212
+ },
5213
+ done(_tree, data, head) {
5214
+ const { commit: _commit, ...got } = data;
5215
+ return { ...got, restored: Array.isArray(data.restored) ? data.restored : ids, head };
5216
+ },
5217
+ refused(_tree, code, why, data) {
5218
+ return sourceRefused(code, why, data.params ?? {});
5219
+ },
5220
+ };
5221
+ };
5222
+ const conflictKeep = () => {
5223
+ let id = "";
5224
+ return {
5225
+ what: "a decision kept without a deleted source",
5226
+ codes: SOURCE_CODES,
5227
+ ask(tree, body) {
5228
+ if (typeof body.conflict !== "string" || !body.conflict.trim() || body.conflict.length > 40)
5229
+ return { code: 400, body: refusal("conflict: the conflict's ID (X…)", "source.body") };
5230
+ try {
5231
+ id = keepable(tree, body.conflict).id;
5232
+ }
5233
+ catch (e) {
5234
+ return sourceAsked(e);
5235
+ }
5236
+ if (!writableHere())
5237
+ return readonly("nothing can be written into the research on this computer");
5238
+ return { args: ["conflict", "keep", id] };
5239
+ },
5240
+ done(_tree, data, head) {
5241
+ return { conflict: typeof data.conflict === "string" ? data.conflict : id, head };
5242
+ },
5243
+ refused(_tree, code, why, data) {
5244
+ return sourceRefused(code, why, data.params ?? {});
5245
+ },
5246
+ };
5247
+ };
4959
5248
  /**
4960
5249
  * An event of history hidden at a place, a person or in the whole tree, or everything of a region, or shown again
4961
5250
  * (POST /history/hide {event, place} | {event, person} | {event, tree: true} | {region}, "do": "show"): strom history
@@ -6136,6 +6425,44 @@ export function serveLive(root, env) {
6136
6425
  refused: (_tree, code, why, data) => offlineRefused(code, why, data),
6137
6426
  };
6138
6427
  };
6428
+ /**
6429
+ * The person's answer to a file of the inbox set aside (POST /books/aside {file, do: "discard" | "take" | "image",
6430
+ * image?: n}; feature inbox.aside): strom media aside <file> --discard | --take | --image n — the same file as another
6431
+ * image: only discard (409 aside.same); another scan: discard (the image stays, the file into the system's trash),
6432
+ * take (it is the image of its number: the one there withdrawn, a cited one stays beside it), image n (it is image n,
6433
+ * not taken yet; 409 aside.taken). {aside: [the list now], done, added, replaced, head, parent}; 404 aside.unknown (no
6434
+ * such file set aside: answered already). Not in an archive nor a research waiting for its agent (409 directions.archive).
6435
+ */
6436
+ const asideWrite = () => {
6437
+ let before = "";
6438
+ return {
6439
+ what: "a file of the inbox set aside",
6440
+ codes: { badBody: "aside.body", busy: "research.busy", failed: "aside.failed" },
6441
+ busyStatus: 503,
6442
+ ask(tree, body) {
6443
+ const { file, do: act, image } = body;
6444
+ const ok = typeof file === "string" && file.length > 0 && file.length < 1024 && !/[\\/]/u.test(file) &&
6445
+ (act === "discard" || act === "take" || (act === "image" && typeof image === "number" && Number.isInteger(image) && image >= 1)) &&
6446
+ Object.keys(body).every((k) => k === "file" || k === "do" || (k === "image" && act === "image"));
6447
+ if (!ok)
6448
+ return { code: 400, body: refusal(`the body: {"file": "<as books.aside lists it>", "do": "discard" | "take" | "image", "image"?: n}`, "aside.body") };
6449
+ if (actsAsArchive(tree))
6450
+ return directionsArchive(tree);
6451
+ before = head(root);
6452
+ return { args: ["media", "aside", file, act === "image" ? `--image=${image}` : `--${act}`] };
6453
+ },
6454
+ done(tree, data, h) {
6455
+ return { ...data, aside: asideJson(tree, new Settings(env, {})), head: h, parent: before };
6456
+ },
6457
+ refused(tree, code, why) {
6458
+ if (code === "aside.unknown")
6459
+ return { code: 404, body: { ...refusal(why, code), aside: asideJson(tree, new Settings(env, {})) } };
6460
+ if (code === "aside.same" || code === "aside.taken")
6461
+ return { code: 409, body: refusal(why, code) };
6462
+ return undefined;
6463
+ },
6464
+ };
6465
+ };
6139
6466
  /**
6140
6467
  * The bridge itself (POST /live): {"idleMinutes": n} — strom config set live.idleMinutes n (this computer's, every
6141
6468
  * tree's bridge; nothing of the research committed; as it is already: 200, nothing written) — or {"do": "stop"}: ended
@@ -6529,8 +6856,9 @@ export function serveLive(root, env) {
6529
6856
  /**
6530
6857
  * The person's bulk verification (POST /verify/bulk {scope: line|lineage|tree, of?, order?, try?, budget?, dry?}):
6531
6858
  * strom verify bulk, after the lines' work — a family tree's leads too, their record looked for (Dotazy 2 of the
6532
- * app, 3). {ok, people, facts, how: {read, search}, tasks, left, estimate: {sessions, usd?}, head, parent};
6533
- * dry: no tasks, head == parent. 400 verify.invalid, 404 verify.unknown, 409 verify.archive | verify.nothing, 503
6859
+ * app, 3). {ok, people, facts, how: {read, search}, tasks, first, working, left, estimate: {sessions, usd?}, head,
6860
+ * parent}; first: a try's tasks first in the queue (K7.1), working: a run or a session at work now (K7.2) — feature
6861
+ * verify.tryFirst; dry: no tasks (nor first, working), head == parent. 400 verify.invalid, 404 verify.unknown, 409 verify.archive | verify.nothing, 503
6534
6862
  * research.busy.
6535
6863
  */
6536
6864
  const verifyBulkWrite = () => {
@@ -6569,9 +6897,11 @@ export function serveLive(root, env) {
6569
6897
  ],
6570
6898
  };
6571
6899
  },
6572
- done(_tree, data, h) {
6573
- const { people, facts, how, tasks, left, estimate } = data;
6574
- return { ok: true, people, facts, how, ...(dry ? {} : { tasks: tasks ?? [] }), left, estimate, head: dry ? before : h, parent: before };
6900
+ done(tree, data, h) {
6901
+ const { people, facts, how, tasks, left, estimate, first } = data;
6902
+ // a try (feature verify.tryFirst): first says its tasks stand first in the queue, working whether the research
6903
+ // works now (a run, a session) — the app offers to work on them now only when it does not (spec 065 K7.2)
6904
+ return { ok: true, people, facts, how, ...(dry ? {} : { tasks: tasks ?? [], first: first === true, working: workingNow(tree) }), left, estimate, head: dry ? before : h, parent: before };
6575
6905
  },
6576
6906
  refused: (_tree, code, why) => verifyRefused(code, why),
6577
6907
  };
@@ -6781,6 +7111,11 @@ export function serveLive(root, env) {
6781
7111
  const refusedAsked = (e) => {
6782
7112
  if (!(e instanceof StromError) || !e.code)
6783
7113
  throw e;
7114
+ // a family tree's file a source standing was made of (spec 117 K2.2): the sources as a list too
7115
+ if (e.code === "material.source-live") {
7116
+ const sources = String(e.params?.sources ?? "").split(",").filter(Boolean);
7117
+ return { code: 409, body: { ...refusal(e.message, e.code, e.params ?? {}), sources } };
7118
+ }
6784
7119
  return { code: e.code === "material.body" || e.code === "material.date" ? 400 : 404, body: refusal(e.message, e.code, e.params ?? {}) };
6785
7120
  };
6786
7121
  /** Whether the research can be written here at all: its history, its records, its locks. */