strom-research 1.36.0 → 1.37.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 (64) hide show
  1. package/CHANGELOG.cs.md +42 -0
  2. package/CHANGELOG.de.md +50 -0
  3. package/CHANGELOG.md +45 -0
  4. package/CHANGELOG.pl.md +46 -0
  5. package/assets/lang/cs.json +40 -4
  6. package/assets/lang/de.json +40 -4
  7. package/assets/lang/pl.json +40 -4
  8. package/assets/strom-doc/cs/R12-where-the-agent-works.md +2 -2
  9. package/assets/strom-doc/de/R12-where-the-agent-works.md +2 -2
  10. package/assets/strom-doc/en/R12-where-the-agent-works.md +2 -2
  11. package/assets/strom-doc/pl/R12-where-the-agent-works.md +1 -1
  12. package/dist/brief/brief.js +43 -5
  13. package/dist/cli/menu-links.js +3 -2
  14. package/dist/cli/menu-waiting.js +3 -1
  15. package/dist/cli/ui.js +36 -4
  16. package/dist/commands/archives.js +11 -3
  17. package/dist/commands/browse.js +5 -1
  18. package/dist/commands/fixchecks.js +21 -1
  19. package/dist/commands/fixes.js +38 -6
  20. package/dist/commands/intake.js +10 -2
  21. package/dist/commands/links.js +5 -4
  22. package/dist/commands/media.js +14 -4
  23. package/dist/commands/people.js +2 -0
  24. package/dist/commands/session.js +54 -1
  25. package/dist/commands/setup.js +1 -1
  26. package/dist/commands/sync.js +113 -54
  27. package/dist/commands/tasks.js +2 -2
  28. package/dist/core/actions.js +4 -0
  29. package/dist/core/appmedia.js +207 -7
  30. package/dist/core/changelog.js +7 -0
  31. package/dist/core/contact.js +220 -0
  32. package/dist/core/contactfix.js +260 -0
  33. package/dist/core/floor.js +13 -3
  34. package/dist/core/import.js +53 -5
  35. package/dist/core/inboxwait.js +93 -18
  36. package/dist/core/links.js +8 -2
  37. package/dist/core/lists.js +117 -0
  38. package/dist/core/live.js +273 -39
  39. package/dist/core/machine.js +28 -0
  40. package/dist/core/material.js +14 -1
  41. package/dist/core/mediaqueue.js +1 -1
  42. package/dist/core/metrics.js +32 -1
  43. package/dist/core/originals.js +28 -9
  44. package/dist/core/overview.js +1 -0
  45. package/dist/core/ownsave.js +43 -0
  46. package/dist/core/phrases.js +4 -0
  47. package/dist/core/queue.js +1 -1
  48. package/dist/core/receive.js +9 -3
  49. package/dist/core/runstate.js +2 -1
  50. package/dist/core/session.js +16 -0
  51. package/dist/core/shaindex.js +31 -5
  52. package/dist/core/shortcut.js +2 -1
  53. package/dist/core/stromapp.js +2 -3
  54. package/dist/core/sync.js +242 -27
  55. package/dist/core/terms.js +44 -8
  56. package/dist/core/text.js +11 -0
  57. package/dist/core/tree.js +1 -1
  58. package/dist/core/validate.js +21 -0
  59. package/dist/core/waiting.js +2 -1
  60. package/dist/core/web.js +49 -7
  61. package/dist/core/webfull.js +105 -0
  62. package/dist/gedcom/export.js +8 -0
  63. package/dist/gedcom/validate.js +2 -1
  64. package/package.json +4 -1
@@ -20,7 +20,8 @@ import { normalizeDate } from "./gdate.js";
20
20
  import { restoreTakenOff } from "./sync.js";
21
21
  import { inTree, workingRel } from "./treemedia.js";
22
22
  import { mediaRecords } from "./mediaindex.js";
23
- import { recordsBySha } from "./shaindex.js";
23
+ import { inputsByWorkingSha, recordsBySha } from "./shaindex.js";
24
+ import { storedBytes } from "./appmedia.js";
24
25
  import { listSorts } from "./sort.js";
25
26
  /** How many of the people citing a source `of` names (all of them counted). */
26
27
  export const CITED_SHOWN = 5;
@@ -89,6 +90,18 @@ export function workingCopyOf(tree, shared, sha) {
89
90
  return undefined;
90
91
  return { id: i.id, kind: "input", mime: i.working.mime, bytes: i.working.bytes, name: i.name, ...(shared ? { file: path.join(shared, workingRel(shared, i.working)) } : {}) };
91
92
  }
