clavarium 0.2.25 → 0.2.26

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.25",
3
+ "version": "0.2.26",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.25",
9
+ "version": "0.2.26",
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.25",
3
+ "version": "0.2.26",
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/main.mjs CHANGED
@@ -39,7 +39,7 @@ import { Network } from './network.mjs';
39
39
  import { Answerer, answererConfig } from './answerer.mjs';
40
40
  import { Dockets } from './dockets.mjs';
41
41
  import { PULSE_MS } from 'clavarium-parley/ui';
42
- import { Wakeups, CALL_PATH } from './wakeups.mjs';
42
+ import { Wakeups, TypingWatch, CALL_PATH } from './wakeups.mjs';
43
43
  import { Alerts } from './alerts.mjs';
44
44
  import { Talk } from './talk.mjs';
45
45
  import { Toolbox } from './toolbox.mjs';
@@ -387,7 +387,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
387
387
  /* Not in a turn: its pulse ended, or is old (Parley's own measure). */
388
388
  idle: (name) => { const p = talk.pulse(name); return !(p?.busy === true && Date.now() - Date.parse(p.at) < PULSE_MS); },
389
389
  awake: () => all.awake(), chatOn: (name) => talk.isOn(name) });
390
- const wakeups = new Wakeups({ store: new Store(`${dataDir}/wakeups.json`), vms, conversations: all, resources: folders, warm: (name) => bridge?.warm(name), docket: dockets,
390
+ const typingWatch = new TypingWatch();
391
+ 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),
391
392
  fired: (name, { text }) => talk.event(name, { kind: 'wakeup', text, topic: 'Wake-up' }) });
392
393
  const wakeTimer = wakeups.start(wakeEveryMs);
393
394
  const docketTimer = dockets.start(wakeEveryMs);
@@ -499,7 +500,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
499
500
  let closing = false;
