dsh-asteme 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -5,3 +5,8 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
5
5
 
6
6
  The name "Asteme" and the constellation mark (icon.svg) are not covered by
7
7
  that license: see TRADEMARKS.md.
8
+
9
+ The films and pictures in public/media are part of this project. The score of
10
+ the films is an original piece played from the Salamander Grand Piano V3
11
+ samples by Alexander Holm, used under CC BY 3.0
12
+ (https://creativecommons.org/licenses/by/3.0/).
package/brain/acp.mjs CHANGED
@@ -121,7 +121,7 @@ export function openWorker({ name, command, args = [], env = {}, cwd = process.c
121
121
  });
122
122
  const hello = await call(
123
123
  "initialize",
124
- { protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: "asteme", version: "0.11.0" } },
124
+ { protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: "asteme", version: "0.12.0" } },
125
125
  startTimeoutMs,
126
126
  );
127
127
  return hello;
package/brain/mind.mjs CHANGED
@@ -33,11 +33,19 @@ export const DEFAULTS = {
33
33
  presentChars: 12000,
34
34
  earlier: 10,
35
35
  promptChars: 80000,
36
- fixedChars: 20500,
36
+ // What every speaking call carries whatever is said: the rules, the charter, the shape of the answer. A test holds this to the real size, so the rules cannot grow past it unnoticed.
37
+ fixedChars: 24500,
37
38
  candidateChars: 28000,
38
39
  fileBytes: 25000000,
39
40
  filesAtOnce: 6,
40
41
  fileText: 4000,
42
+ // Between two messages said one after the other: a moment, longer for more words, the way a second message takes a moment to write.
43
+ pauseMs: 700,
44
+ pauseChar: 25,
45
+ pauseMax: 2600,
46
+ // How long the user was not here before coming back counts as coming back, and how many things are kept to bring up then.
47
+ absenceMs: 3 * 3600000,
48
+ held: 8,
41
49
  };
42
50
  // Kinds of file whose beginning can be read as text. The bytes decide in the
43
51
  // end: a file with one of these names that is not text is not read.