93
+ /**
94
+ * A working copy the research keeps of a file of the app's tree, by the working copy's own hash (spec 133: the app asks
95
+ * POST /media/known by the bytes it would send, then names them by reference): the input it is of, while its bytes are
96
+ * in the shared store — answered as a known file is. None: the app sends those bytes as ever.
97
+ */
98
+ export function workingCopyBySha(tree, shared, sha) {
99
+ if (!shared)
100
+ return undefined;
101
+ const i = inputsByWorkingSha(tree, sha).find((x) => !x.retracted && x.working);
102
+ const file = i ? storedBytes(shared, sha) : undefined;
103
+ return i && file ? { id: i.id, kind: "input", mime: i.working.mime, bytes: i.working.bytes, name: i.name, file } : undefined;
104
+ }
92
105
  function usesIndex(tree) {
93
106
  const idx = { tree, media: new Map(), byMedia: new Map(), byInput: new Map(), sources: new Map(), tasks: new Map() };
94
107
  const add = (m, k, v) => {
@@ -289,7 +289,7 @@ export function takeQueued(tree, shared, env, o) {
289
289
  said.input = got.input;
290
290
  }
291
291
  else {
292
- const got = takeOriginal(tree, shared, j.file, j.sha, { name: j.name, persons: j.persons, ...(j.families?.length ? { families: j.families } : {}), note: j.note, auto: !!o.auto });
292
+ const got = takeOriginal(tree, shared, j.file, j.sha, { name: j.name, persons: j.persons, ...(j.families?.length ? { families: j.families } : {}), ...(j.list ? { list: j.list } : {}), note: j.note, auto: !!o.auto });
293
293
  if (got.known)
294
294
  said.known = got.known;
295
295
  else
@@ -380,6 +380,34 @@ function journalTail(root) {
380
380
  return undefined;
381
381
  }
382
382
  }
383
+ /**
384
+ * Whether the agent's web tools were refused a page of a site (webDomain) since `since` (ms) and given none of it — the
385
+ * tree's hook's lines of fetch.jsonl (its end): a page asked for (strom media save's) that never opened.
386
+ */
387
+ export function siteRefusedSince(root, site, since) {
388
+ const text = journalTail(root);
389
+ if (text === undefined)
390
+ return false;
391
+ let refused = false;
392
+ for (const line of text.split("\n")) {
393
+ if (!line.includes('"via":"web"') || !line.includes('"from":"hook"'))
394
+ continue;
395
+ let r;
396
+ try {
397
+ r = JSON.parse(line);
398
+ }
399
+ catch {
400
+ continue;
401
+ }
402
+ if (!r.host || (r.domain ?? webDomain(r.host)) !== site || !(Date.parse(r.at ?? "") >= since))
403
+ continue;
404
+ if (r.decision === "allow")
405
+ return false;
406
+ if (r.decision === "deny")
407
+ refused = true;
408
+ }
409
+ return refused;
410
+ }
383
411
  /**
384
412
  * The times (ms) the agent's web fetches to one host went out in the last hour as this tree's journal tells them (each
385
413
  * counted one: its line's time and the pause it made for the pace) — what a host's state that cannot be read is made
@@ -448,6 +476,7 @@ export function webRequestsOf(root, who) {
448
476
  const answered = new Map();
449
477
  const advised = new Set();
450
478
  const advisedSites = new Set();
479
+ const refusedMany = new Map();
451
480
  let search = 0;
452
481
  if (!who.session && !who.agentSession)
453
482
  return { hosts, domains, toolUses, asked, advised, answered, search };
@@ -494,6 +523,8 @@ export function webRequestsOf(root, who) {
494
523
  answered.set(site, "yes");
495
524
  else if (r.decision === "deny" && r.why === WEB_SAID_NO && threshold)
496
525
  answered.set(site, "no");
526
+ if (r.decision === "deny" && r.why === "many")
527
+ refusedMany.set(site, (refusedMany.get(site) ?? 0) + 1);
497
528
  }
498
529
  }
499
530
  mine.push(r);
@@ -507,5 +538,5 @@ export function webRequestsOf(root, who) {
507
538
  domains.set(site, (domains.get(site) ?? 0) + 1);
508
539
  }
509
540
  }
510
- return { hosts, domains, toolUses, asked, advised, advisedSites, answered, search };
541
+ return { hosts, domains, toolUses, asked, advised, advisedSites, answered, search, refusedMany };
511
542
  }
@@ -10,6 +10,7 @@ import fs from "node:fs";
10
10
  import path from "node:path";
11
11
  import { UsageError } from "./errors.js";
12
12
  import { removeRetrying, retryingHeld } from "./json.js";
13
+ import { sameList, takeList } from "./lists.js";
13
14
  import { mimeOf, sharedMediaPath } from "./media.js";
14
15
  import { create, update } from "./records.js";
15
16
  import { makeNote } from "./actions.js";
@@ -215,7 +216,12 @@ const displayOf = (p) => `${[p.names[0]?.given, p.names[0]?.surname].filter(Bool
215
216
  * caller holds the tree lock and commits.
216
217
  */
217
218
  export function takeOriginal(tree, shared, file, sha, metaIn) {
218
- const meta = { ...metaIn, ...checkOriginalMeta(tree, metaIn) };
219
+ const checked = checkOriginalMeta(tree, metaIn);
220
+ // the list it was sent to (of the material, or of a source's scan): its people up to LIST_PEOPLE are its people too,
221
+ // after those named
222
+ const sent = metaIn.list ? takeList(tree, metaIn.list) : undefined;
223
+ const meta = { ...metaIn, ...checked, ...(sent ? { persons: [...new Set([...checked.persons, ...sent.persons])] } : {}) };
224
+ const list = sent?.list;
219
225
  const name = path.basename(metaIn.name.normalize("NFC").replace(/[\\/]+/g, "/")).replace(/[\u0000-\u001f]/g, "").slice(0, 200) || `${sha.slice(0, 12)}`;
220
226
  const type = originalType(file, name);
221
227
  if (!type)
@@ -231,8 +237,8 @@ export function takeOriginal(tree, shared, file, sha, metaIn) {
231
237
  fs.rmSync(file, { force: true });
232
238
  // an input of the people: what is said of it now is added (in a batch the batch's tasks see to it)
233
239
  if (known.kind === "input" && !meta.batch) {
234
- const a = amendInput(tree, known.id, { persons: meta.persons, note: meta.note, families: meta.families }, { again: !meta.task && !meta.read, auto: !!meta.auto });
235
- return { known: known.id, ...(a.added.persons.length || a.added.note || a.added.families ? { added: a.added } : {}), ...(a.task ? { task: a.task } : {}) };
240
+ const a = amendInput(tree, known.id, { persons: meta.persons, note: meta.note, families: meta.families, list }, { again: !meta.task && !meta.read, auto: !!meta.auto });
241
+ return { known: known.id, ...(addedAny(a) ? { added: a.added } : {}), ...(a.task ? { task: a.task } : {}) };
236
242
  }
237
243
  return { known: known.id };
238
244
  }
@@ -263,8 +269,8 @@ export function takeOriginal(tree, shared, file, sha, metaIn) {
263
269
  update(tree, waiting.id, "input", (x) => ({ ...x, file: `media:${rel}`, size, mime: type.mime }), { op: "input.original", summary: `${waiting.id} its original "${name.slice(0, 50)}" (the Strom app)` });
264
270
  if (meta.batch)
265
271
  return { known: waiting.id };
266
- const a = amendInput(tree, waiting.id, { persons: meta.persons, note: meta.note, families: meta.families }, { again: !meta.task && !meta.read, auto: !!meta.auto });
267
- return { known: waiting.id, ...(a.added.persons.length || a.added.note || a.added.families ? { added: a.added } : {}), ...(a.task ? { task: a.task } : {}) };
272
+ const a = amendInput(tree, waiting.id, { persons: meta.persons, note: meta.note, families: meta.families, list }, { again: !meta.task && !meta.read, auto: !!meta.auto });
273
+ return { known: waiting.id, ...(addedAny(a) ? { added: a.added } : {}), ...(a.task ? { task: a.task } : {}) };
268
274
  }
269
275
  if (s) {
270
276
  // an image of the source: the record itself, as the user scanned or photographed it
@@ -278,7 +284,11 @@ export function takeOriginal(tree, shared, file, sha, metaIn) {
278
284
  ...(type.image && !tree.dryRun ? (imageSizeOfFile(dest) ?? {}) : {}),
279
285
  from: `${APP_FROM}: ${name}`,
280
286
  accessed: new Date().toISOString().slice(0, 10),
287
+ ...(list ? { list } : {}),
281
288
  }, (id) => `+${id} image "${name.slice(0, 50)}" of ${s.id} (the Strom app)`, [s.id]);
289
+ // an image the research had (of another source) sent now to a list: the list as sent now kept on it
290
+ if (known?.kind === "media" && list && !sameList(m.list, list))
291
+ update(tree, m.id, "media", (x) => ({ ...x, list }), { op: "media.list", summary: `${m.id} sent to the list "${list.name.slice(0, 50)}" (the Strom app)` });
282
292
  // the part the entry is on, where nobody said it yet (another one waits for the reader's word)
283
293
  const clip = !!meta.region && !s.clips?.length && !!type.image;
284
294
  update(tree, s.id, "source", (x) => ({ ...x, media: [...new Set([...(x.media ?? []), m.id])], ...(clip ? { clips: [{ media: m.id, region: meta.region }] } : {}) }), { op: "source.media", summary: `${s.id} image ${m.id}${clip ? " with the part the entry is on" : ""} (the Strom app)` });
@@ -315,6 +325,7 @@ export function takeOriginal(tree, shared, file, sha, metaIn) {
315
325
  state: "new",
316
326
  ...(meta.persons.length ? { persons: meta.persons } : {}),
317
327
  ...(meta.families?.length ? { families: meta.families } : {}),
328
+ ...(list ? { list } : {}),
318
329
  ...(meta.batch ? { batch: meta.batch } : {}),
319
330
  ...(meta.path ? { path: meta.path } : {}),
320
331
  ...(meta.note?.trim() ? { note: meta.note.trim().slice(0, 500) } : {}),
@@ -344,7 +355,10 @@ export function gatherTask(tree, input, persons) {
344
355
  .list("task")
345
356
  .filter((t) => t.origin === APP_MEDIA_ORIGIN && (t.state === "open" || (held && t.state === "parked")) && Date.now() - Date.parse(t.created) < GATHER_MS && t.where.length < GATHER_MAX && same(t))
346
357
  .pop();
347
- const who = persons.map((p) => displayOf(tree.get(p))).join(", ") || phrase(lang, "app.media.nobody");
358
+ // sent to a list: named by it, never by its people one by one (up to 50 of them)
359
+ const who = input.list
360
+ ? phrase(lang, "app.media.list", { name: input.list.name, count: input.list.count })
361
+ : persons.map((p) => displayOf(tree.get(p))).join(", ") || phrase(lang, "app.media.nobody");
348
362
  if (recent) {
349
363
  const where = [...recent.where, input.id];
350
364
  update(tree, recent.id, "task", (t) => ({ ...t, where, subject: [...where, ...persons], what: phrase(lang, "app.media.what", { count: where.length, who, first: where[0], last: where.at(-1) }) }), { op: "task.edit", summary: `${recent.id} + ${input.id} (the Strom app)` });
@@ -384,8 +398,10 @@ export function amendInput(tree, id, more, o = {}) {
384
398
  const families = (checked.families ?? []).filter((f) => !(input.families ?? []).includes(f));
385
399
  const text = more.note?.replace(/[\p{Cc}]/gu, " ").trim().slice(0, 500);
386
400
  const note = !!text && !input.notes.some((n) => foldText(n.text) === foldText(text));
387
- const out = { known: id, added: { persons, note, ...(families.length ? { families } : {}) }, ...(kept.length ? { declined: kept } : {}) };
388
- if (!persons.length && !note && !families.length)
401
+ // the list it was sent to now (the latest send's, as it was sent then)
402
+ const list = more.list && !sameList(input.list, more.list) ? more.list : undefined;
403
+ const out = { known: id, added: { persons, note, ...(families.length ? { families } : {}), ...(list ? { list: true } : {}) }, ...(kept.length ? { declined: kept } : {}) };
404
+ if (!persons.length && !note && !families.length && !list)
389
405
  return out;
390
406
  const held = tree.list("task").some((t) => t.where.includes(id) && (t.state === "open" || t.state === "doing" || t.state === "parked" || t.state === "waiting"));
391
407
  const again = o.again !== false && !held && !input.batch;
@@ -394,13 +410,16 @@ export function amendInput(tree, id, more, o = {}) {
394
410
  ...(persons.length ? { persons: [...had, ...persons] } : {}),
395
411
  ...(persons.some((p) => off.has(p)) ? { declined: (i.declined ?? []).filter((d) => !persons.includes(d.person)) } : {}),
396
412
  ...(families.length ? { families: [...(i.families ?? []), ...families] } : {}),
413
+ ...(list ? { list } : {}),
397
414
  ...(note ? { notes: [...i.notes, makeNote(tree, text)] } : {}),
398
415
  ...(again ? { state: "new" } : {}),
399
- }), { op: "input.amend", summary: `${id}: ${[persons.length ? `+ ${persons.join(", ")}` : "", families.length ? `+ ${families.join(", ")}` : "", note ? "+ a note" : ""].filter(Boolean).join(", ")}${o.app === false ? "" : " (the Strom app)"}`, targets: persons });
416
+ }), { op: "input.amend", summary: `${id}: ${[persons.length ? `+ ${persons.join(", ")}` : "", families.length ? `+ ${families.join(", ")}` : "", list ? `+ the list "${list.name.slice(0, 50)}"` : "", note ? "+ a note" : ""].filter(Boolean).join(", ")}${o.app === false ? "" : " (the Strom app)"}`, targets: persons });
400
417
  if (again && o.auto)
401
418
  out.task = gatherTask(tree, next, next.persons ?? []);
402
419
  return out;
403
420
  }
421
+ /** Something came of a file sent again: people, a note, couples or a list. */
422
+ const addedAny = (a) => !!(a.added.persons.length || a.added.note || a.added.families || a.added.list);
404
423
  /** The originals from the app (or a phone) nobody has worked through yet: what waits in the research (the bridge's inbox.material). */
405
424
  export function materialWaiting(tree) {
406
425
  // a file taken back or deleted for good waits for nobody
@@ -183,6 +183,7 @@ export function personCard(tree, p) {
183
183
  parents: parentsOf(tree, p.id).map(who),
184
184
  families: families.sort((a, b) => Math.sign(yearOf(a.facts[0]?.date) - yearOf(b.facts[0]?.date)) || 0),
185
185
  ...(p.story ? { story: { status: p.story.status, text: p.story.text } } : {}),
186
+ ...(p.contact?.emails?.length ? { contact: { emails: [...p.contact.emails] } } : {}),
186
187
  };
187
188
  }
188
189
  /** What the research added and refined since a time (ISO): the operation logs say what, the records how it is now. */
@@ -0,0 +1,43 @@
1
+ // An image of a task the agent's own browser was to save (strom media save: the task waits for it, the browser's file
2
+ // brings it back) and that never came: found in a live run — the page of the image was refused by the hook (the site's
3
+ // pages used up), the script never ran, the session ended and the task stayed waiting for ever, out of the queue, its
4
+ // wait woken by nothing (no file comes). So a session closing (its agent's close, an interruption, a takeover) puts
5
+ // such a task back in the queue with a note of the images left — never handed to the person; and such a save is never
6
+ // said held back by the browser (the person asked to allow downloads of a page that never opened).
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { findDownload, loadSaves } from "./browser.js";
10
+ import { folderFiles, registeredImages } from "./inboxwait.js";
11
+ import { parseImageList } from "./media.js";
12
+ import { siteRefusedSince, webDomain } from "./metrics.js";
13
+ /**
14
+ * The saves through the agent's browser a waiting task still waits for, when they are all it waits for and none of them
15
+ * came or is on its way: no file in the downloads folder (nor one being written), none in the task's folder, none said
16
+ * held back by the browser (that one is the person's: allowing the downloads). Else undefined: the wait stays.
17
+ */
18
+ export function unsavedOwnWait(tree, t, o) {
19
+ if (t.state !== "waiting" || !t.awaits?.recordset)
20
+ return undefined;
21
+ const b = t.awaits.recordset;
22
+ const saves = loadSaves(tree.root).filter((r) => r.task === t.id && r.recordset === b && r.taken === undefined);
23
+ if (!saves.length)
24
+ return undefined;
25
+ const have = registeredImages(tree, b);
26
+ const missing = (parseImageList(t.awaits.images) ?? []).filter((n) => !have.has(n) || saves.some((r) => r.n === n && r.again));
27
+ const mine = saves.filter((r) => missing.includes(r.n));
28
+ // an image it waits for that no save of the agent's browser is for (the person's hand): the wait is theirs
29
+ if (!missing.length || missing.some((n) => !mine.some((r) => r.n === n)))
30
+ return undefined;
31
+ if (mine.some((r) => r.held))
32
+ return undefined;
33
+ if (o.downloads && mine.some((r) => { const d = findDownload(o.downloads, r.file); return !!d.file || !!d.unfinished; }))
34
+ return undefined;
35
+ const dir = o.shared && t.awaits.folder ? path.join(o.shared, "inbox", t.awaits.folder) : undefined;
36
+ if (dir && fs.existsSync(dir) && folderFiles(dir).length > 0)
37
+ return undefined;
38
+ return mine;
39
+ }
40
+ /** A save whose page the hook refused since it was given, with none of its site let through since: its script never ran. */
41
+ export function saveNeverOpened(tree, r) {
42
+ return siteRefusedSince(tree.root, webDomain(r.host), r.at);
43
+ }
@@ -191,6 +191,7 @@ export const PHRASES = {
191
191
  "transcript.read": "Transcript written by a reader ({model}) from the entry cut out of its scan and checked by a second reader ({date}, strom transcripts).",
192
192
  "app.media.what": "Analyse {count, plural, one {# file} other {# files}} the user sent from the Strom app — {who} ({first}–{last})",
193
193
  "app.media.nobody": "for the research",
194
+ "app.media.list": "the list “{name}” ({count, plural, one {# person} other {# people}})",
194
195
  "app.media.why": "Originals from the user, sent from the Strom app (kept unchanged): find out what each is, whom it is about and what it can prove.",
195
196
  "app.scan.what": "Read the scan the user sent of {source} ({title})",
196
197
  "app.scan.why": "The user sent the record itself from the Strom app: the research reads it for itself — its reading confirms the user's transcript or shows a mistake.",
@@ -424,6 +425,9 @@ export const PHRASES = {
424
425
  "log.streetplace.unfix": "Places and houses of facts put back as they were: {n}",
425
426
  "log.tree.return": "Return to the state of {when}",
426
427
  "log.streetplace.towns": "Numbers after the name of a municipality answered (houses or not): {n}",
428
+ "fix.contact.retracted": "A contact, not a residence: its e-mail is the person's contact (fix contact-residences).",
429
+ "log.contact.fix": "E-mails out of residences moved to the contacts of the persons: {n}",
430
+ "log.contact.unfix": "Residences of contacts put back as they were: {n}",
427
431
  "fix.editdecision.note": "Decided by an agent before strom {since}, though it was the user's to decide: {decided}. Opened again for the user's decision (fix edit-decisions).",
428
432
  "log.editdecision.fix": "Disagreements with the user's own edits opened again for the user's decision: {n}",
429
433
  "log.editdecision.unfix": "Disagreements with the user's own edits closed again as they were decided: {n}",
@@ -165,7 +165,7 @@ export function waitsForDecision(tree, qs = permissionQuestions(tree.env), withI
165
165
  };
166
166
  }
167
167
  /** Levels whose work asks an archive for its images or its indexes (the user's material, a request, a story: none). */
168
- const ASKS_ARCHIVE = new Set(["locate", "link", "verify", "enrich"]);
168
+ export const ASKS_ARCHIVE = new Set(["locate", "link", "verify", "enrich"]);
169
169
  /**
170
170
  * An open task whose archive strom leaves alone now (core/leftalone.ts): its level asks an archive, every record set of
171
171
  * it with an address lies on a host left alone, and — reading records (link, verify) — none of them has images here
@@ -151,7 +151,8 @@ export function receiveOriginal(r, req, res, f) {
151
151
  // an input of the people, said of again — people it lacks, a note it has not got: added by a strom of its own
152
152
  // (found live: the app said "Sent" while the research took nothing)
153
153
  const had = known.kind === "input" && !batch ? tree.get(known.id) : undefined;
154
- const more = had && (f.persons.some((p) => !(had.persons ?? []).includes(p)) || (f.families ?? []).some((x) => !(had.families ?? []).includes(x)) || (!!note?.trim() && !had.notes.some((n) => foldText(n.text) === foldText(note.trim()))));
154
+ // (a list: what it is now is compared by the strom that takes it — sent again it changes nothing)
155
+ const more = had && (!!f.list || f.persons.some((p) => !(had.persons ?? []).includes(p)) || (f.families ?? []).some((x) => !(had.families ?? []).includes(x)) || (!!note?.trim() && !had.notes.some((n) => foldText(n.text) === foldText(note.trim()))));
155
156
  // (a file to read: what it is of goes with its reading, never into an intake task)
156
157
  // nothing written (or what came again not added): the head as it is, which is its parent too (the bridge's answers)
157
158
  const unchanged = () => {
@@ -161,7 +162,7 @@ export function receiveOriginal(r, req, res, f) {
161
162
  if (!more || f.read)
162
163
  return refuse(200, { known: known.id, kind: known.kind, ...(batch ? { batch } : {}), ...unchanged() });
163
164
  req.resume();
164
- runOf(r)(["input", "amend", known.id, ...f.persons.flatMap((p) => ["--person", p]), ...(f.families ?? []).flatMap((x) => ["--family", x]), ...(note ? [`--note=${note}`] : []), "--json"], ({ code, stdout, error }) => {
165
+ runOf(r)(["input", "amend", known.id, ...f.persons.flatMap((p) => ["--person", p]), ...(f.families ?? []).flatMap((x) => ["--family", x]), ...(f.list ? ["--list", f.list] : []), ...(note ? [`--note=${note}`] : []), "--json"], ({ code, stdout, error }) => {
165
166
  if (error)
166
167
  return reply(200, { known: known.id, kind: known.kind, ...unchanged() });
167
168
  let data = {};
@@ -176,7 +177,10 @@ export function receiveOriginal(r, req, res, f) {
176
177
  if (code === EXIT.locked)
177
178
  return reply(503, { ...refusal("the research is busy — send it again in a while", "research.busy"), retry: 30 });
178
179
  const c = committed(data, () => r.head?.());
179
- reply(200, { known: known.id, kind: known.kind, ...(code === 0 && data.added ? { added: data.added } : {}), ...(code === 0 && data.task ? { task: data.task } : {}), ...(code === 0 ? { head: c.head, ...(c.parent !== undefined ? { parent: c.parent } : {}) } : unchanged()) });
180
+ // added only what came (a list sent again the same: nothing)
181
+ const a = data.added;
182
+ const came = !!a && (!!a.persons?.length || !!a.note || !!a.families?.length || !!a.list);
183
+ reply(200, { known: known.id, kind: known.kind, ...(code === 0 && came ? { added: data.added } : {}), ...(code === 0 && data.task ? { task: data.task } : {}), ...(code === 0 ? { head: c.head, ...(c.parent !== undefined ? { parent: c.parent } : {}) } : unchanged()) });
180
184
  });
181
185
  return;
182
186
  }
@@ -257,6 +261,7 @@ export function receiveOriginal(r, req, res, f) {
257
261
  job = enqueue(r.root, part, {
258
262
  sha, name, persons: f.persons,
259
263
  ...(f.families?.length ? { families: f.families } : {}),
264
+ ...(f.list ? { list: f.list } : {}),
260
265
  ...(note ? { note } : {}),
261
266
  ...(batch ? { batch, path: where ?? batchPath(name) ?? name, ...(zip ? { zip: true } : {}) } : {}),
262
267
  client: { ...(f.async.origin ? { origin: f.async.origin } : {}), ...(f.async.app ? { app: f.async.app } : {}) },
@@ -276,6 +281,7 @@ export function receiveOriginal(r, req, res, f) {
276
281
  "media", "original", part, "--sha", sha, `--name=${name}`,
277
282
  ...f.persons.flatMap((p) => ["--person", p]),
278
283
  ...(f.families ?? []).flatMap((x) => ["--family", x]),
284
+ ...(f.list ? ["--list", f.list] : []),
279
285
  ...(f.source ? ["--source", f.source] : []),
280
286
  ...(region ? ["--region", region] : []),
281
287
  ...(note ? [`--note=${note}`] : []),
@@ -158,7 +158,8 @@ export function clearRunFiles(root, id) {
158
158
  export function runEndOf(stop, asked) {
159
159
  if (asked || stop === "user")
160
160
  return "stopped";
161
- if (["done", "empty", "tasks", "sessions", "asleep"].includes(stop))
161
+ // nothing to do until a time (asleep: the subscription's window; web: a site whose pages are used up here) is a run done
162
+ if (["done", "empty", "tasks", "sessions", "asleep", "web"].includes(stop))
162
163
  return "done";
163
164
  if (stop === "limit")
164
165
  return "limit";
@@ -28,6 +28,8 @@ import { readCodexConfig } from "../agents/effort.js";
28
28
  import { clearSessionWait, permissionWait, waitingForDecision } from "./archivewait.js";
29
29
  import { forgetLeftAlone } from "./leftalone.js";
30
30
  import { Settings } from "./config.js";
31
+ import { unsavedOwnWait } from "./ownsave.js";
32
+ import { runs } from "../cli/format.js";
31
33
  import { claimSite, heldSiteOfTask, heldSites, holderWords, releaseHolder, restrictedSiteOfTask, transferSite } from "./archiveholds.js";
32
34
  import { forGaps, regionOfTask, takeRegion } from "./pastevents.js";
33
35
  import { placeOfTask, takePlace } from "./placehistory.js";
@@ -609,6 +611,20 @@ export function closeSession(tree, s, input) {
609
611
  tree.put(back, { op: "task.continue", targets: [task.id, s.id], summary: `${task.id} back to the queue` });
610
612
  }
611
613
  }
614
+ else if (task && task.state === "waiting") {
615
+ // waiting for images its own agent's browser was to save, none of which came (core/ownsave.ts): back in the queue
616
+ // with the images left — a wait no file would ever end, never the person's
617
+ const settings = new Settings(tree.env, {});
618
+ const left = unsavedOwnWait(tree, task, { shared: settings.shared()?.value, downloads: settings.downloads() });
619
+ if (left) {
620
+ const images = runs(left.map((r) => r.n));
621
+ const note = makeNote(tree, `${input.interrupted ? "interrupted" : "closed"} in ${s.id}: image ${images} of ${task.awaits.recordset} still to be saved through the browser (strom media save) — nothing came`.slice(0, 500));
622
+ const back = { ...onceDone(task), state: "open", notes: [...task.notes, note], updated: now() };
623
+ for (const k of ["waitingOn", "awaits", "awaitsCheck", "awaitsPermission", "wait", "sent"])
624
+ delete back[k];
625
+ tree.put(back, { op: "task.continue", targets: [task.id, s.id], summary: `${task.id} back to the queue: image ${images} of ${task.awaits.recordset} not saved through the browser` });
626
+ }
627
+ }
612
628
  // a session on the places: what it did counted by strom (identified, verified, asked …) before the agent's words
613
629
  const counts = task?.origin === PLACES_IDENTIFY_ORIGIN ? placesSessionCounts(tree, s.id) : "";
614
630
  if (counts)
@@ -8,7 +8,8 @@
8
8
  // Anything that fails — no file, another format, a commit git no longer has (a reset, a gc) — and it is made again
9
9
  // from the records. It is only a help: what it names is read and checked (the record's own sha), and what this
10
10
  // process holds or wrote itself is looked at too, so a second file of the same content in one hold of the lock is
11
- // the first one's (never a second record).
11
+ // the first one's (never a second record). An input's working copy (the app's file whose original is another) is kept
12
+ // under its own hash too (spec 133: the app asks by the bytes it would send), as `<id>~w`.
12
13
  import fs from "node:fs";
13
14
  import path from "node:path";
14
15
  import { RECORD_TYPES } from "./model.js";
@@ -16,7 +17,9 @@ import { readJson, readJsonIfExists, writeFileAtomic } from "./json.js";
16
17
  import { headCommit, heldStatus, runGit } from "./git.js";
17
18
  import { STABLE_MS } from "./mediaindex.js";
18
19
  const TYPES = ["media", "input"];
19
- const FORMAT = 1;
20
+ const FORMAT = 2;
21
+ /** The key of an input's working copy in the index (its own hash): `<id>~w`. */
22
+ const WORKING = "~w";
20
23
  /** The index of each research this process has looked at (a bridge asks again and again): never parsed twice. */
21
24
  const indexes = new Map();
22
25
  /** The trees whose index was checked against the files since they last forgot what they read (Tree.epoch). */
@@ -74,10 +77,14 @@ function reread(index, root, rel) {
74
77
  throw e;
75
78
  rec = undefined;
76
79
  }
77
- if (rec && typeof rec === "object")
80
+ if (rec && typeof rec === "object") {
78
81
  add(index, id, rec.sha);
79
- else
82
+ add(index, `${id}${WORKING}`, rec.working?.sha);
83
+ }
84
+ else {
80
85
  drop(index, id);
86
+ drop(index, `${id}${WORKING}`);
87
+ }
81
88
  }
82
89
  /** Each folder's modification time (ns), and whether all changed long enough ago to be trusted to it. */
83
90
  function stampsOf(root) {
@@ -265,7 +272,7 @@ export function recordsBySha(tree, type, sha) {
265
272
  if (tree.loaded(type))
266
273
  return tree.list(type).filter((x) => x.sha === sha);
267
274
  const prefix = RECORD_TYPES[type].prefix;
268
- const ids = new Set((indexOf(tree).bySha.get(sha) ?? []).filter((id) => id.startsWith(prefix)));
275
+ const ids = new Set((indexOf(tree).bySha.get(sha) ?? []).filter((id) => id.startsWith(prefix) && !id.endsWith(WORKING)));
269
276
  for (const rec of tree.heldRecords(type))
270
277
  if (rec.sha === sha)
271
278
  ids.add(rec.id);
@@ -277,6 +284,25 @@ export function recordsBySha(tree, type, sha) {
277
284
  }
278
285
  return out;
279
286
  }
287
+ /**
288
+ * The inputs whose working copy is this content (`working.sha`: the bytes the app shows of a file whose original is
289
+ * another), found as recordsBySha finds records. Retracted ones too: the caller says which count.
290
+ */
291
+ export function inputsByWorkingSha(tree, sha) {
292
+ if (tree.loaded("input"))
293
+ return tree.list("input").filter((x) => x.working?.sha === sha);
294
+ const ids = new Set((indexOf(tree).bySha.get(sha) ?? []).filter((id) => id.endsWith(WORKING)).map((id) => id.slice(0, -WORKING.length)));
295
+ for (const rec of tree.heldRecords("input"))
296
+ if (rec.working?.sha === sha)
297
+ ids.add(rec.id);
298
+ const out = [];
299
+ for (const id of [...ids].sort(fileOrder)) {
300
+ const rec = tree.get(id);
301
+ if (rec && rec.type === "input" && rec.working?.sha === sha)
302
+ out.push(rec);
303
+ }
304
+ return out;
305
+ }
280
306
  /** Forget the indexes held in memory (a test that changes the files under a process that keeps them). */
281
307
  export function forgetShaIndexes() {
282
308
  indexes.clear();
@@ -127,7 +127,8 @@ export function openInNewTerminal(argv, cwd, env, platform = process.platform, o
127
127
  // the title without what a shell or a terminal reads as its own (quotes, controls, escapes)
128
128
  const title = opts.title?.replace(/[\p{Cc}\p{Cf}"'`$\\%^&|<>!]/gu, "").slice(0, 120);
129
129
  if (platform === "win32") {
130
- const q = (a) => `"${a.replace(/"/g, '""')}"`;
130
+ // a .cmd reads %…% as a variable even in quotes (a link's name=, a folder with a %): each % doubled
131
+ const q = (a) => `"${a.replace(/"/g, '""').replace(/%/g, "%%")}"`;
131
132
  const file = path.join(dir, `strom-${stamp}.cmd`);
132
133
  const lines = ["@echo off", "chcp 65001 >nul", ...(title ? [`title ${title}`] : []), ...marks.map((k) => `set "${k}="`), ...own.map(([k, v]) => `set "${k}=${v}"`), 'set "STROM_HANDOVER=1"', `cd /d ${q(cwd)}`, [command, ...args, ...argv].map(q).join(" "), "if errorlevel 1 pause", ""];
133
134
  fs.writeFileSync(file, lines.join("\r\n"));
@@ -9,7 +9,7 @@ import path from "node:path";
9
9
  import { desktopDir, userHome } from "./paths.js";
10
10
  import { appUrlInvalid, checkValue, settingDef, Settings } from "./config.js";
11
11
  import { UsageError } from "./errors.js";
12
- import { foldText } from "./text.js";
12
+ import { foldText, oneLineName } from "./text.js";
13
13
  import { compareVersions, updateChannel } from "./update.js";
14
14
  export const STROM_APP_URL = "https://stromapp.info/run/";
15
15
  /** The Strom app's beta: the copy a strom of the beta channel opens unless strom.app.url says another. */
@@ -123,8 +123,7 @@ export function appCopyOfInstall(env) {
123
123
  export function appTreeNameFromInstall(env) {
124
124
  if (!env.STROM_FROM_APP?.trim())
125
125
  return undefined;
126
- const name = (env.STROM_FROM_APP_NAME ?? "").normalize("NFC").replace(/[\p{Cc}\p{Cf}]/gu, " ").replace(/\s+/gu, " ").trim().slice(0, 80).trim();
127
- return name || undefined;
126
+ return oneLineName(env.STROM_FROM_APP_NAME, 80) || undefined;
128
127
  }
129
128
  /**
130
129
  * The setting strom.app.url (STROM_APP_URL) read and checked as strom config set checks it — from the variable, and