clavarium 0.2.466-next.1 → 0.2.468-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.468-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.468-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.468-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/health.mjs CHANGED
@@ -31,6 +31,8 @@ import { SESSION } from './conversations.mjs';
31
31
  /* A FILE OUTSIDE /work where its tool may ask to be restarted when /work itself is dead (16-11): the
32
32
  one in its chat's folder (talk.mjs, RESTART_ASKED) cannot be written then. Read by the probe. */
33
33
  export const RESTART_OUTSIDE = '/var/tmp/clavarium-restart-asked';
34
+ /* The host of its tools, as pgrep -f reads it (the bracket: never the shell that asks). */
35
+ export const TOOLS_HOST_PATTERN = '/tools/launch/[t]ools-host.mjs';
34
36
  /* What a folder that came loose looks like on a terminal (the kernel's words for ENOTCONN). */
35
37
  const LOOSE_WORDS = 'transport endpoint is not connected|socket is not connected|ENOTCONN';
36
38
  /* A WORK FOLDER THE VM MANAGER CANNOT TAKE BACK (16-11, tried on a test server): its mount program died, multipass
@@ -60,6 +62,9 @@ export const PROBE = [
60
62
  `t=$(tmux -L ${SOCKET} list-panes -t '=${SESSION}:' -F '#{pane_pid}' 2>/dev/null | head -n 1)`,
61
63
  'case "$t" in ""|*[!0-9]*) ;; *) timeout 5 sh -c \'for p in $(ps -o pid= -s "$1" 2>/dev/null); do l=$(readlink "/proc/$p/cwd" 2>/dev/null) || continue; [ -n "$l" ] || continue; [ -d "/proc/$p/cwd/." ] || { echo "stale $p"; exit 0; }; done\' stale "$t";; esac',
62
64
  /* What its terminal shows now: a folder that is not connected, said by its tool (a symptom, not a proof). */
65
+ /* And the host of its tools (config/launch/tools-host.mjs: Parley, Docket... for its agent), started in its own
66
+ session from the tool's folder: left in a dead one, every tool it serves fails, the tool restarted or not. */
67
+ `for p in $(pgrep -f '${TOOLS_HOST_PATTERN}' 2>/dev/null); do [ -d "/proc/$p/cwd/." ] || { echo "stale $p"; break; }; done`,
63
68
  `tmux -L ${SOCKET} capture-pane -p -t '=${SESSION}:' 2>/dev/null | grep -c -i -E '${LOOSE_WORDS}' | awk '{print "screen", $1+0}'`,
64
69
  `if [ -f ${RESTART_OUTSIDE} ]; then echo "restart asked"; fi`,
65
70
  ].join('\n');
package/server/main.mjs CHANGED
@@ -59,7 +59,7 @@ import { GitChecks } from './gitchecks.mjs';
59
59
  import { GitKeeper } from './gitkeeper.mjs';
60
60
  import { GitRunner } from './gitrunner.mjs';
61
61
  import { Shelf } from './shelf.mjs';
62
- import { Health, RESTART_OUTSIDE } from './health.mjs';
62
+ import { Health, RESTART_OUTSIDE, TOOLS_HOST_PATTERN } from './health.mjs';
63
63
  import { Revive } from './revive.mjs';
64
64
  import { LinkGuard, removedLine, toolLine } from './linkguard.mjs';
65
65
  import { Setup } from './setup.mjs';
@@ -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);
@@ -617,7 +620,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
617
620
  /* ITS TOOL STILL IN A FOLDER THAT CAME LOOSE, or asking from outside /work (16-11, revive.mjs): restarted
618
621
  by the server, its tool only; told through its docket first (read as it starts), its chat after. */
619
622
  const revive = new Revive({
620
- restart: (name) => all.restartTool(name),
623
+ /* Its tools' host stopped first (it starts again at the tool's first tool, from the folder put back). */
624
+ restart: async (name) => { await vms.exec(name, ['sh', '-c', `for p in $(pgrep -f '${TOOLS_HOST_PATTERN}'); do kill "$p"; done; true`], { timeoutMs: 10_000 }).catch(() => {}); return all.restartTool(name); },
621
625
  restartMachine: async (name) => { const r = await all.machineAction(name, 'restart', { wait: true }); return r?.ok !== false; },
622
626
  busy: (name) => talk.pulse(name)?.busy === true,
623
627
  taken: (name) => vms.exec(name, ['rm', '-f', RESTART_OUTSIDE], { timeoutMs: 10_000 }),
@@ -866,6 +870,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
866
870
  wake: (name) => {
867
871
  const c = all.get(name);
868
872
  if (c?.phase !== 'ready') throw new Refusal(409, 'This conversation is not ready.');
873
+ if (c.asleep === true || c.stopped === true) wakeWhy.set(name, 'a key (API)');
869
874
  void bridge?.warm(name);
870
875
  return { state: c.asleep === true ? 'waking' : 'awake' };
871
876
  },
@@ -921,8 +926,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
921
926
  /* Put to sleep or stopped: a page that comes back by itself does not wake it (bridge.mjs, CLOSE_ASLEEP). */
922
927
  asleep: (name) => { const c = all.get(name); return c?.asleep === true || c?.stopped === true; },
923
928
  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);
929
+ spawn: async (name, cols, rows, say, who) => {
930
+ const [program, ...argv] = await all.open(name, say, who ?? wakeWhy.take(name));
926
931
  const started = pty.spawn(program, argv, { name: 'xterm-256color', env: withoutTmux(env), cols, rows });
927
932
  /* Its start is over once something is drawn (nothing of it is
928
933
  read), once it ends, or after a while whatever happens. Not