clavarium 0.2.466-next.1 → 0.2.467-next.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.466-next.1",
3
+ "version": "0.2.467-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.466-next.1",
9
+ "version": "0.2.467-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.466-next.1",
3
+ "version": "0.2.467-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/bridge.mjs CHANGED
@@ -185,7 +185,9 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
185
185
  return run;
186
186
  }
187
187
  async function openNow(name, cols, rows, sink, say) {
188
- const terminal = await spawn(name, cols, rows, say);
188
+ /* Who opens it, for What happened when it wakes a sleeper: a screen, or this server (warm). */
189
+ const who = sink ? (deviceSeats.has(sink) ? 'a paired device' : 'a page') : undefined;
190
+ const terminal = await spawn(name, cols, rows, say, who);
189
191
  /* While it was being opened another one may have been: the newest wins. */
190
192
  if (live.has(name)) close(name);
191
193
  const kept = { terminal, sink, cols, rows, openedAt: Date.now(), outputAt: Date.now() };
@@ -163,6 +163,9 @@ export class Conversations {
163
163
  /* Set by the server: its wake-ups, for a whole export; and on its import, when asked, its reminders (from the
164
164
  export's work folder) and those wake-ups given again (15-11, as a copy does). */
165
165
  wakeupsOf = () => undefined;
166
+ /* Set by the server: a machine put to sleep or stopped, woken by an opening -- `by` who (16-11: a sleeper found
167
+ awake in the morning, and nothing said who woke it). Said in What happened. */
168
+ woken = () => {};
166
169
  importReminders = async () => {};
167
170
 
168
171
  /* `uid`/`gid`: the account this server runs as; files the tool writes in
@@ -560,7 +563,7 @@ export class Conversations {
560
563
  }
561
564
 
562
565
  /* What a terminal must run to reach this conversation. Wakes the VM first. */
563
- async open(name, say = () => {}) {
566
+ async open(name, say = () => {}, by = 'the server') {
564
567
  const c = this.#store.get(name);
565
568
  if (!c) throw new Refusal(404, 'No such conversation.');
566
569
  if (c.phase !== 'ready') throw new Refusal(409, c.phase === 'building' ? 'This conversation is still being built.' : c.phase === 'moving' ? 'This conversation is moving its work folder.' : 'This conversation could not be built.');
@@ -571,6 +574,7 @@ export class Conversations {
571
574
  /* Opening is the explicit gesture that ends a sleep, or a stop its owner asked for. */
572
575
  if (c.asleep) this.#store.patch(name, { asleep: false });
573
576
  if (c.stopped) this.#store.patch(name, { stopped: undefined });
577
+ if (c.asleep || c.stopped) { try { this.woken(name, by, c.asleep ? 'asleep' : 'stopped'); } catch { /* said, nothing more */ } }
574
578
  this.#watching.set(name, (this.#watching.get(name) ?? 0) + 1);
575
579
  /* Another screen is applying the size kept for its wake: this one opens once it is over. */
576
580
  await this.#resizing.get(name)?.catch(() => {});
package/server/main.mjs CHANGED
@@ -483,7 +483,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
483
483
  /* A sign-in a companion did for another conversation (signinhelp.mjs, made below): its answer typed there. */
484
484
  acked: (name, e) => signinHelp?.acked(name, e) });
485
485
  const typingWatch = new TypingWatch();
486
- const wakeups = new Wakeups({ store: new Store(`${dataDir}/wakeups.json`), vms, conversations: all, resources: folders, warm: (name) => bridge?.warm(name), docket: dockets, typing: (name) => typingWatch.busy(name),
486
+ /* WHO WOKE IT (16-11): this server opens a terminal for others (a wake-up, a key); said once it wakes one. */
487
+ const wakeWhy = { why: new Map(), set(name, by) { this.why.set(name, by); }, take(name) { const by = this.why.get(name); this.why.delete(name); return by ?? 'the server'; } };
488
+ all.woken = (name, by, was) => events.add({ kind: 'machine', text: `Machine of ${name}: woken by ${by} (it was ${was})`, conversation: name });
489
+ const wakeups = new Wakeups({ store: new Store(`${dataDir}/wakeups.json`), vms, conversations: all, resources: folders, warm: (name) => { if (!all.awake().includes(name)) wakeWhy.set(name, 'its wake-up'); return bridge?.warm(name); }, docket: dockets, typing: (name) => typingWatch.busy(name),
487
490
  fired: (name, { text }) => talk.event(name, { kind: 'wakeup', text, topic: 'Wake-up' }) });
488
491
  const wakeTimer = wakeups.start(wakeEveryMs);
489
492
  const docketTimer = dockets.start(wakeEveryMs);
@@ -866,6 +869,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
866
869
  wake: (name) => {
867
870
  const c = all.get(name);
868
871
  if (c?.phase !== 'ready') throw new Refusal(409, 'This conversation is not ready.');
872
+ if (c.asleep === true || c.stopped === true) wakeWhy.set(name, 'a key (API)');
869
873
  void bridge?.warm(name);
870
874
  return { state: c.asleep === true ? 'waking' : 'awake' };
871
875
  },
@@ -921,8 +925,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
921
925
  /* Put to sleep or stopped: a page that comes back by itself does not wake it (bridge.mjs, CLOSE_ASLEEP). */
922
926
  asleep: (name) => { const c = all.get(name); return c?.asleep === true || c?.stopped === true; },
923
927
  onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
924
- spawn: async (name, cols, rows, say) => {
925
- const [program, ...argv] = await all.open(name, say);
928
+ spawn: async (name, cols, rows, say, who) => {
929
+ const [program, ...argv] = await all.open(name, say, who ?? wakeWhy.take(name));
926
930
  const started = pty.spawn(program, argv, { name: 'xterm-256color', env: withoutTmux(env), cols, rows });
927
931
  /* Its start is over once something is drawn (nothing of it is
928
932
  read), once it ends, or after a while whatever happens. Not