@@ -134,8 +142,10 @@ export function openMind({
134
142
  // looked at again with more of what it remembers before it is said, and dots that came, went and came back read as words that were lost.
135
143
  let writing = false,
136
144
  greeting = null;
145
+ // On an occasion where saying nothing is the ordinary case, the dots do not come up for words that may never be said: they would appear and go, answering nothing.
146
+ let hushed = false;
137
147
  const write = (on) => {
138
- if (writing === on) return;
148
+ if (writing === on || (on && hushed)) return;
139
149
  writing = on;
140
150
  emit({ type: "writing", on });
141
151
  };
@@ -420,7 +430,26 @@ export function openMind({
420
430
  }
421
431
  return { answered: ask.id };
422
432
  }
433
+ // Something to bring up when the user is next around: kept in its own words, with no time on it.
434
+ if (a.act === "hold") {
435
+ const about = typeof a.about === "string" ? cut(a.about.trim(), 300) : "";
436
+ if (!about) return { refused: "hold", why: "what is kept needs words" };
437
+ const list = held();
438
+ if (list.length >= cfg.held) return { refused: "hold", why: `${cfg.held} things are kept already; let one go first` };
439
+ const kept = { id: `held-${randomUUID().slice(0, 8)}`, at: log.now(), about, ...(origin ? { from: origin } : {}) };
440
+ log.save("brain:mind", [...list, kept]);
441
+ emit({ type: "intention" });
442
+ return { holding: kept.id };
443
+ }
423
444
  if (a.act === "unwake") {
445
+ if (held().some((h) => h.id === a.id)) {
446
+ log.save(
447
+ "brain:mind",
448
+ held().filter((h) => h.id !== a.id),
449
+ );
450
+ emit({ type: "intention" });
451
+ return { unset: a.id };
452
+ }
424
453
  if (!standing().some((w) => w.id === a.id)) return { refused: "unwake", why: "there is no such time set" };
425
454
  wake.forget(a.id);
426
455
  emit({ type: "intention" });
@@ -527,6 +556,9 @@ export function openMind({
527
556
  // The times it has set to look at something or to speak, soonest first. A watch on a worker is its own business.
528
557
  const standing = () => wake.alarms.filter((a) => !String(a.ref ?? "").startsWith("watch:")).sort((a, b) => a.at - b.at);
529
558
 
559
+ // What it keeps to bring up when the user is next around. No time is set on these; each is in its own words, from the moment it kept it.
560
+ const held = () => (log.state("brain:mind", null) ?? []).filter((h) => h && typeof h.id === "string" && typeof h.about === "string");
561
+
530
562
  // --- One moment of attention ---------------------------------------------------
531
563
  const think = async (request, present) => {
532
564
  // An earlier message that came with files says so, by name, where the model reads it.
@@ -542,6 +574,7 @@ export function openMind({
542
574
  : e,
543
575
  );
544
576
  let reply = "",
577
+ more = [],
545
578
  acts = [];
546
579
  const zone = cfg.zone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;
547
580
  const here = new Intl.DateTimeFormat("sv-SE", { timeZone: zone, dateStyle: "short", timeStyle: "short" }).format(new Date(log.now()));
@@ -576,6 +609,7 @@ export function openMind({
576
609
  }
577
610
  : {}),
578
611
  ...unanswered(present),
612
+ ...(held().length ? { mind: held().map((h) => ({ id: h.id, since: new Date(h.at).toISOString(), about: h.about })) } : {}),
579
613
  ...(feel().express && expressions().length
580
614
  ? { expressions: expressions().map((x) => ({ name: x.name, ...(x.shows ? { shows: x.shows } : {}) })) }
581
615
  : {}),
@@ -605,7 +639,11 @@ export function openMind({
605
639
  input: input(found),
606
640
  draft: () => ({ reply, acts }),
607
641
  heard: (a) => {
608
- if (typeof a.reply === "string") reply = a.reply;
642
+ // What follows the reply belongs to that reply: a later answer that says the reply again says what follows it again, or that nothing does.
643
+ if (typeof a.reply === "string") {
644
+ reply = a.reply;
645
+ more = Array.isArray(a.more) ? a.more : [];
646
+ }
609
647
  if (Array.isArray(a.acts)) acts = a.acts;
610
648
  },
611
649
  });
@@ -675,7 +713,19 @@ export function openMind({
675
713
  memories: core.items().length,
676
714
  at: log.now(),
677
715
  };
678
- return { reply: typeof reply === "string" ? reply.trim() : "", acts: acts.filter((a) => a?.act !== "search"), trace };
716
+ const opening = typeof reply === "string" ? reply.trim() : "";
717
+ return {
718
+ reply: opening,
719
+ // Two more at most, and only after a first: a reply in pieces is still one reply.
720
+ more: opening
721
+ ? more
722
+ .filter((m) => typeof m === "string" && m.trim())
723
+ .map((m) => m.trim())
724
+ .slice(0, 2)
725
+ : [],
726
+ acts: acts.filter((a) => a?.act !== "search"),
727
+ trace,
728
+ };
679
729
  };
680
730
  const attend = async (event) => {
681
731
  thinking = true;
@@ -686,6 +736,7 @@ export function openMind({
686
736
  thinkingSince = since;
687
737
  try {
688
738
  let request, present;
739
+ hushed = event.kind === "return";
689
740
  own();
690
741
  if (event.kind === "user") {
691
742
  const files = (event.files ?? []).map(fileOf).filter(Boolean),
@@ -797,6 +848,19 @@ export function openMind({
797
848
  );
798
849
  if (!turnOpen) turnOpen = true;
799
850
  present = { kind: "a time you set has come", why: event.why, ...(event.away ? { away: event.away } : {}) };
851
+ } else if (event.kind === "return") {
852
+ // The user is here again after a time away, and something was kept to bring up. Whether it is brought up is its own to decide; mostly it is not.
853
+ if (!held().length) return;
854
+ const hours = Math.max(1, Math.round((event.gone.to - event.gone.from) / 3600000));
855
+ request = add("tool", `The user is here again, after about ${hours} ${hours === 1 ? "hour" : "hours"} away.`, "tool/result", {
856
+ tool: { phase: "result", name: "clock", execution: "completed" },
857
+ });
858
+ if (!turnOpen) turnOpen = true;
859
+ present = {
860
+ kind: "the user is back",
861
+ gone: { from: new Date(event.gone.from).toISOString(), to: new Date(event.gone.to).toISOString() },
862
+ note: "Nothing is asked of you and the user has said nothing yet.",
863
+ };
800
864
  } else if (event.kind === "born") {
801
865
  request = add("tool", "You have just been woken for the first time.", "tool/result", {
802
866
  tool: { phase: "result", name: "clock", execution: "completed" },
@@ -808,7 +872,7 @@ export function openMind({
808
872
  note: "Nothing has been said yet and nothing is asked of you. Greet the person, briefly, in your own voice, in the language their screen is in (language, when given, is its tag).",
809
873
  };
810
874
  } else return;
811
- const { reply, acts, trace } = await think(request, present);
875
+ const { reply, more, acts, trace } = await think(request, present);
812
876
  // Stopped by the user while it thought: nothing is said and nothing is done, and it is on record that this is why.
813
877
  if (mine.signal.aborted) {
814
878
  add("tool", "The user stopped this before you answered. Nothing was said and nothing was done.", "tool/result", {
@@ -852,6 +916,27 @@ export function openMind({
852
916
  ...with_,
853
917
  used: trace.delivered.map((i) => ({ id: i.id, use: i.use, text: cut(i.text, 200) })),
854
918
  });
919
+ // What it says right after, each a message of its own, a moment apart. Stopped in between, the rest is not said.
920
+ if (more.length) {
921
+ hushed = false;
922
+ write(true);
923
+ }
924
+ for (const text of more) {
925
+ await new Promise((done) => {
926
+ const t = setTimeout(done, Math.min(cfg.pauseMax, cfg.pauseMs + text.length * cfg.pauseChar));
927
+ mine.signal.addEventListener(
928
+ "abort",
929
+ () => {
930
+ clearTimeout(t);
931
+ done();
932
+ },
933
+ { once: true },
934
+ );
935
+ });
936
+ if (mine.signal.aborted) break;
937
+ const next = add("assistant", text);
938
+ emit({ type: "message", role: "assistant", text, at: next.occurredAt, id: next.id });
939
+ }
855
940
  }
856
941
  // The matter is closed for now when nothing is out; reflection reads it whole.
857
942
  if (!running().length) endTurn();
@@ -859,6 +944,7 @@ export function openMind({
859
944
  thinking = false;
860
945
  thinkingSince = null;
861
946
  if (halt === mine) halt = null;
947
+ hushed = false;
862
948
  write(false);
863
949
  emit({ type: "thinking", on: false });
864
950
  }
@@ -932,6 +1018,8 @@ export function openMind({
932
1018
  const ids = Array.isArray(files) ? files.filter((id) => fileOf(id)).slice(0, cfg.filesAtOnce) : [];
933
1019
  if (typeof text !== "string" || (!text.trim() && !ids.length)) throw new Error("Say something");
934
1020
  if (log.state("brain:draft", null)) log.save("brain:draft", null);
1021
+ // Whoever speaks is here.
1022
+ log.save("brain:here", log.now());
935
1023
  // Said in answer to one thing that was said before: it is named, so that "that one" has something to point at.
936
1024
  const about =
937
1025
  typeof replyTo === "string"
@@ -1001,8 +1089,15 @@ export function openMind({
1001
1089
  },
1002
1090
  /** A time it set is taken back by the user. What it said when it set it stays said. */
1003
1091
  unwake(id) {
1004
- if (!standing().some((w) => w.id === id)) throw new Error("That time is no longer set");
1005
- wake.forget(id);
1092
+ if (held().some((h) => h.id === id))
1093
+ log.save(
1094
+ "brain:mind",
1095
+ held().filter((h) => h.id !== id),
1096
+ );
1097
+ else {
1098
+ if (!standing().some((w) => w.id === id)) throw new Error("That time is no longer set");
1099
+ wake.forget(id);
1100
+ }
1006
1101
  emit({ type: "intention" });
1007
1102
  return plain({
1008
1103
  intentions: standing()
@@ -1087,6 +1182,19 @@ export function openMind({
1087
1182
  if (kept !== log.state("brain:draft", null)) log.save("brain:draft", kept);
1088
1183
  return plain({ kept: !!kept });
1089
1184
  },
1185
+ /**
1186
+ * The user is in front of the conversation. After a time away, when
1187
+ * something was kept to bring up, that is an occasion: it is woken to
1188
+ * decide for itself whether to say it. Nothing is kept, nothing happens.
1189
+ */
1190
+ here() {
1191
+ const now = log.now(),
1192
+ last = log.state("brain:here", null);
1193
+ if (!last || now - last > 60000) log.save("brain:here", now);
1194
+ const back = !!last && now - last >= cfg.absenceMs && held().length > 0 && !thinking && !running().length;
1195
+ if (back) wake.stimulus({ kind: "return", gone: { from: last, to: now } });
1196
+ return plain({ here: true, back });
1197
+ },
1090
1198
  seen(ids) {
1091
1199
  if (!Array.isArray(ids)) return plain({ seen: 0 });
1092
1200
  log.save("brain:shown", log.now());
@@ -1443,6 +1551,7 @@ export function openMind({
1443
1551
  intentions: standing()
1444
1552
  .slice(0, 8)
1445
1553
  .map((a) => ({ id: a.id, at: a.at, why: a.why, ...(a.every ? { every: a.every } : {}) })),
1554
+ held: held().map((h) => ({ id: h.id, at: h.at, about: h.about })),
1446
1555
  unread: log.pending(identity, STAGE).length,
1447
1556
  idle: d.sleep?.idle ?? [],
1448
1557
  lastSleep: d.sleep?.last ?? null,
@@ -209,6 +209,9 @@ const when = (at) => {
209
209
  ? d.toLocaleTimeString(lang, { hour: "numeric", minute: "2-digit" })
210
210
  : d.toLocaleDateString(lang, { month: "short", day: "numeric" });
211
211
  };
212
+ // To the end of the conversation. Once the conversation is drawn, this is its own doing (carry, where it is drawn): what was on the page is seen to travel there.
213
+ let carryNow = null;
212
214
  const down = () => {
213
- scroller.scrollTop = scroller.scrollHeight;
215
+ if (carryNow) carryNow(true);
216
+ else scroller.scrollTop = scroller.scrollHeight;
214
217
  };
@@ -1,12 +1,15 @@
1
1
  // --- Among the stars -------------------------------------------------------------
2
2
  // The sky behind the conversation is a window onto something larger. Take hold
3
3
  // of it and the conversation falls away, the flat sky tips over into depth and
4
- // you are carried in: every memory is there, laid out as a galaxy is. The
5
- // newest are at the centre and the oldest at the rim, so looking further out
6
- // is looking further back. A lesson holds the cases it was drawn from close
7
- // around it. What comes to mind easily is bright and stands nearer to you;
8
- // what is fading lies lower and further. Nothing here is drawn that is not a
9
- // stored memory.
4
+ // you are carried in: every memory is there, and they are all around you.
5
+ // Not a galaxy looked at from outside, which is a picture of somebody else's
6
+ // sky: you stand near the middle of your own, and there are stars in every
7
+ // direction, also behind you. The newest are nearest and the oldest furthest,
8
+ // so looking further out is looking further back, whichever way you look, as
9
+ // it is in the real sky. A lesson holds the cases it was drawn from close
10
+ // around it. What comes to mind easily is bright; what is fading is faint.
11
+ // Pulled far enough back, the whole of it is seen at once, as a ball of stars.
12
+ // Nothing here is drawn that is not a stored memory.
10
13
  let spaceOn = false,
11
14
  space = 0,
12
15
  spaceFrom = 0,
@@ -86,30 +89,36 @@ let cam = { x: 0, y: 0, z: 0, k: 1, q: FLAT },
86
89
  const NEAREST = 2.8;
87
90
  const EASE = (x) => (x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2),
88
91
  OUT = (x) => 1 - Math.pow(1 - x, 4),
89
- SPACING = 44,
92
+ // How far apart neighbours stand, and how far from the middle the nearest ring begins: each memory has the same room about it, however many there are.
93
+ SPACING = 96,
94
+ CLEAR = 60,
90
95
  GLIDE = 1500,
91
- FOCAL = 900,
92
- TIP = 0.98,
93
- UPRIGHT = qabout(1, 0, 0, TIP);
96
+ // The eye is wide: standing among stars, a narrow eye sees a handful ahead and none of the ones going past.
97
+ FOCAL = 600,
98
+ UPRIGHT = FLAT;
94
99
  const sky = () => (space > 0 && all.size ? all : stars),
95
100
  quiet = () => (space > 0 ? calm : still);
96
101
  // Where each memory stands in that sky.
97
102
  const chart = (map) => {
98
- // The first star (the memory of being woken and named) is the pole of this sky: it stands at the middle, a little above the plane, and the rest are laid out around it.
103
+ // The first star (the memory of being woken and named) is the middle of this sky: everything since has gathered around it.
99
104
  const pole = [...map.values()].find((m) => m.first);
100
105
  if (pole) {
101
106
  pole.wx = 0;
102
107
  pole.wy = 0;
103
- pole.wz = 70;
108
+ pole.wz = 0;
104
109
  pole.ph = 0;
105
110
  }
111
+ // Around it in every direction, the newest nearest. The direction is the memory's own (from its id) and is even over the whole ball;
112
+ // how far out is its place in time, by the cube root, so that the stars are as thick far out as near.
106
113
  const list = [...map.values()].filter((m) => m !== pole).sort((a, b) => (b.at ?? 0) - (a.at ?? 0));
107
114
  list.forEach((m, n) => {
108
- const r = SPACING * Math.sqrt(n + 0.5),
115
+ const r = CLEAR + SPACING * Math.cbrt(n + 0.5),
116
+ up = 2 * hash(m.id, 7) - 1,
117
+ flat = Math.sqrt(1 - up * up),
109
118
  a = hash(m.id, 3) * 6.2832;
110
- m.wx = Math.cos(a) * r;
111
- m.wy = Math.sin(a) * r;
112
- m.wz = (m.strength - 0.42) * 230 + (hash(m.id, 7) - 0.5) * 70;
119
+ m.wx = Math.cos(a) * flat * r;
120
+ m.wy = Math.sin(a) * flat * r;
121
+ m.wz = up * r;
113
122
  m.ph = hash(m.id, 5) * 6.2832;
114
123
  });
115
124
  // A case stands by its lesson: the first lesson that was drawn from it.
@@ -121,12 +130,14 @@ const chart = (map) => {
121
130
  if (!c || c.kind === "lesson" || held.has(id)) continue;
122
131
  held.add(id);
123
132
  const a = hash(id, 4) * 6.2832,
124
- d = 34 + 46 * hash(id, 6);
125
- c.wx = m.wx + Math.cos(a) * d;
126
- c.wy = m.wy + Math.sin(a) * d;
127
- c.wz = m.wz + (hash(id, 8) - 0.5) * 60;
133
+ up = 2 * hash(id, 8) - 1,
134
+ flat = Math.sqrt(1 - up * up),
135
+ d = 30 + 34 * hash(id, 6);
136
+ c.wx = m.wx + Math.cos(a) * flat * d;
137
+ c.wy = m.wy + Math.sin(a) * flat * d;
138
+ c.wz = m.wz + up * d;
128
139
  }
129
- rim = SPACING * Math.sqrt(list.length + 1) + 90;
140
+ rim = CLEAR + SPACING * Math.cbrt(list.length + 1) + 60;
130
141
  };
131
142
  const loadAll = async () => {
132
143
  try {
@@ -136,6 +147,11 @@ const loadAll = async () => {
136
147
  chart(next);
137
148
  regather(next);
138
149
  all = next;
150
+ // The whole sky is larger than the part of it behind the conversation: where the eye is set down is taken from the whole, unless a hand has already moved it.
151
+ if (spaceOn && touched === spaceT0) {
152
+ if (flight) flight.to.k = setDown();
153
+ else cam.k = setDown();
154
+ }
139
155
  if (gather) lay();
140
156
  if (!found) $("spacecount").textContent = say("brainSpaceCount", { n: next.size });
141
157
  kick();
@@ -144,6 +160,14 @@ const loadAll = async () => {
144
160
  }
145
161
  };
146
162
  const lowest = () => Math.min(1, (Math.min(innerWidth, innerHeight) * 0.46) / rim);
163
+ // How near the eye is set down on coming in. A sky of a few hundred memories is stood inside: a little under half way from the middle to the edge.
164
+ // A young sky is too thin to stand in (a few points and a great deal of dark), so it is met from just outside, all of it ahead, and one walks in.
165
+ // It grows around whoever keeps it: with every memory the place one is set down is further in.
166
+ const setDown = () => {
167
+ const n = (all.size || stars.size) - 1,
168
+ out = Math.min(1.45, Math.max(0.45, 1.45 - n / 420));
169
+ return Math.min(NEAREST, Math.max(lowest(), FOCAL / (out * rim)));
170
+ };
147
171
  const hold = (c) => {
148
172
  const far = rim + 200,
149
173
  x = c.x ?? cam.x,
@@ -271,10 +295,10 @@ const enterSpace = () => {
271
295
  $("find").value = "";
272
296
  touched = spaceT0;
273
297
  chart(stars);
274
- const near = SPACING * Math.sqrt(Math.min(stars.size || 1, 220) + 1) + 60,
275
- k = Math.min(1.25, Math.max(lowest(), (Math.min(innerWidth, innerHeight) * 0.5) / near));
276
- // Carried in: from flat and far, turning, to tipped and near.
277
- cam = { x: 0, y: 0, z: 0, k: k * 0.5, q: qabout(0, 0, 1, -0.7) };
298
+ // Where you are set down: inside, a little under half way from the middle to the edge, looking at the middle. From there the newest are close about you and the rest go on behind them in every direction, and behind you.
299
+ const k = setDown();
300
+ // Carried in: from outside and turning, to inside.
301
+ cam = { x: 0, y: 0, z: 0, k: Math.max(lowest(), k * 0.35), q: qabout(0, 0, 1, -0.7) };
278
302
  aim = null;
279
303
  anchor = null;
280
304
  glide = null;
@@ -343,7 +367,9 @@ const zoomAt = (px, py, k) => {
343
367
  aim = null;
344
368
  kick();
345
369
  };
346
- const flyTo = (id) => {
370
+ // To a star. `beside` is for a star whose memory is being opened: on a wide screen the sheet covers the right of the sky, so the star is brought to the middle
371
+ // of what is left, not to the middle of the screen, where the sheet's edge would lie across it.
372
+ const flyTo = (id, beside = false) => {
347
373
  const s = all.get(id) ?? stars.get(id);
348
374
  unpoint();
349
375
  touched = performance.now();
@@ -351,16 +377,20 @@ const flyTo = (id) => {
351
377
  anchor = null;
352
378
  glide = null;
353
379
  spin = null;
380
+ const k = Math.max(cam.k, 1.7),
381
+ rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16,
382
+ aside = beside && innerWidth >= 70 * rem ? Math.min(25 * rem, innerWidth) / 2 / k : 0,
383
+ m = view.m;
354
384
  flight = {
355
385
  from: { ...cam },
356
- to: hold({ ...cam, x: s.wx, y: s.wy, z: s.wz, k: Math.max(cam.k, 1.7) }),
386
+ to: hold({ ...cam, x: s.wx + m[0] * aside, y: s.wy + m[1] * aside, z: s.wz + m[2] * aside, k }),
357
387
  t0: performance.now(),
358
388
  ms: calm ? 1 : 900,
359
389
  };
360
390
  kick();
361
391
  }
362
392
  };
363
- // Put the sky the right way up again: tipped as it was when you came in, facing as near as may be the way it faces now, and looking at the plane.
393
+ // Back to where you were set down: at the middle, facing the way you faced when you came in.
364
394
  const upright = () => {
365
395
  unpoint();
366
396
  touched = performance.now();
@@ -370,15 +400,15 @@ const upright = () => {
370
400
  aim = null;
371
401
  flight = {
372
402
  from: { ...cam },
373
- to: hold({ ...cam, z: 0, q: qmul(UPRIGHT, qabout(0, 0, 1, heading(cam.q))) }),
403
+ to: hold({ ...cam, x: 0, y: 0, z: 0, q: UPRIGHT }),
374
404
  t0: performance.now(),
375
405
  ms: calm ? 1 : 800,
376
406
  };
377
407
  kick();
378
408
  };
379
409
  const askew = () => {
380
- const m = view.m;
381
- return cam.z * cam.z > 900 || m[5] * -Math.sin(TIP) + m[8] * Math.cos(TIP) < 0.975 || Math.abs(m[2]) > 0.12;
410
+ // Away from the middle, or turned well away from how you came in: only then is there anything to go back to.
411
+ return Math.hypot(cam.x, cam.y, cam.z) > 60 || view.m[8] < 0.8;
382
412
  };
383
413
  // A soft light for the brighter stars, made once for each colour the page is in.
384
414
  const SHADES = 10,
@@ -749,8 +779,9 @@ const draw = (t = performance.now()) => {
749
779
  (skyHush && !s.first ? 1 - skyHush : 1) *
750
780
  (s.gw ? 1 - s.gw + s.gw * rowLight(s.go) : wheel.veil ? clearOf(p.x, p.y) : 1);
751
781
  // Near things are larger and clear, far ones small and faint.
752
- const near = Math.min(2.4, Math.max(0.4, 1 / p.far)),
753
- haze = Math.min(1, Math.max(0.16, 1.55 - 0.6 * p.far));
782
+ // Far ones do not go out: from inside, most of the sky is far, and a sky is its far stars.
783
+ const near = Math.min(2.4, Math.max(0.5, 1 / Math.sqrt(p.far))),
784
+ haze = Math.min(1, Math.max(0.34, 1.3 - 0.3 * p.far));
754
785
  const twinkle = e && !hush ? 1 - 0.24 * e * (0.5 + 0.5 * Math.sin(t * 0.0017 + s.ph)) : 1;
755
786
  const r =
756
787
  (1.1 + 2.1 * s.strength) *
@@ -1108,6 +1139,8 @@ addEventListener("click", (e) => {
1108
1139
  if (hover && !e.target.closest(BUSY)) {
1109
1140
  tip.classList.remove("on");
1110
1141
  gatherShow(hover);
1142
+ // The star that was chosen comes to you as its memory opens.
1143
+ if (spaceOn && !gather) flyTo(hover, true);
1111
1144
  void openMemory(hover);
1112
1145
  }
1113
1146
  });
@@ -178,6 +178,17 @@ const seenMark = (id, at) => {
178
178
  );
179
179
  };
180
180
  document.addEventListener("visibilitychange", tellSeen);
181
+ // That the user is in front of the conversation is said when they come to it: on opening it, on turning back to it. Not more than once a minute; what it means is Asteme's to decide.
182
+ let hereTold = 0;
183
+ const tellHere = () => {
184
+ if (document.hidden || Date.now() - hereTold < 60000) return;
185
+ hereTold = Date.now();
186
+ void post("/api/here", {}).catch(() => {
187
+ hereTold = 0;
188
+ });
189
+ };
190
+ document.addEventListener("visibilitychange", tellHere);
191
+ addEventListener("focus", tellHere);
181
192
  addEventListener("resize", tellSeen);
182
193
  // The signs to choose from close when anything else is touched, or on Escape.
183
194
  const signsShut = (but) => {
@@ -587,7 +587,23 @@ const openActivity = async () => {
587
587
  } catch (e) {
588
588
  return problem(e.message);
589
589
  }
590
- const quiet = !a.tasks.length && !a.intentions.length && !a.unread;
590
+ const kept = a.held ?? [],
591
+ quiet = !a.tasks.length && !a.intentions.length && !kept.length && !a.unread;
592
+ // What it set a time for and what it keeps for when the user is next here are taken back the same way.
593
+ const takeBack = (id) =>
594
+ button(
595
+ say("brainUnwake"),
596
+ async () => {
597
+ try {
598
+ await post("/api/unwake", { id });
599
+ await load();
600
+ await openActivity();
601
+ } catch (e) {
602
+ problem(e.message);
603
+ }
604
+ },
605
+ "bare muted",
606
+ );
591
607
  sheet(say("brainDoing"), [
592
608
  el("p", "big", say("brainState_" + a.state)),
593
609
  quiet ? el("p", "muted", say("brainQuiet")) : null,
@@ -603,22 +619,19 @@ const openActivity = async () => {
603
619
  words = el("div");
604
620
  words.append(el("b", null, (i.every ? say("brainEvery_" + i.every) + " · " : "") + time(i.at)), el("span", null, i.why));
605
621
  // Taking one back does not unsay it: the line under the words it was said with stays.
606
- row.append(
607
- words,
608
- button(
609
- say("brainUnwake"),
610
- async () => {
611
- try {
612
- await post("/api/unwake", { id: i.id });
613
- await load();
614
- await openActivity();
615
- } catch (e) {
616
- problem(e.message);
617
- }
618
- },
619
- "bare muted",
620
- ),
621
- );
622
+ row.append(words, takeBack(i.id));
623
+ return row;
624
+ }),
625
+ ]
626
+ : []),
627
+ ...(kept.length
628
+ ? [
629
+ el("h3", null, say("brainHeld")),
630
+ ...kept.map((h) => {
631
+ const row = el("div", "vowrow"),
632
+ words = el("div");
633
+ words.append(el("b", null, when(h.at)), el("span", null, h.about));
634
+ row.append(words, takeBack(h.id));
622
635
  return row;
623
636
  }),
624
637
  ]
@@ -676,6 +689,74 @@ const post = async (path, body) => {
676
689
  return v;
677
690
  };
678
691
  // Several things often change at once (a reply, what was learned from it, a time it set): the state is read once for them, a moment after the first, and never twice at the same time.
692
+ // What was on the page does not jump to its new place: it is carried there, and what has just arrived rises in with it. A person follows a thing that moves;
693
+ // a thing that is suddenly somewhere else has to be found again.
694
+ //
695
+ // How: where the last thing said stands in the page is kept. When the conversation's rows change, or the page is put at its end, that row is somewhere else;
696
+ // the conversation is set back by exactly that much in the same instant (`off`), and `off` then runs down to nothing, a share of what is left at each frame.
697
+ // A second change while the first is still on its way adds to what is left: there is one quantity, so nothing starts again and nothing goes backward.
698
+ // Anything else that moves the row (a hand scrolling, the window or the box below changing size) is not carried: the place kept is brought up to date.
699
+ //
700
+ // Three things this is built to avoid, each seen on the painted frames of an earlier version, where the page shook:
701
+ // an animation begun late in a frame shows one frame at the new place first; a carrying begun again from the start slows and jerks; and a conversation set back
702
+ // downward reaches below the end of the page while it travels, so the end measured then is too low and the page has to come back up. So `off` is this code's own
703
+ // number set by style, it is never started again, and it is taken off for the instant in which the page is measured or put at its end.
704
+ // Not where the device asks for less movement, not while the page is first filled, and not for a move of most of a screen.
705
+ let stoodAt = null,
706
+ off = 0,
707
+ carrying = 0,
708
+ carriedAt = 0;
709
+ const setBack = () => {
710
+ thread.style.transform = Math.abs(off) > 0.5 ? `translateY(${off.toFixed(2)}px)` : "";
711
+ };
712
+ const settleStep = (t) => {
713
+ // A frame's own time can be a little before the moment the carrying was begun in: never run it backward.
714
+ off *= Math.exp(-Math.max(0, Math.min(50, t - carriedAt)) / 85);
715
+ carriedAt = t;
716
+ if (Math.abs(off) <= 0.5) off = 0;
717
+ setBack();
718
+ carrying = off ? requestAnimationFrame(settleStep) : 0;
719
+ };
720
+ // The row whose place is kept is the topmost one in view. When something is added at the end, everything in view moves by the same amount and any row would do.
721
+ // When something changes in the middle (the "seen" line going from one message to a later one), what is above it stays where it is, and carrying the whole
722
+ // conversation by what a lower row moved would shake the upper ones. Found by halving, so a long conversation costs a dozen looks, not one for every row.
723
+ const standing = () => {
724
+ const rows = thread.children,
725
+ edge = scroller.getBoundingClientRect().top;
726
+ let lo = 0,
727
+ hi = rows.length - 1;
728
+ while (lo < hi) {
729
+ const mid = (lo + hi) >> 1;
730
+ if (rows[mid].getBoundingClientRect().bottom - off > edge + 1) hi = mid;
731
+ else lo = mid + 1;
732
+ }
733
+ const row = rows[lo];
734
+ stoodAt = row ? { row, top: row.getBoundingClientRect().top - off } : null;
735
+ };
736
+ const carry = (toEnd) => {
737
+ const row = stoodAt?.row.isConnected ? stoodAt.row : null;
738
+ thread.style.transform = "";
739
+ if (toEnd === true) scroller.scrollTop = scroller.scrollHeight;
740
+ if (row) {
741
+ const moved = stoodAt.top - row.getBoundingClientRect().top;
742
+ if (Math.abs(moved) > 1) off = !calm && loaded && Math.abs(off + moved) < innerHeight * 0.8 ? off + moved : 0;
743
+ }
744
+ setBack();
745
+ standing();
746
+ if (off && !carrying) {
747
+ carriedAt = performance.now();
748
+ carrying = requestAnimationFrame(settleStep);
749
+ }
750
+ };
751
+ carryNow = carry;
752
+ new MutationObserver(carry).observe(thread, { childList: true, subtree: true, characterData: true });
753
+ scroller.addEventListener("scroll", standing, { passive: true });
754
+ addEventListener("resize", standing);
755
+ if (typeof ResizeObserver !== "undefined") {
756
+ const sized = new ResizeObserver(standing);
757
+ sized.observe(scroller);
758
+ sized.observe(thread);
759
+ }
679
760
  // Whether the newest is kept in view. It is where the reader last left the conversation (at its end, or further back), and saying something brings them to the end.
680
761
  // It is not worked out when something arrives: what arrives is often drawn a moment later, and by then the reader may have gone back to read.
681
762
  let follow = true;
@@ -776,6 +857,7 @@ const load = async () => {
776
857
  loaded = true;
777
858
  paint();
778
859
  tellSeen();
860
+ tellHere();
779
861
  wasBorn = s.born !== false;
780
862
  if (s.stale && !toldStale) {
781
863
  toldStale = true;
@@ -941,7 +1023,8 @@ const listen = () => {
941
1023
  };
942
1024
  };
943
1025
  const newest = $("newest"),
944
- away = () => scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight > 80;
1026
+ // How far the page is from its end, not counting what the conversation reaches below it while it is being carried there.
1027
+ away = () => scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight - Math.max(0, off) > 80;
945
1028
  const browse = () => {
946
1029
  const on = away();
947
1030
  follow = !on;