500
501
  bridge = attachBridge(server, {
501
502
  onRejoin: (name) => all.rejoin(name),
502
- onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); },
503
+ onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
503
504
  spawn: async (name, cols, rows, say) => {
504
505
  const [program, ...argv] = await all.open(name, say);
505
506
  const started = pty.spawn(program, argv, { name: 'xterm-256color', env: withoutTmux(env), cols, rows });
@@ -97,6 +97,22 @@ export function cron(line) {
97
97
  && (anyDay && anyWeekday ? true : anyDay ? weekday.has(date.getDay()) : anyWeekday ? day.has(date.getDate()) : day.has(date.getDate()) || weekday.has(date.getDay()));
98
98
  }
99
99
  const PANE = `=${SESSION}:`;
100
+ const HOLD_STEP_MS = 1000;
101
+ const HOLD_MAX_MS = 5 * 60_000;
102
+
103
+ /* WHO IS TYPING IN A TERMINAL, from what screens send (bridge.mjs onTyped).
104
+ Busy: a key in the last seconds, or a line begun and not yet sent
105
+ (Enter, Ctrl-C, Ctrl-U end it) -- held so for a few minutes at most. */
106
+ export class TypingWatch {
107
+ #at = new Map(); #now;
108
+ constructor({ now = () => Date.now(), quietMs = 2000, openMs = HOLD_MAX_MS } = {}) { this.#now = now; this.quietMs = quietMs; this.openMs = openMs; }
109
+ typed(name, data) { this.#at.set(name, { at: this.#now(), open: !/[\r\n\x03\x15]$/.test(String(data ?? '')) }); }
110
+ busy(name) {
111
+ const t = this.#at.get(name); if (!t) return false;
112
+ const since = this.#now() - t.at;
113
+ return since < this.quietMs || (t.open && since < this.openMs);
114
+ }
115
+ }
100
116
  /* How new commits are named among what arrived. */
101
117
  export const COMMITS = 'new commits';
102
118
 
@@ -134,19 +150,22 @@ const FIRED_SHOWN = 120;
134
150
  const sameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
135
151
 
136
152
  export class Wakeups {
137
- #store; #vms; #conversations; #resources; #warm; #now; #fired; #docket; #held = new Map(); #busy = false;
153
+ #store; #vms; #conversations; #resources; #warm; #now; #fired; #docket; #typing; #pause; #held = new Map(); #busy = false;
138
154
 
139
155
  /* `warm(name)`: opens the terminal of a machine that runs, if it is not open.
140
156
  `fired(name, { text, item })`: a wake-up was typed (its chat says so: Talk.event). */
141
157
  /* `docket`: { on(name), post(name, {kind, text, data}) } (dockets.mjs), or none: typed always. */
142
- constructor({ store, vms, conversations, resources, warm = async () => {}, now = () => new Date(), fired = () => {}, docket = null }) {
158
+ /* `typing(name)`: someone is typing in its terminal from a screen (see TypingWatch): a line is held until it is free. */
159
+ constructor({ store, vms, conversations, resources, warm = async () => {}, now = () => new Date(), fired = () => {}, docket = null, typing = () => false, pause = (ms) => new Promise((ok) => setTimeout(ok, ms)) }) {
143
160
  this.#store = store; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#warm = warm; this.#now = now; this.#fired = fired; this.#docket = docket;
161
+ this.#typing = typing; this.#pause = pause;
144
162
  }
145
163
  /* Where its chat is on, posted to its docket (told at its next tick); else typed. Resolves with what to say of it, and whether it went. */
146
164
  async #deliver(name, item, text) {
147
165
  if (this.#docket?.on(name)) {
148
166
  try { this.#docket.post(name, { kind: item.kind, text, data: { wakeup: item.id } }); return { ok: true, what: `Posted to its docket: ${text}` }; } catch { /* its folder: typed instead */ }
149
167
  }
168
+ await this.#free(name);
150
169
  const typed = await this.#type(name, text).catch(() => false);
151
170
  return { ok: typed, what: typed ? `Typed: ${text}` : 'Could not be typed: is its tool running?' };
152
171
  }
@@ -269,6 +288,11 @@ export class Wakeups {
269
288
  return withFiles(item.message, arrived);
270
289
  }
271
290
 
291
+ /* Typed into a command being typed, both were broken (seen 24-10): wait for the line to be free, a while at most. */
292
+ async #free(name) {
293
+ for (const start = this.#now().getTime(); this.#typing(name) && this.#now().getTime() - start < HOLD_MAX_MS;) await this.#pause(HOLD_STEP_MS);
294
+ }
295
+
272
296
  async #type(name, text) {
273
297
  await this.#warm(name);
274
298
  const tmux = ['tmux', '-L', SOCKET, 'send-keys', '-t', PANE];
@@ -286,7 +310,7 @@ export class Wakeups {
286
310
  async say(name, text) {
287
311
  if (!this.#conversations.awake().includes(name)) return false;
288
312
  const before = this.#queue.get(name) ?? Promise.resolve();
289
- const mine = before.then(() => this.#type(name, cleanMessage(text)).catch(() => false));
313
+ const mine = before.then(() => this.#free(name)).then(() => this.#type(name, cleanMessage(text)).catch(() => false));
290
314
  this.#queue.set(name, mine);
291
315
  void mine.finally(() => { if (this.#queue.get(name) === mine) this.#queue.delete(name); });
292
316
  return mine;
@@ -323,7 +347,8 @@ export class Wakeups {
323
347
  try {
324
348
  const awake = new Set(this.#conversations.awake());
325
349
  for (const record of this.#store.all()) {
326
- if (!awake.has(record.name)) continue;
350
+ /* Someone typing there: its wake-ups wait for the next tick, the others go on. */
351
+ if (!awake.has(record.name) || (this.#typing(record.name) && !this.#docket?.on(record.name))) continue;
327
352
  for (const item of record.items.filter((i) => i.on)) {
328
353
  let text;
329
354
  try { text = this.#due(record.name, item); } catch { text = undefined; }
package/web/app.js CHANGED
@@ -333,22 +333,30 @@
333
333
  let listFolded = false;
334
334
  try { listFolded = localStorage.getItem('clavarium-list') === 'folded'; } catch { /* a private window */ }
335
335
  /* THE LIST SLIDES, THE PAGE IS LAID OUT ONCE. Animating the grid's columns laid the whole page out (and
336
- redrew the terminal) at every frame: it stuttered. The list and the menu slide instead -- a transform,
337
- which costs nothing -- and the columns change once: after it slid out, or before it slides in. */
336
+ redrew the terminal) at every frame: it stuttered. The columns change once, the room taking the whole
337
+ width (its far side off the screen), and the list, the menu and the room slide -- transforms, which cost
338
+ nothing -- so nothing is left blank, and nothing jumps at the end. */
338
339
  const sliders = () => ['list', 'nav'].map((id) => $(id)).filter(Boolean);
339
- const slide = (out) => Promise.all(sliders().map((e) => e.animate(
340
- [{ transform: 'none', opacity: 1 }, { transform: 'translateX(-100%)', opacity: 0 }],
341
- { duration: 200, easing: 'ease', direction: out ? 'normal' : 'reverse' }).finished.catch(() => {})));
340
+ const slide = (out, width) => {
341
+ const how = { duration: 200, easing: 'ease', direction: out ? 'normal' : 'reverse' };
342
+ const moving = sliders().map((e) => e.animate([{ transform: 'none' }, { transform: 'translateX(-100%)' }], how));
343
+ moving.push($('room').animate([{ transform: `translateX(${width}px)` }, { transform: 'none' }], how));
344
+ return Promise.all(moving.map((a) => a.finished.catch(() => {})));
345
+ };
342
346
  const still = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches || window.innerWidth <= 700;
343
347
  $('fold').addEventListener('click', async () => {
344
348
  listFolded = !listFolded;
345
349
  try { localStorage.setItem('clavarium-list', listFolded ? 'folded' : 'open'); } catch { /* as above */ }
346
350
  const folded = listFolded;
347
- if (!still() && folded) await slide(true);
351
+ if (still()) { applyFold(folded); fit.fit(); focusTerminal(); return; }
352
+ const width = $('list').getBoundingClientRect().width || $('list').offsetWidth;
353
+ app.classList.add('sliding');
354
+ if (folded) { applyFold(true); fit.fit(); }
355
+ await slide(folded, width);
356
+ app.classList.remove('sliding');
348
357
  if (listFolded !== folded) return;
349
- applyFold(folded);
350
- fit.fit(); focusTerminal();
351
- if (!still() && !folded) await slide(false);
358
+ if (!folded) { applyFold(false); fit.fit(); }
359
+ focusTerminal();
352
360
  });
353
361
 
354
362
  /* ---------- light or dark ---------- */
package/web/style.css CHANGED
@@ -113,6 +113,9 @@ footer button.wide { flex: 1 0 auto; background: var(--brass); border-color: var
113
113
  #app[data-list="folded"] { grid-template-columns: 0px minmax(0, 1fr); }
114
114
  #app :is(#list, #nav) { min-width: 0; overflow-x: hidden; }
115
115
  #app[data-list="folded"] :is(#list, #nav) { visibility: hidden; }
116
+ /* While it slides: the list keeps its width over the room, the room's far side off the screen. */
117
+ #app.sliding { overflow: hidden; }
118
+ #app.sliding :is(#list, #nav) { visibility: visible; width: var(--list-width, 260px); box-sizing: border-box; position: relative; z-index: 1; }
116
119
  }
117
120
  @media (max-width: 700px) { #fold { display: none; } }
118
121
  #fold { font-size: 1rem; line-height: 1; padding: 4px 9px; }