clavarium 0.2.330-next.1 → 0.2.332-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,19 +1,19 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.330-next.1",
3
+ "version": "0.2.332-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.330-next.1",
9
+ "version": "0.2.332-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
14
  "clavarium-binder": "0.1.60-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
- "clavarium-parley": "0.17.70-next.1",
16
+ "clavarium-parley": "0.17.71-next.1",
17
17
  "clavarium-tether": "0.1.0-next.53",
18
18
  "mammoth": "1.13.0",
19
19
  "mermaid": "11.17.2",
@@ -787,9 +787,9 @@
787
787
  }
788
788
  },
789
789
  "node_modules/clavarium-parley": {
790
- "version": "0.17.70-next.1",
791
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.70-next.1.tgz",
792
- "integrity": "sha512-DfoNmVWNt32vIXLjtV9Mtvzj6PgIVy+Up4AtJQ5rwtW+4z3988hSYZni4PwRW+yYtZ991WPE8mGg1r6iIvr9/w==",
790
+ "version": "0.17.71-next.1",
791
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.71-next.1.tgz",
792
+ "integrity": "sha512-98RGnKFb8sCl05HSzrWY7qCvlqBGY4wAL4kwNVKTO69d8F1x3++pLCHjyE8AXjKNNlt2BE5fCrxtbsu/BTsnLA==",
793
793
  "license": "MIT",
794
794
  "bin": {
795
795
  "parley": "bin/parley.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.330-next.1",
3
+ "version": "0.2.332-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.",
@@ -46,7 +46,7 @@
46
46
  "@xterm/xterm": "^6.0.0",
47
47
  "clavarium-binder": "0.1.60-next.1",
48
48
  "clavarium-docket": "0.1.2-next.2",
49
- "clavarium-parley": "0.17.70-next.1",
49
+ "clavarium-parley": "0.17.71-next.1",
50
50
  "clavarium-tether": "0.1.0-next.53",
51
51
  "mammoth": "1.13.0",
52
52
  "mermaid": "11.17.2",
package/server/boxes.mjs CHANGED
@@ -44,7 +44,9 @@ export const wakeHeard = (text) => { const t = plainWords(text); return WAKE_HEA
44
44
  the room's talk from afar, not someone speaking to the box. Every real call of 05-11 that the word missed
45
45
  had a firm voice or none measured; the false wake of 05-11, 429. Said by one discreet line in the thread. */
46
46
  export const WAKE_FAINT = 600;
47
- export const dropsWake = (ok, voice) => !ok && (WAKE_DROP || (Number.isFinite(voice) && voice > 0 && voice < WAKE_FAINT));
47
+ /* 06-11: a radio or a TV read a whole news flash after a false wake (120 s, cut by the length limit, no voice measured):
48
+ a sentence never ended is not someone speaking to the box -- not heard AND cut by the length limit is dropped too. */
49
+ export const dropsWake = (ok, voice, reason = '') => !ok && (WAKE_DROP || reason === 'timeout' || (Number.isFinite(voice) && voice > 0 && voice < WAKE_FAINT));
48
50
  const plainWords = (t) => String(t).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z\s]/g, ' ').replace(/\s+/g, ' ').trim();
49
51
  export const SENTENCE_MAX = 300 * 32_000 + 32_000; /* 5 min of 16 kHz 16-bit mono, and some slack */
50
52
  export const TRIES_PER_MINUTE = 10;
@@ -781,7 +783,7 @@ export class Boxes {
781
783
  this.#log(`voice box ${box.name}: a sentence while recording here, the recording closed`);
782
784
  r.out.end(() => { void this.#recorded(link, r); });
783
785
  }
784
- if (m.t === 'listen.start') { link.why = whyOf(m); link.wakeCheck = null; } /* its clip, if any, comes after listen.start: an older check never carries over */
786
+ if (m.t === 'listen.start') { link.why = whyOf(m); link.wakeCheck = null; link.voice = NaN; link.endReason = ''; } /* its clip, if any, comes after listen.start: an older check never carries over */
785
787
  if (m.t === 'listen.start') { if (this.stop(box.id)) this.#log(`voice box ${box.name}: stopped playing, someone speaks`); sentence = []; size = 0; return; }
786
788
  if (m.t === 'listen.end' && sentence && m.reason === 'nobody') {
787
789
  /* Listened again, nobody spoke: a conversation ends there, in silence. */
@@ -792,6 +794,8 @@ export class Boxes {
792
794
  link.send({ t: 'cue', name: 'done' });
793
795
  return;
794
796
  }
797
+ /* How this sentence ended, said with or without its measures (a radio cut at the length limit may have none). */
798
+ if (m.t === 'listen.end') link.endReason = String(m.reason ?? '');
795
799
  if (m.t === 'listen.end' && m.ep) {
796
800
  const end = endOf(m.ep, m.reason ?? '');
797
801
  link.why = `${link.why ? `${link.why} · ` : ''}${end}`;
@@ -919,10 +923,10 @@ export class Boxes {
919
923
  /* First in the line: Parley keeps 120 characters of `why`, and the end stats after it can pass that. */
920
924
  link.why = `mot ${check.ok ? '\u2713' : '\u2717'} « ${check.heard.slice(0, 30)} »${link.why ? ` · ${link.why}` : ''}`;
921
925
  this.#log(`voice box ${box.name}: wake word heard again: ${check.ok ? 'yes' : 'NO'} (« ${check.heard.slice(0, 40)} »)`);
922
- if (dropsWake(check.ok, link.voice)) {
926
+ if (dropsWake(check.ok, link.voice, link.endReason)) {
923
927
  link.send({ t: 'cue', name: 'done' });
924
- this.#log(`voice box ${box.name}: wake ignored (word not heard again, faint voice ${Math.round(link.voice || 0)})`);
925
- try { this.#note?.(box.conversation, { kind: 'box-wake-ignored', text: `Wake ignored on ${box.name}: « ${check.heard.slice(0, 40)} », faint voice`, topic: 'Voice box', tone: 'info' }); } catch { /* the log has it */ }
928
+ this.#log(`voice box ${box.name}: wake ignored (word not heard again, ${link.endReason === 'timeout' ? 'a sentence that never ended' : `faint voice ${Math.round(link.voice || 0)}`})`);
929
+ try { this.#note?.(box.conversation, { kind: 'box-wake-ignored', text: `Wake ignored on ${box.name}: « ${check.heard.slice(0, 40)} », ${link.endReason === 'timeout' ? 'a sound that never stopped (radio, TV)' : 'faint voice'}`, topic: 'Voice box', tone: 'info' }); } catch { /* the log has it */ }
926
930
  return;
927
931
  }
928
932
  }
package/server/talk.mjs CHANGED
@@ -179,6 +179,22 @@ const ACTIONS_MAX = 4;
179
179
  const ACTION = /^[a-z]{1,20}(:[a-z0-9][a-z0-9._-]{0,63})?$/;
180
180
  const REQUEST_MAX = 8000;
181
181
  const OUTCOMES = ['yes', 'always', 'no', 'timeout', 'withdrawn', 'stopped'];
182
+ /* A LINE'S TEXT IN THE READER'S WORDS (Parley 0.17.71): plain text, or `{k, v, t}` -- a word of Parley's
183
+ dictionary, its values (text, a number, or such a word again), and `t`, the plain English an older screen
184
+ says. Kept bounded: `t` as long as a plain text may be; a word without its `t` is none. */
185
+ const WORD = /^[a-z0-9-]{1,60}$/;
186
+ function lineWords(x, max, depth = 0) {
187
+ if (typeof x === 'string') { const t = x.trim(); return t ? t.slice(0, max) : null; }
188
+ if (typeof x === 'number') return Number.isFinite(x) ? x : null;
189
+ if (!x || typeof x !== 'object' || Array.isArray(x) || depth > 3 || typeof x.k !== 'string' || !WORD.test(x.k)) return null;
190
+ const t = typeof x.t === 'string' ? x.t.trim().slice(0, max) : '';
191
+ if (!t) return null;
192
+ const v = x.v && typeof x.v === 'object' && !Array.isArray(x.v)
193
+ ? Object.fromEntries(Object.entries(x.v).filter(([n]) => /^[a-z]{1,20}$/.test(n)).slice(0, 8).map(([n, y]) => [n, lineWords(y, EVENT_TEXT_MAX, depth + 1)]).filter(([, y]) => y !== null)) : null;
194
+ return { k: x.k, ...(v && Object.keys(v).length ? { v } : {}), t };
195
+ }
196
+ /* A line's text, topic or brief as given: text, or such a word; null when it says nothing. */
197
+ const lineSaid = (x, max) => lineWords(x && typeof x === 'object' ? x : String(x ?? ''), max);
182
198
  /* Where the person's files go, in the bridge folder; one folder per file, named by an id. */
183
199
  const FILES = 'files';
184
200
  const ATTACHED = new RegExp(`^/work/\\${FOLDER}/${FILES}/([0-9a-f-]{36})/([^/]+)$`);
@@ -581,18 +597,20 @@ export class Talk {
581
597
  line kept, or null. `actions`: ids the page maps to buttons. */
582
598
  event(name, { kind, text, level, tone, topic, brief, actions = [], request, outcome } = {}) {
583
599
  if (!Object.hasOwn(EVENT_LEVELS, kind)) throw new RangeError(`No such kind of event: ${kind}`);
584
- const said = String(text ?? '').trim();
585
- if (!said) return null;
600
+ const said = lineSaid(text, EVENT_TEXT_MAX);
601
+ if (said === null) return null;
602
+ const group = lineSaid(topic, TOPIC_MAX);
603
+ const short = lineSaid(brief, BRIEF_MAX);
586
604
  /* The owner's choice when there is one (stored only where it differs from the kind's own). */
587
605
  const chosen = this.thread().levels[kind];
588
606
  const line = {
589
607
  /* Not `kind`: the page reads that of every message ('system' for these). */
590
608
  event: kind,
591
- text: said.slice(0, EVENT_TEXT_MAX),
609
+ text: said,
592
610
  level: chosen !== EVENT_LEVELS[kind] ? chosen : LEVELS.includes(level) ? level : chosen,
593
611
  ...(TONES.includes(tone) ? { tone } : {}),
594
- ...(topic ? { topic: String(topic).slice(0, TOPIC_MAX) } : {}),
595
- ...(brief ? { brief: String(brief).slice(0, BRIEF_MAX) } : {}),
612
+ ...(group !== null ? { topic: group } : {}),
613
+ ...(short !== null ? { brief: short } : {}),
596
614
  actions: (Array.isArray(actions) ? actions : []).filter((a) => typeof a === 'string' && ACTION.test(a)).slice(0, ACTIONS_MAX),
597
615
  /* A request's card, as Parley draws it (demandes.mjs): plain data, bounded. */
598
616
  ...(request && typeof request === 'object' && !Array.isArray(request) && JSON.stringify(request).length <= REQUEST_MAX ? { request } : {}),
@@ -50,8 +50,41 @@ const NOTICE_HEADS = {
50
50
  };
51
51
  const NOTICE_INFO = /\.(delayed|later-late|sent-late)$/;
52
52
  export const noticeHead = (kind) => NOTICE_HEADS[kind] ?? 'Later news';
53
+ /* The same head as a word of Parley's (notice-mail-bounced...), said in the reader's language. */
54
+ export const noticeWord = (kind) => (Object.hasOwn(NOTICE_HEADS, kind) ? { k: `notice-${kind.replace(/\./g, '-')}`, t: NOTICE_HEADS[kind] } : { k: 'notice-later', t: 'Later news' });
53
55
  export const noticeWarns = (kind) => !NOTICE_INFO.test(String(kind ?? ''));
54
56
 
57
+ /* A LINE IN THE READER'S WORDS (Parley 0.17.71, as a request's card since 0.17.70, demandes.mjs): a word of
58
+ Parley's dictionary and its values, said by each screen in its own language; `t`, the plain English an
59
+ older screen says. Values that are data (a verb, a name, a reason, Tether's own sentence) stay as given. */
60
+ const said = (k, v, t) => ({ k, ...(v ? { v } : {}), t });
61
+ const TOPIC_REQUEST = Object.freeze({ k: 'line-topic-request', t: 'Request' });
62
+ const TOPIC_NOTICE = Object.freeze({ k: 'line-topic-notice', t: 'Later news' });
63
+ /* A call that ended without being done (not accepted): how it ended, by its outcome. */
64
+ const ENDED = {
65
+ no: ['line-refused', 'Refused'],
66
+ timeout: ['line-timeout', 'No answer in time'],
67
+ withdrawn: ['line-withdrawn', 'Withdrawn by the agent'],
68
+ stopped: ['line-stopped', 'Stopped'],
69
+ };
70
+ export function endedLine(verb, outcome) {
71
+ if (outcome === 'yes' || outcome === 'always') return said('line-accepted', { verb }, `Accepted: ${verb} — being done`);
72
+ const [k, head] = ENDED[outcome] ?? ['line-handled', 'Request handled'];
73
+ return said(k, { verb }, `${head}: ${verb}`);
74
+ }
75
+ export function resultLine(verb, error) {
76
+ if (error === undefined) return said('line-done', { verb }, `Done: ${verb}`);
77
+ const reason = String(error ?? '').trim();
78
+ return reason ? said('line-failed', { verb, reason }, `Failed: ${verb} — ${reason}`) : said('line-failed-plain', { verb }, `Failed: ${verb}`);
79
+ }
80
+ export function noticeLine(kind, target, text) {
81
+ const head = noticeWord(kind);
82
+ if (target && text) return said('line-notice', { head, target, text }, `${head.t} (${target}): ${text}`);
83
+ if (text) return said('line-notice-said', { head, text }, `${head.t}: ${text}`);
84
+ if (target) return said('line-notice-at', { head, target }, `${head.t} (${target})`);
85
+ return head;
86
+ }
87
+
55
88
  export class Tethers {
56
89
  #keeper; #resources; #conversations; #secrets; #dockets; #timers = []; #changes = 0; #seen = new Map(); #offered; #noticed; #ended = new Map(); #acting = [];
57
90
  /* Set by the server once the thread is ready (main.mjs): (name, event) => talk.event(...).
@@ -106,7 +139,7 @@ export class Tethers {
106
139
  /* `request`: the card Parley draws (demandes.mjs); the text and its buttons stay for an older screen. */
107
140
  let request;
108
141
  try { request = demandeView(r); } catch { request = undefined; }
109
- try { this.announce(name, { kind: 'tether-demande', text: text || (r.verb ?? 'A Tether call'), topic: 'Demande', tone: 'warn', actions: [`allow:${r.id}`, `deny:${r.id}`], ...(request ? { request } : {}) }); } catch { /* its chat is off */ }
142
+ try { this.announce(name, { kind: 'tether-demande', text: text || (r.verb ?? 'A Tether call'), topic: TOPIC_REQUEST, tone: 'warn', actions: [`allow:${r.id}`, `deny:${r.id}`], ...(request ? { request } : {}) }); } catch { /* its chat is off */ }
110
143
  }
111
144
  /* An approved call only the owner's browser can do (a device to flash): said once, with where to do it. */
112
145
  let jobs = [];
@@ -118,7 +151,9 @@ export class Tethers {
118
151
  if (!who.startsWith(AGENT)) continue;
119
152
  const name = who.slice(AGENT.length);
120
153
  this.#seen.set(j.id, { name, verb: j.verb });
121
- try { this.announce(name, { kind: 'tether-job', text: `To do in your browser: ${j.args?.name ? `flash ${j.args.name}` : 'flash a device'}. Plug it in by USB here, then start.`, topic: 'Demande', tone: 'warn', actions: [`flash:${j.id}`] }); } catch { /* its chat is off */ }
154
+ const text = j.args?.name ? said('line-flash', { name: String(j.args.name) }, `To do in your browser: flash ${j.args.name}. Plug it in by USB here, then start.`)
155
+ : said('line-flash-device', undefined, 'To do in your browser: flash a device. Plug it in by USB here, then start.');
156
+ try { this.announce(name, { kind: 'tether-job', text, topic: TOPIC_REQUEST, tone: 'warn', actions: [`flash:${j.id}`] }); } catch { /* its chat is off */ }
122
157
  }
123
158
  for (const [id, info] of [...this.#seen]) {
124
159
  if (live.has(id)) continue;
@@ -129,8 +164,8 @@ export class Tethers {
129
164
  fail): said as being done, and its result said when Tether journals it (#tellResult). */
130
165
  const accepted = outcome === 'yes' || outcome === 'always';
131
166
  if (accepted) { this.#acting.push({ id, ...info }); if (this.#acting.length > ACTING_MAX) this.#acting.shift(); }
132
- const text = accepted ? `Accepted: ${info.verb} — being done` : `Request handled: ${info.verb}${outcome ? ` (${outcome})` : ''}`;
133
- try { this.announce(info.name, { kind: 'tether-done', text, topic: 'Demande', brief: id, ...(outcome ? { outcome } : {}) }); } catch { /* its chat is off */ }
167
+ const text = endedLine(info.verb, outcome);
168
+ try { this.announce(info.name, { kind: 'tether-done', text, topic: TOPIC_REQUEST, brief: id, ...(outcome ? { outcome } : {}) }); } catch { /* its chat is off */ }
134
169
  }
135
170
  for (const id of [...this.#ended.keys()]) if (!this.#seen.has(id)) this.#ended.delete(id);
136
171
  }
@@ -146,8 +181,8 @@ export class Tethers {
146
181
  if (i < 0) return;
147
182
  const [call] = this.#acting.splice(i, 1);
148
183
  const failed = l.ok === false;
149
- const text = failed ? `Failed: ${call.verb}${l.error ? ` — ${l.error}` : ''}` : `Done: ${call.verb}`;
150
- try { this.announce(call.name, { kind: 'tether-done', text, topic: 'Demande', ...(failed ? { tone: 'bad', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
184
+ const text = resultLine(call.verb, failed ? (l.error ?? '') : undefined);
185
+ try { this.announce(call.name, { kind: 'tether-done', text, topic: TOPIC_REQUEST, ...(failed ? { tone: 'bad', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
151
186
  }
152
187
 
153
188
  /* A NOTICE (Tether calls `notify`): said once in the thread of the conversation whose agent did it,
@@ -166,12 +201,11 @@ export class Tethers {
166
201
  if (!Array.isArray(seen) || seen.includes(id)) return;
167
202
  try { this.#noticed.set([...seen, id].slice(-NOTICES_MAX)); } catch { /* said anyway, this once */ }
168
203
  const kind = String(n.kind ?? '');
169
- const head = noticeHead(kind);
170
204
  const warns = noticeWarns(kind);
171
- const said = String(n.text ?? '').trim();
172
- const where = n.target?.title ? ` (${n.target.title})` : '';
173
- const text = `${head}${where}${said ? `: ${said}` : ''}`;
174
- try { this.announce?.(name, { kind: 'tether-notice', text, topic: 'Notice', ...(warns ? { tone: 'warn', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
205
+ /* Clavarium's head and frame in the reader's words; Tether's own sentence as Tether wrote it. */
206
+ const line = noticeLine(kind, n.target?.title ? String(n.target.title) : '', String(n.text ?? '').trim());
207
+ const text = line.t;
208
+ try { this.announce?.(name, { kind: 'tether-notice', text: line, topic: TOPIC_NOTICE, ...(warns ? { tone: 'warn', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
175
209
  try {
176
210
  if (this.#dockets?.on(name)) {
177
211
  this.#dockets.post(name, { kind: 'tether-notice', text: `${text}${/[.!?]$/.test(text) ? '' : '.'} See more: tether notices.`,