strom-research 1.13.1 → 1.13.2-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.
@@ -52,6 +52,8 @@ export const PHRASES = {
52
52
  "sync.verify.done": "each record found and read independently (its image registered, strom read M… --blind): the readings agree → noted on the source and the facts kept; they differ → a conflict with both readings",
53
53
  "sync.reading.note": "The user read this record otherwise in the Strom app ({source}); the research's reading stays until it is read again:",
54
54
  "sync.reading.page": "page",
55
+ "conflict.app.decided": "the user's decision in the Strom app",
56
+ "conflict.app.noted": "{decided}: {note}",
55
57
  "sync.reading.text": "transcript",
56
58
  "archive.held": "kept for later: the research is an archive (the data come from the Strom app); back in the queue when work with an agent is switched on",
57
59
  "archive.removed": "removed in the Strom app",
@@ -150,6 +152,8 @@ export const PHRASES = {
150
152
  "log.lesson.add": "Learned: {name}",
151
153
  "log.hypothesis.add": "A question weighed: {name}",
152
154
  "log.hypothesis.argue": "Weighed further: {name}",
155
+ "log.hypothesis.link": "What a variant would connect: {name}",
156
+ "log.hypothesis.variant": "Another possibility weighed: {name}",
153
157
  "log.hypothesis.decide": "Decided: {name}",
154
158
  "log.conflict.add": "The records disagree: {name}",
155
159
  "log.conflict.resolve": "Disagreement settled: {name}",
@@ -12,6 +12,7 @@ import { birthEstimate, RECORD_KINDS, recordsetsCovering, researchPeople } from
12
12
  import { birthEvent, displayName, familiesAsPartner, lifespan } from "./people.js";
13
13
  import { phrase } from "./phrases.js";
14
14
  import { foldText } from "./text.js";
15
+ import { weighedSources } from "./conflicts.js";
15
16
  export const REVIEW_KINDS = ["mentions", "entries", "verify", "reread", "conflicts", "marriage", "death"];
16
17
  /** At most so many records, entries or facts in one task: a session's worth. */
17
18
  export const REVIEW_BATCH = 8;
@@ -71,6 +72,13 @@ function citedFor(tree, p) {
71
72
  if (e.participants?.some((x) => x.person === p.id))
72
73
  for (const c of e.citations)
73
74
  out.add(c.source);
75
+ // a record the user decided against (a conflict of their edit, their value taken: the record's fact withdrawn) was
76
+ // weighed: never a "mention" to read again, nor a new conflict to open on it
77
+ const families = new Set(familiesAsPartner(tree, p.id).map((f) => f.id));
78
+ for (const c of tree.list("conflict"))
79
+ if (c.state === "resolved" && c.decidedBy === "user" && c.subject.some((s) => s === p.id || families.has(s)))
80
+ for (const s of weighedSources(tree, c))
81
+ out.add(s);
74
82
  return out;
75
83
  }
76
84
  /**
@@ -1,6 +1,6 @@
1
1
  // Declarative field rules for record types. Used for write-time validation
2
2
  // and by `strom check` (including references between records).
3
- import { ACCESS, AUTOMATION, INPUT_KINDS, JURISDICTIONS, LESSON_MAX, LESSON_SCOPES, SEARCH_METHODS, SEARCH_RESULTS, SOURCE_KINDS, TASK_LEVELS, TASK_STATES, } from "./model.js";
3
+ import { ACCESS, AUTOMATION, INPUT_KINDS, JURISDICTIONS, LESSON_MAX, LESSON_SCOPES, SEARCH_METHODS, SEARCH_RESULTS, SOURCE_KINDS, TASK_LEVELS, TASK_STATES, VARIANT_LINK_KINDS, } from "./model.js";
4
4
  import { normalizeDate } from "./gdate.js";
5
5
  const S = (extra = {}) => ({ t: "string", ...extra });
6
6
  const R = (to, req = false) => ({ t: "ref", to, req });
@@ -101,10 +101,15 @@ export const SCHEMAS = {
101
101
  title: S({ req: true, max: 200 }),
102
102
  fact: S({ max: 8 }),
103
103
  subject: RS(ANY_SUBJECT, 1),
104
- claims: { t: "array", req: true, min: 2, of: { source: R("source"), value: S({ req: true, max: 500 }), note: S({ max: 500 }), text: S({ max: 500 }) } },
104
+ // a value may be empty: the user's edit took a title off (decided by side, the title goes)
105
+ claims: { t: "array", req: true, min: 2, of: { source: R("source"), value: S({ max: 500 }), note: S({ max: 500 }), text: S({ max: 500 }) } },
105
106
  state: S({ req: true, enum: ["open", "resolved"] }),
106
107
  resolution: S({ max: 500 }),
107
108
  reasoning: S({ max: 2000 }),
109
+ decidedBy: S({ enum: ["user", "agent"] }),
110
+ decidedIn: S({ enum: ["app"] }),
111
+ decidedAt: S(),
112
+ taken: S({ enum: ["user", "research"] }),
108
113
  },
109
114
  hypothesis: {
110
115
  question: S({ req: true, max: 300 }),
@@ -113,10 +118,28 @@ export const SCHEMAS = {
113
118
  t: "array",
114
119
  req: true,
115
120
  min: 2,
116
- of: { label: S({ req: true, max: 20 }), claim: S({ req: true, max: 500 }), support: { t: "strings", req: true }, against: { t: "strings", req: true } },
121
+ of: {
122
+ label: S({ req: true, max: 20 }),
123
+ claim: S({ req: true, max: 500 }),
124
+ support: { t: "strings", req: true },
125
+ against: { t: "strings", req: true },
126
+ // what the variant would connect (strom hypothesis link): the records it names are references `check` follows
127
+ links: {
128
+ t: "array",
129
+ of: {
130
+ kind: S({ req: true, enum: VARIANT_LINK_KINDS }),
131
+ person: R("person"),
132
+ family: R("family"),
133
+ parents: { t: "refs", to: "person" },
134
+ persons: { t: "refs", to: "person" },
135
+ },
136
+ },
137
+ linked: { t: "refs", to: ["person", "family"] },
138
+ },
117
139
  },
118
140
  state: S({ req: true, enum: ["open", "decided", "abandoned"] }),
119
141
  decision: S({ max: 1000 }),
142
+ chosen: S({ max: 20 }),
120
143
  },
121
144
  lesson: {
122
145
  scope: S({ req: true, enum: LESSON_SCOPES }),
@@ -373,6 +373,51 @@ export function appShowsFactStatus(settings, version) {
373
373
  return (a[i] ?? 0) > (b[i] ?? 0);
374
374
  return true;
375
375
  }
376
+ /**
377
+ * The Strom app shows what each variant of an open hypothesis would connect (the app's spec
378
+ * docs/ZADANI_VYZKUM_nejista-spojeni.md, phase 1): 2 _VAR under each 1 _STROM_HYPO with its claim (3 TITL), its links
379
+ * (3 _LINK child|same|partners|siblings with 4 _PERS, _FAM, _PAR) and sources (3 SOUR), and where the tree ends the
380
+ * parents a variant names but nobody linked (2 _END named). Not released yet; another copy of the app (its beta, its
381
+ * development: strom.app.url) is taken as current, so it can be built. An app of unknown version: today's, once
382
+ * released (an older one only skips the tags).
383
+ */
384
+ export const APP_SHOWS_HYPOTHESIS_LINKS = undefined;
385
+ export function appShowsHypothesisLinks(settings, version) {
386
+ if (anotherCopy(settings))
387
+ return true;
388
+ if (!APP_SHOWS_HYPOTHESIS_LINKS)
389
+ return false;
390
+ if (!version)
391
+ return true;
392
+ const n = (v) => v.split(".").map((x) => Number.parseInt(x, 10) || 0);
393
+ const [a, b] = [n(version), n(APP_SHOWS_HYPOTHESIS_LINKS)];
394
+ for (let i = 0; i < 3; i++)
395
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
396
+ return (a[i] ?? 0) > (b[i] ?? 0);
397
+ return true;
398
+ }
399
+ /**
400
+ * The Strom app decides a conflict of the user's edit by side (the app's spec docs/ZADANI_VYZKUM_rozpory-v-aplikaci.md,
401
+ * phase 1): 2 _STROM_TAKE Y under each open one it may (a fact's value, a name, a title, a sex — never a child's
402
+ * parents), 3 _STROM_SIDE user|research under each of its values (2 VAL, empty when the side's value is), a sex also
403
+ * as 3 _STROM_RAW M|F|U. Not released yet; another copy of the app (its beta, its development: strom.app.url) is taken
404
+ * as current, so it can be built. An app of unknown version: today's, once released (3.10.1 only skips the tags).
405
+ */
406
+ export const APP_DECIDES_CONFLICTS = undefined;
407
+ export function appDecidesConflicts(settings, version) {
408
+ if (anotherCopy(settings))
409
+ return true;
410
+ if (!APP_DECIDES_CONFLICTS)
411
+ return false;
412
+ if (!version)
413
+ return true;
414
+ const n = (v) => v.split(".").map((x) => Number.parseInt(x, 10) || 0);
415
+ const [a, b] = [n(version), n(APP_DECIDES_CONFLICTS)];
416
+ for (let i = 0; i < 3; i++)
417
+ if ((a[i] ?? 0) !== (b[i] ?? 0))
418
+ return (a[i] ?? 0) > (b[i] ?? 0);
419
+ return true;
420
+ }
376
421
  /**
377
422
  * The Strom app turns an excerpt cut from a picture that lies on its side (2 _STROM_ORIENT 2–8, a phone's photo): from
378
423
  * 3.9.0 (the app's spec docs/ZADANI_VYZKUM_app-vstup-dat.md); another copy of the app is taken as current. An app of
package/dist/core/sync.js CHANGED
@@ -40,6 +40,7 @@ import { StromError, UsageError } from "./errors.js";
40
40
  import * as git from "./git.js";
41
41
  import { now, Tree, typeOfId } from "./tree.js";
42
42
  import { isArchive } from "./mode.js";
43
+ import { appSides } from "./conflicts.js";
43
44
  import { APP_DATA_SEX_UNKNOWN, isAppVersion } from "./stromapp.js";
44
45
  import { cleanTitle, familiesAsPartner, formatName, foundTitles, gedcomTitledName, primaryName, titledName } from "./people.js";
45
46
  /** The words of a _STAT (the Strom app's own, also Legacy's and FTM's) as a union, or nothing it names. */
@@ -667,6 +668,8 @@ const APP_COUPLE_EVENTS = {
667
668
  };
668
669
  /** Facts whose value is what they are (the GEDCOM tag's value). */
669
670
  const VALUE_KINDS = new Set(["OCCU", "RELI", "TITL", "NATI"]);
671
+ /** A fact that is its value (an occupation, a religion) without one: no fact — its value taken off in the app (B-1). */
672
+ const bare = (f) => VALUE_KINDS.has(kindOf(f.kind)) && !f.value?.trim();
670
673
  /** A tree of the Strom app (its JSON) as a snapshot. */
671
674
  export function readStromJson(data) {
672
675
  const d = data;
@@ -1254,7 +1257,7 @@ export function syncConflicts(tree, input) {
1254
1257
  const person = x.subject.find((s) => s.startsWith("P"));
1255
1258
  const family = x.subject.find((s) => s.startsWith("F"));
1256
1259
  const partner = person ?? (family ? tree.list("family").find((f) => f.id === family)?.partners[0] : undefined);
1257
- out.push({ id: x.id, ...(partner ? { person: partner } : {}), ...(family ? { family } : {}), ...(x.fact ? { fact: x.fact } : {}) });
1260
+ out.push({ id: x.id, ...(partner ? { person: partner } : {}), ...(family ? { family } : {}), ...(x.fact ? { fact: x.fact } : {}), ...appSides(tree, x) });
1258
1261
  }
1259
1262
  return out;
1260
1263
  }
@@ -1917,8 +1920,20 @@ export function planSync(tree, incoming, edits, opts = {}) {
1917
1920
  }
1918
1921
  const less = our.find((o) => knowsMore(o, f));
1919
1922
  if (less) {
1920
- // the file knows less of it (the date lost on the way)
1923
+ // the file knows less of it (the date lost on the way) — or, against what the app was given, the user took a
1924
+ // part of it off, the fact itself kept (B-1, found with the app's 3.11.0-beta.2: a proven death's date taken off,
1925
+ // "not written 1", no conflict): its date, place or value as given, the research's still. A record's fact: the
1926
+ // user's to decide (empty where nothing is left); a lead corrected. Without a base nothing is taken off (an
1927
+ // older copy, another program: what it lacks it may never have had)
1921
1928
  partsDiff(f, less);
1929
+ const given = less.id && !used.has(factKey(less)) ? was?.find((b) => factKey(b) === factKey(less) && (!b.id || b.id === less.id)) : undefined;
1930
+ const off = given ? ["date", "place", "value"].filter((k) => !!exact(given[k]) && !exact(f[k])) : [];
1931
+ if (off.length) {
1932
+ used.add(factKey(less));
1933
+ const action = recordBacked(tree, eventById(tree, less.id)) ? edits : "correct";
1934
+ if (action !== "conflict" || !openConflict(tree, owner.person ?? owner.family, f))
1935
+ push({ kind: "fact.changed", action, ...owner, fact: f, was: less, off });
1936
+ }
1922
1937
  continue;
1923
1938
  }
1924
1939
  if (was && baseKeys.has(k)) {
@@ -2857,7 +2872,7 @@ function addsTo(ours, file) {
2857
2872
  }
2858
2873
  /** An open conflict whose claims hold this value for the person or family already. */
2859
2874
  function openConflict(tree, owner, f) {
2860
- return openClaim(tree, owner, describe(f));
2875
+ return openClaim(tree, owner, claimValue(f));
2861
2876
  }
2862
2877
  function openClaim(tree, owner, value) {
2863
2878
  if (!owner)
@@ -3181,7 +3196,13 @@ export function applySync(tree, plan, incoming, source, only) {
3181
3196
  toVerify(owner, given);
3182
3197
  }
3183
3198
  else if (c.action === "correct" || (c.kind === "fact.differs" && c.action === "pick" && !recordBacked(tree, mine))) {
3184
- editEvent(tree, mine.id, { date: c.fact.date ?? "", place: c.fact.place ?? "", ...(c.fact.value !== undefined ? { value: c.fact.value } : {}) }, `corrected in ${reason}`);
3199
+ // a value the user took off goes (B-1); a fact that is its value (an occupation) goes with it
3200
+ if (bare(c.fact)) {
3201
+ retractEvent(tree, mine.id, `corrected in ${reason}`);
3202
+ applied.push({ do: "event.retract", id: mine.id, before: mine.status });
3203
+ break;
3204
+ }
3205
+ editEvent(tree, mine.id, { date: c.fact.date ?? "", place: c.fact.place ?? "", ...(c.fact.value !== undefined ? { value: c.fact.value } : c.off?.includes("value") ? { value: "" } : {}) }, `corrected in ${reason}`);
3185
3206
  // cited: the sources the user gave it in the app, else the sync — a family tree that gave the old value (a file
3186
3207
  // taken in, an earlier send) says it no more: its citation goes, kept for an undo (found on Mac: "S0001:
3187
3208
  // kovář" in a conflict, the file saying mlynář)
@@ -3199,6 +3220,8 @@ export function applySync(tree, plan, incoming, source, only) {
3199
3220
  else if (c.action === "user") {
3200
3221
  retractEvent(tree, mine.id, `the user's edit wins: ${reason}`);
3201
3222
  applied.push({ do: "event.retract", id: mine.id, before: mine.status });
3223
+ if (bare(c.fact))
3224
+ break;
3202
3225
  // the user's word: no record makes it probable — unless it is their reading of one, which counts
3203
3226
  const citations = theirs.length ? theirs : [cite(c.fact.kind)];
3204
3227
  const { event } = addEvent(tree, owner, { ...fields(c.fact), status: citations.some((x) => reading(x.source)) ? "probable" : "possible", citations });
@@ -3209,7 +3232,7 @@ export function applySync(tree, plan, incoming, source, only) {
3209
3232
  const title = editTitle(c.name ?? owner, eventName(c.fact.kind, tree.lang, c.fact.label), factWords(tree, incoming, mine), factWords(tree, incoming, c.fact));
3210
3233
  conflictOfEdit(tree, applied, owner, c.fact.kind, title, [
3211
3234
  { ...(mine.citations[0] ? { source: mine.citations[0].source } : {}), value: describe(mine), note: `the research: ${mine.id}`, text: factWords(tree, incoming, mine) },
3212
- { source: source.id, value: describe(c.fact), note: "the user's edit", text: factWords(tree, incoming, c.fact) },
3235
+ { source: source.id, value: claimValue(c.fact), note: "the user's edit", text: factWords(tree, incoming, c.fact) },
3213
3236
  ], { event: mine.id, ...(c.fact.date ? { date: c.fact.date } : {}), ...(c.fact.place ? { place: c.fact.place } : {}), ...(c.fact.value ? { value: c.fact.value } : {}), ...(theirs.length ? { cites: theirs } : {}) });
3214
3237
  }
3215
3238
  break;
@@ -3753,6 +3776,11 @@ function describe(f) {
3753
3776
  const ages = Object.entries(f.ages ?? {}).map(([who, a]) => `${who} aged ${a}`);
3754
3777
  return [f.value, f.date, f.place, f.house && `house ${f.house}`, f.age && `aged ${f.age}`, ...ages, f.cause && `cause ${f.cause}`].filter(Boolean).join(", ") || "—";
3755
3778
  }
3779
+ /** A fact as a claim of a conflict of the user's edit holds it: nothing left of it (B-1: its date and place taken off) empty. */
3780
+ function claimValue(f) {
3781
+ const said = describe(f);
3782
+ return said === "—" ? "" : said;
3783
+ }
3756
3784
  /**
3757
3785
  * The title of a conflict of the user's edit, in the research's language — the Strom app shows it in what the research
3758
3786
  * knows (found on Mac: "Petr Svoboda: SEX — U × F" in a Czech research): "Petr Svoboda: Pohlaví — neznámé × žena".
@@ -3839,6 +3867,11 @@ export function takeSide(tree, x, side, reason) {
3839
3867
  const user = x.claims.find((c) => c.note === "the user's edit");
3840
3868
  // where the user's value came from: the sources they gave it in the app (where in them), and their edits' source
3841
3869
  const cited = [...(x.edit.cites ?? []), ...(user?.source && tree.get(user.source)?.type === "source" ? [{ source: user.source, locator: mine.kind }] : [])].filter((c, i, all) => !!tree.get(c.source) && all.findIndex((y) => y.source === c.source) === i);
3870
+ // a fact that is its value (an occupation) with the value taken off is no fact: withdrawn, nothing in its place (B-1)
3871
+ if (bare({ kind: mine.kind, ...(x.edit.value ? { value: x.edit.value } : {}) })) {
3872
+ retractEvent(tree, mine.id, `the user's edit wins (${x.id}): ${reason}`);
3873
+ return `${mine.id} withdrawn`;
3874
+ }
3842
3875
  if (recordBacked(tree, mine)) {
3843
3876
  retractEvent(tree, mine.id, `the user's edit wins (${x.id}): ${reason}`);
3844
3877
  const { event } = addEvent(tree, owner, { kind: mine.kind, ...(x.edit.date ? { date: x.edit.date } : {}), ...(x.edit.place ? { place: x.edit.place } : {}), ...(x.edit.value ? { value: x.edit.value } : {}), ...(mine.label ? { label: mine.label } : {}), status: "possible", citations: cited });
package/dist/core/tree.js CHANGED
@@ -27,7 +27,7 @@ import { lastBackup } from "./backup.js";
27
27
  export const TREE_FILE = "strom.json";
28
28
  // between releases the candidate being made (a bridge run from the sources says what it is: the Strom app goes by it);
29
29
  // at a release the release's own (package.json)
30
- export const VERSION = "1.13.1";
30
+ export const VERSION = "1.13.2-beta.2";
31
31
  const GITIGNORE = `# Strom Research — local state and large files are not versioned
32
32
  .strom/
33
33
  /media/
@@ -248,10 +248,49 @@ export function validateRecord(value) {
248
248
  const spec = SCHEMAS[rec.type];
249
249
  if (spec)
250
250
  checkFields(value, spec, ALL_PREFIXES, "", out, []);
251
+ if (rec.type === "hypothesis")
252
+ checkVariantLinks(rec, out);
251
253
  checkNotes(value.notes, "notes", out);
252
254
  }
253
255
  return out;
254
256
  }
257
+ /**
258
+ * What a variant would connect, by its kind: a child with a family or one or two parents; two records of one person,
259
+ * a couple, siblings — the people of each. How many is the command's to check (strom hypothesis link): a merge
260
+ * repoints every reference, and the two records of one person become one.
261
+ */
262
+ function checkVariantLinks(h, out) {
263
+ if (!Array.isArray(h.variants))
264
+ return;
265
+ h.variants.forEach((v, i) => {
266
+ if (!isObj(v) || v.links === undefined || !Array.isArray(v.links))
267
+ return;
268
+ v.links.forEach((l, j) => {
269
+ const p = `variants[${i}].links[${j}]`;
270
+ if (!isObj(l))
271
+ return;
272
+ const link = l;
273
+ if (link.kind === "child") {
274
+ if (!str(link.person))
275
+ out.push({ path: `${p}.person`, message: "is required (the child)" });
276
+ const parents = Array.isArray(link.parents) ? link.parents.length : 0;
277
+ if (link.family !== undefined && link.parents !== undefined)
278
+ out.push({ path: p, message: "a family or parents, not both" });
279
+ else if (link.family === undefined && (parents < 1 || parents > 2))
280
+ out.push({ path: `${p}.parents`, message: "a family, or one or two parents" });
281
+ if (link.persons !== undefined)
282
+ out.push({ path: `${p}.persons`, message: "is not for a child link" });
283
+ }
284
+ else if (link.kind === "same" || link.kind === "partners" || link.kind === "siblings") {
285
+ const n = Array.isArray(link.persons) ? link.persons.length : 0;
286
+ if (n < 1 || (link.kind !== "siblings" && n > 2))
287
+ out.push({ path: `${p}.persons`, message: link.kind === "siblings" ? "needs the siblings" : "needs the two persons" });
288
+ if (link.person !== undefined || link.family !== undefined || link.parents !== undefined)
289
+ out.push({ path: p, message: `a ${link.kind} link has persons only` });
290
+ }
291
+ });
292
+ });
293
+ }
255
294
  /**
256
295
  * A record as strom reads, writes and checks it: a family's husb (the side its files keep, U01-e) only while it names
257
296
  * one of its two partners — else it is dropped, never an error (B5-a: a partner taken away by a sync, by an archive's
@@ -38,6 +38,7 @@ import { hypothesisPeople } from "../core/directions.js";
38
38
  import * as git from "../core/git.js";
39
39
  import { treeEdges } from "../core/edge.js";
40
40
  import { readersOf } from "../core/review.js";
41
+ import { sexRaw, sideText, sidesOf } from "../core/conflicts.js";
41
42
  import { humanTask } from "../cli/human.js";
42
43
  export const GED_PROFILES = ["standard", "strom"];
43
44
  /**
@@ -65,6 +66,8 @@ export function stromReadsTags(version, from = STROM_READS_TAGS, unknown = false
65
66
  return (a[i] ?? 0) > (b[i] ?? 0);
66
67
  return true;
67
68
  }
69
+ /** A source named by its ID in a text of any script (never \b, which knows only ASCII letters): as namesId. */
70
+ const SOURCE_ID = /(?<![\p{L}\p{M}\p{N}])S\d{4,}(?![\p{L}\p{M}\p{N}])/gu;
68
71
  /** Whose IDs a person's REFN carries: a tree coming back is matched by them (strom sync, the Strom app). */
69
72
  export const REFN_TYPE = "strom-research";
70
73
  /** Tags whose value IS the fact and rides on the tag line. */
@@ -142,11 +145,13 @@ export function exportGedcom(tree, opts = {}) {
142
145
  // What the research knows beyond the facts (the Strom profile, opts.research): read once.
143
146
  const research = {
144
147
  conflicts: opts.research ? tree.list("conflict") : [],
145
- // with the people each is about: its subject's, and those its variants name (core/directions.ts hypothesisPeople)
148
+ // with the people each is about: its subject's, and those its variants name (core/directions.ts hypothesisPeople);
149
+ // for an app that shows what a hypothesis would connect, a decided or abandoned one too while a variant of it has
150
+ // links — the app tells "decided for B" (its ghost now a real link) from "decided otherwise" (STAT, _CHOSEN)
146
151
  hypotheses: opts.research
147
152
  ? tree
148
153
  .list("hypothesis")
149
- .filter((h) => h.state === "open")
154
+ .filter((h) => !h.retracted && (h.state === "open" || (opts.hypothesisLinks && h.variants.some((v) => v.links?.length))))
150
155
  .map((h) => ({ h, people: hypothesisPeople(tree, h) }))
151
156
  : [],
152
157
  // a search is of the people of the task it served
@@ -158,7 +163,7 @@ export function exportGedcom(tree, opts = {}) {
158
163
  : [],
159
164
  };
160
165
  // Where the tree ends, and the families nothing links to it (the Strom profile, opts.edges).
161
- const ends = opts.edges && opts.for === "strom" ? treeEdges(tree) : undefined;
166
+ const ends = opts.edges && opts.for === "strom" ? treeEdges(tree, { named: !!opts.hypothesisLinks }) : undefined;
162
167
  // Who read each source (the Strom profile, opts.sourceReads).
163
168
  const readers = opts.sourceReads && opts.for === "strom" ? readersOf(tree) : undefined;
164
169
  // ── header ──
@@ -555,13 +560,24 @@ export function exportGedcom(tree, opts = {}) {
555
560
  w.line(2, "TYPE", c.fact ?? "EVEN");
556
561
  w.text(2, "TITL", conflictTitle(tree, c));
557
562
  w.line(2, "STAT", c.state === "resolved" ? "decided" : "open");
563
+ // a conflict of the user's edit the app decides by side (open: it may now), each value with its side
564
+ const sides = opts.conflictSides && opts.for === "strom" ? sidesOf(c) : undefined;
565
+ if (sides && c.state === "open")
566
+ w.line(2, "_STROM_TAKE", "Y");
558
567
  for (const claim of c.claims) {
559
- // in the research's language (found on Mac: "14 JAN 1931, Dolní Lhota, house 12" in the app's dialog)
560
- w.text(2, "VAL", claimText(tree, c, claim));
568
+ const side = sides ? (claim === sides.user ? "user" : claim === sides.research ? "research" : undefined) : undefined;
569
+ // in the research's language (found on Mac: "14 JAN 1931, Dolní Lhota, house 12" in the app's dialog); a side's
570
+ // empty value empty (2 VAL alone: the app shows it as empty)
571
+ w.text(2, "VAL", side ? sideText(tree, c, claim) : claimText(tree, c, claim));
561
572
  if (claim.source && sourceById.has(claim.source)) {
562
573
  citedSources.add(claim.source);
563
574
  w.line(3, "SOUR", x(claim.source));
564
575
  }
576
+ if (side) {
577
+ w.line(3, "_STROM_SIDE", side);
578
+ if (c.fact === "SEX")
579
+ w.line(3, "_STROM_RAW", sexRaw(claim.value));
580
+ }
565
581
  }
566
582
  if (c.state === "resolved" && c.resolution)
567
583
  w.text(2, "DECI", c.resolution);
@@ -569,7 +585,15 @@ export function exportGedcom(tree, opts = {}) {
569
585
  for (const { h } of research.hypotheses.filter((x) => x.people.includes(p.id))) {
570
586
  w.line(1, "_STROM_HYPO", h.id);
571
587
  w.text(2, "TITL", h.question);
588
+ if (opts.hypothesisLinks) {
589
+ w.line(2, "STAT", h.state);
590
+ if (h.state === "decided" && h.chosen)
591
+ w.line(2, "_CHOSEN", h.chosen);
592
+ }
572
593
  w.text(2, "NOTE", h.variants.map((v) => `${v.label}: ${v.claim}`).join("\n"));
594
+ if (opts.hypothesisLinks)
595
+ for (const v of h.variants)
596
+ variant(v, h.state === "open");
573
597
  }
574
598
  for (const q of research.searched.filter((x) => x.people.includes(p.id)).map((x) => x.search)) {
575
599
  w.line(1, "_STROM_SEARCHED");
@@ -581,6 +605,47 @@ export function exportGedcom(tree, opts = {}) {
581
605
  w.line(2, "_AT", q.created.slice(0, 10));
582
606
  }
583
607
  }
608
+ /**
609
+ * A variant of a hypothesis: its claim, what it would connect — only a link all of whose records are in the file,
610
+ * and of an open one none the tree has already (a child of that family; a decided one keeps it: the link it chose,
611
+ * now recorded); never one person merged into the other — and the sources its claim and support name (the app's
612
+ * ZADANI_VYZKUM_nejista-spojeni.md).
613
+ */
614
+ function variant(v, open) {
615
+ w.line(2, "_VAR", v.label);
616
+ w.text(3, "TITL", v.claim);
617
+ const person = (id) => personIds.has(id);
618
+ for (const l of v.links ?? []) {
619
+ if (l.kind === "child") {
620
+ const parents = [...new Set(l.parents ?? [])];
621
+ // the family named, else the one its parents have made since (_PAR: parents who have no family together)
622
+ const f = l.family ? families.find((x) => x.id === l.family) : families.find((x) => parents.length && x.partners.length === parents.length && parents.every((p) => x.partners.includes(p)));
623
+ if (!person(l.person) || (l.family && !f) || (!f && (!parents.length || !parents.every(person))) || (open && f?.children.some((c) => c.person === l.person)))
624
+ continue;
625
+ w.line(3, "_LINK", "child");
626
+ w.line(4, "_PERS", x(l.person));
627
+ if (f)
628
+ w.line(4, "_FAM", x(f.id));
629
+ else
630
+ for (const p of parents)
631
+ w.line(4, "_PAR", x(p));
632
+ }
633
+ else {
634
+ const people = [...new Set(l.persons)];
635
+ if (people.length < 2 || !people.every(person))
636
+ continue;
637
+ w.line(3, "_LINK", l.kind);
638
+ for (const p of people)
639
+ w.line(4, "_PERS", x(p));
640
+ }
641
+ }
642
+ const named = new Set([v.claim, ...v.support].flatMap((text) => text.match(SOURCE_ID) ?? []));
643
+ for (const s of named)
644
+ if (sourceById.has(s)) {
645
+ citedSources.add(s);
646
+ w.line(3, "SOUR", x(s));
647
+ }
648
+ }
584
649
  /** Years as a GEDCOM date: one year, or FROM … TO …. */
585
650
  function years(r) {
586
651
  return r.from === r.to ? String(r.from) : `FROM ${r.from} TO ${r.to}`;
@@ -641,6 +706,10 @@ export function exportGedcom(tree, opts = {}) {
641
706
  w.line(2, "_HYPO", h.id);
642
707
  for (const j of h.joins)
643
708
  w.line(3, "_JOIN", j);
709
+ // which variant would make the join (an app that shows what a hypothesis would connect)
710
+ if (opts.hypothesisLinks)
711
+ for (const v of h.variants ?? [])
712
+ w.line(3, "_VAR", v);
644
713
  if (h.island) {
645
714
  w.line(3, "_ISLAND", String(h.island.people));
646
715
  w.line(3, "_HELD", String(h.island.held));
@@ -669,6 +738,9 @@ export function exportGedcom(tree, opts = {}) {
669
738
  w.line(2, "_HYPO", h.id);
670
739
  for (const j of h.joins)
671
740
  w.line(3, "_JOIN", j);
741
+ if (opts.hypothesisLinks)
742
+ for (const v of h.variants ?? [])
743
+ w.line(3, "_VAR", v);
672
744
  }
673
745
  if (i.held)
674
746
  w.line(2, "_HELD", String(i.held));
@@ -5,7 +5,7 @@
5
5
  // gets trimmed by some readers and two words silently glue together.
6
6
  export const MAX_LINE_BYTES = 255;
7
7
  /** Tags whose value may be a pointer (@X@) — everywhere else an "@" is text and is doubled. */
8
- const POINTER_TAGS = new Set(["FAMC", "FAMS", "HUSB", "WIFE", "CHIL", "SOUR", "REPO", "ASSO", "SUBM", "SUBN", "OBJE", "NOTE", "ALIA", "ANCI", "DESI"]);
8
+ const POINTER_TAGS = new Set(["FAMC", "FAMS", "HUSB", "WIFE", "CHIL", "SOUR", "REPO", "ASSO", "SUBM", "SUBN", "OBJE", "NOTE", "ALIA", "ANCI", "DESI", "_PERS", "_FAM", "_PAR"]);
9
9
  /** GEDCOM 5.5.1 writes a literal "@" as "@@" (so "@I1@ BIRT" in a note is not a pointer). */
10
10
  export function escapeAt(tag, value) {
11
11
  if (POINTER_TAGS.has(tag) && /^@[^@\s]+@$/.test(value))
@@ -20,12 +20,16 @@ const CHILDREN = {
20
20
  "HEAD.GEDC": ["VERS", "FORM"],
21
21
  "HEAD.DATE": ["TIME"],
22
22
  INDI: ["NAME", "SEX", "FAMC", "FAMS", "NOTE", "SOUR", "REFN", "ASSO", "ALIA", "OBJE", "RESN", "RIN", "CHAN", "_STORY", "_STROM_CONFLICT", "_STROM_HYPO", "_STROM_SEARCHED", "_STROM_EDGE", "_STROM_ISLAND", ...INDI_EVENTS],
23
- "INDI._STROM_CONFLICT": ["TYPE", "TITL", "STAT", "VAL", "DECI"],
24
- "INDI._STROM_HYPO": ["TITL", "NOTE"],
23
+ "INDI._STROM_CONFLICT": ["TYPE", "TITL", "STAT", "_STROM_TAKE", "VAL", "DECI"],
24
+ "INDI._STROM_HYPO": ["TITL", "STAT", "_CHOSEN", "NOTE", "_VAR"],
25
+ // what a variant of a hypothesis would connect (the Strom profile)
26
+ _VAR: ["TITL", "_LINK", "SOUR"],
27
+ _LINK: ["_PERS", "_FAM", "_PAR"],
25
28
  "INDI._STROM_SEARCHED": ["TITL", "DATE", "RESN", "_AT"],
26
29
  "INDI._STROM_EDGE": ["_SCOPE", "_RESEARCH", "_GEN", "_END", "_NEXT", "_EST", "DATE", "_RECORDS", "_BOOK", "_COVERED", "_NORECORDS", "_TASK", "_TRIED", "_HYPO", "_CONFLICT", "_SEARCHES", "_SESSIONS", "_LAST"],
27
30
  "INDI._STROM_ISLAND": ["_HYPO", "_HELD"],
28
- _STROM_VALUE: ["SOUR"],
31
+ // a value of a conflict the app decides by side: its side, a sex as M, F or U
32
+ _STROM_VALUE: ["SOUR", "_STROM_SIDE", "_STROM_RAW"],
29
33
  "INDI.NAME": ["TYPE", "GIVN", "SURN", "NPFX", "NSFX", "NICK", "SPFX", "SOUR", "NOTE"],
30
34
  "INDI.FAMC": ["PEDI", "NOTE"],
31
35
  "INDI.FAMS": ["NOTE"],
@@ -52,13 +56,15 @@ const CHILDREN = {
52
56
  const TEXT_TAGS = new Set(["NOTE", "TEXT", "TITL", "PAGE", "AUTH", "PUBL", "_STORY", "DATA", "COPR", "ADDR", "CAUS", "FILE", "_URL", "VAL", "DECI"]);
53
57
  const EXTENSIONS = new Set([
54
58
  "_STORY", "_WITN", "_FREL", "_MREL", "_STROM_KIND", "_URL", "_STROM_TREE", "_STROM_HEAD", "_STROM_LINKS", "_STROM_CLIP",
55
- "_STROM_ASOF", "_SCHEME", "_STROM_CONFLICT", "_STROM_HYPO", "_STROM_SEARCHED", "_AT",
59
+ "_STROM_ASOF", "_SCHEME", "_STROM_CONFLICT", "_STROM_TAKE", "_STROM_SIDE", "_STROM_RAW", "_STROM_HYPO", "_STROM_SEARCHED", "_AT",
56
60
  // where the tree ends (_STROM_EDGE) and the families nothing links to it (_STROM_ISLAND), with their parts
57
61
  "_STROM_EDGE", "_STROM_ISLAND", "_SCOPE", "_RESEARCH", "_GEN", "_END", "_NEXT", "_EST", "_BASIS", "_RECORDS", "_BOOK", "_ACCESS",
58
62
  "_COVERED", "_NORECORDS", "_TASK", "_LEVEL", "_POS", "_HELD", "_UNTIL", "_TRIED", "_HYPO", "_JOIN", "_ISLAND", "_TEST", "_CONFLICT",
59
63
  "_SEARCHES", "_SESSIONS", "_COST", "_PARTIAL", "_LAST",
60
64
  // the new version of an approved story, waiting for the user
61
65
  "_DRAFT",
66
+ // what a variant of a hypothesis would connect
67
+ "_VAR", "_LINK", "_PERS", "_FAM", "_PAR", "_CHOSEN",
62
68
  ]);
63
69
  /** Context of the children of the last tag in `anc` (the ancestors of a line). */
64
70
  function contextOf(anc) {
@@ -77,6 +83,10 @@ function contextOf(anc) {
77
83
  return "_STORY";
78
84
  if (parent === "_WITN")
79
85
  return "_WITN";
86
+ if (parent === "_VAR" && anc[1] === "_STROM_HYPO")
87
+ return "_VAR";
88
+ if (parent === "_LINK" && anc[2] === "_VAR")
89
+ return "_LINK";
80
90
  if (parent === "ADDR")
81
91
  return "ADDR";
82
92
  if (parent === "DATA" && anc[depth - 2] === "SOUR")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strom-research",
3
- "version": "1.13.1",
3
+ "version": "1.13.2-beta.2",
4
4
  "description": "Genealogical research toolkit for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
@@ -45,5 +45,8 @@
45
45
  "devDependencies": {
46
46
  "@types/node": "^22.20.4",
47
47
  "typescript": "^7.0.2"
48
+ },
49
+ "publishConfig": {
50
+ "tag": "beta"
48
51
  }
49
52
  }