clavarium 0.2.352-next.1 → 0.2.354-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.352-next.1",
3
+ "version": "0.2.354-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.352-next.1",
9
+ "version": "0.2.354-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.61-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
- "clavarium-parley": "0.17.82-next.1",
16
+ "clavarium-parley": "0.17.84-next.1",
17
17
  "clavarium-tether": "0.1.0-next.55",
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.82-next.1",
791
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.82-next.1.tgz",
792
- "integrity": "sha512-wCH7ajkmqfxY2qnY9zuaqdppd1C5rAiiFXH2IWcVYIpzuvnhjD2ac6lgVM3tJsfg6RsUBoBZVC9poLVeHpCwjg==",
790
+ "version": "0.17.84-next.1",
791
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.84-next.1.tgz",
792
+ "integrity": "sha512-tvw4ahhxfwzbBZ1r22hhyEHts+41tt78zmEQl+DlUvR+V3GipiriOQSfLqiEWE1HbTeMZZO98lG69ipHLZ/rNg==",
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.352-next.1",
3
+ "version": "0.2.354-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.61-next.1",
48
48
  "clavarium-docket": "0.1.2-next.2",
49
- "clavarium-parley": "0.17.82-next.1",
49
+ "clavarium-parley": "0.17.84-next.1",
50
50
  "clavarium-tether": "0.1.0-next.55",
51
51
  "mammoth": "1.13.0",
52
52
  "mermaid": "11.17.2",
package/server/rooms.mjs CHANGED
@@ -18,6 +18,7 @@ import { mkdirSync, rmSync } from 'node:fs';
18
18
  import { randomUUID } from 'node:crypto';
19
19
  import { Parley } from 'clavarium-parley/host';
20
20
  import { Refusal } from './conversations.mjs';
21
+ import { scan } from './secret-scan.mjs';
21
22
 
22
23
  export const ROOM_NAME_MAX = 60;
23
24
  export const ROOMS_MAX = 20;
@@ -29,6 +30,12 @@ export const THINKING_MS = 10 * 60_000;
29
30
  const KINDS = ['person', 'ai', 'box'];
30
31
  const nameOf = (v) => String(v ?? '').replace(/\s+/g, ' ').trim().slice(0, ROOM_NAME_MAX);
31
32
 
33
+ /* A SECRET IN A ROOM (06-11): a room's thread is read by all its members, now and later -- a token, a key pasted
34
+ there is never kept: the thread shows it as stars, and only the AI the message goes to gets it (lifted into its
35
+ own short-lived store by its chat, as any secret said to it). What an AI writes in a room is masked the same way:
36
+ a secret never passes from one AI to another through a room. */
37
+ export const masked = (text) => { const str = String(text ?? ''); const hits = scan(str); if (!hits.length) return str; let out = ''; let last = 0; for (const h of hits) { out += str.slice(last, h.start) + '••••••'; last = h.end; } return out + str.slice(last); };
38
+
32
39
  /* A sign as the cards draw it (web/kit.js hueOf, initialOf): the same name, the same letter and colour. */
33
40
  export const lookOf = (name) => { const text = String(name ?? ''); let h = 0; for (const ch of text) h = (h * 31 + ch.codePointAt(0)) >>> 0; return { initial: ([...text.trim()][0] ?? '?').toUpperCase(), hue: h % 360 }; };
34
41
 
@@ -57,7 +64,8 @@ export class Rooms {
57
64
  .map((m) => { const name = m.kind === 'box' ? (boxes.get(m.ref)?.name ?? m.name) : m.kind === 'ai' ? convs.get(m.ref) : m.name;
58
65
  return { id: m.id, kind: m.kind, name, ref: m.ref, look: lookOf(m.kind === 'ai' ? titles.get(m.ref) : name), ...(m.id === room.host ? { host: true } : {}) }; });
59
66
  }
60
- #think(room, member, on) { const m = this.#thinking.get(room) ?? new Map(); if (on) m.set(member, Date.now()); else m.delete(member); this.#thinking.set(room, m); }
67
+ /* Who works for the room now, and what it says it does (06-11: « je fais… » on the status line, never in the thread). */
68
+ #think(room, member, on, text = '') { const m = this.#thinking.get(room) ?? new Map(); if (on) m.set(member, { at: Date.now(), text: String(text ?? '').slice(0, 160) }); else m.delete(member); this.#thinking.set(room, m); }
61
69
  has(id) { return this.#all().some((r) => r.id === id); }
62
70
  /* What came since the owner last looked (#282): the AIs' and the boxes' messages after it. */
63
71
  #unread(r) { try { const seen = Date.parse(r.seen ?? '') || 0; return this.#thread(r.id).read({ last: 200 }).messages.filter((m) => (m.from === 'agent' || m.by) && (Date.parse(m.at) || 0) > seen).length; } catch { return 0; } }
@@ -65,7 +73,8 @@ export class Rooms {
65
73
  #last(r) { try { const m = this.#thread(r.id).read({ last: 1 }).messages.at(-1); return m ? { at: m.at, text: String(m.text ?? '').replace(/\s+/g, ' ').slice(0, 120), ...(m.by?.name ? { by: m.by.name } : {}) } : null; } catch { return null; } }
66
74
  /* Who has a message of the room and has not answered yet (#282), by their names of the moment: « Hugo parle… »
67
75
  in its row of the list and on its bar, « Hugo réfléchit… » in its thread. */
68
- #thinkingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([, at]) => Date.now() - at < THINKING_MS).map(([mid]) => members.find((m) => m.id === mid)?.name).filter(Boolean); }
76
+ #thinkingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([, v]) => Date.now() - v.at < THINKING_MS).map(([mid]) => members.find((m) => m.id === mid)?.name).filter(Boolean); }
77
+ #doingOf(id, members) { return [...(this.#thinking.get(id) ?? new Map()).entries()].filter(([, v]) => v.text && Date.now() - v.at < THINKING_MS).map(([mid, v]) => ({ name: members.find((m) => m.id === mid)?.name, text: v.text })).filter((x) => x.name); }
69
78
  list() { return this.#all().map((r) => { const members = this.#shown(r); return { id: r.id, name: r.name, host: r.host, members, at: r.at, unread: this.#unread(r), last: this.#last(r), thinking: this.#thinkingOf(r.id, members) }; }); }
70
79
  get(id) { const r = this.#find(id); return { id: r.id, name: r.name, host: r.host, members: this.#shown(r), at: r.at }; }
71
80
 
@@ -130,8 +139,8 @@ export class Rooms {
130
139
  /* A member named in a text (@{id}): its name of the moment, on the screen. */
131
140
  const named = (text) => String(text ?? '').replace(/@\{([0-9a-f-]{36})\}/g, (whole, mid) => { const m = members.find((x) => x.id === mid); return m ? `@${m.name}` : whole; });
132
141
  if (options?.seen !== false) { const list = this.#all(); const r = list.find((x) => x.id === id); if (r) { r.seen = this.#now().toISOString(); this.#file.set(list); } }
133
- const thinking = this.#thinkingOf(id, members);
134
- return { room: this.get(id), thinking, ...read, messages: (read.messages ?? []).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m)) };
142
+ const thinking = this.#thinkingOf(id, members); const doing = this.#doingOf(id, members);
143
+ return { room: this.get(id), thinking, doing, ...read, messages: (read.messages ?? []).map((m) => (typeof m.text === 'string' && m.text.includes('@{') ? { ...m, text: named(m.text) } : m)) };
135
144
  }
136
145
 
137
146
  /* SOMEONE OF THE PERSON'S SIDE SPEAKS (the person here, a box): kept in the room, given to the host -- or to the
@@ -144,13 +153,13 @@ export class Rooms {
144
153
  const t = this.#thread(room.id);
145
154
  this.#hops.set(room.id, 0);
146
155
  /* The owner is the room's own side (no name over their words, as in any chat); anyone else is named. */
147
- const now = t.say(text, undefined, [], who.ref === 'owner' ? {} : { by: { id: who.id, name: who.name, kind: who.kind, look: who.look } });
156
+ const now = t.say(masked(text), undefined, [], who.ref === 'owner' ? {} : { by: { id: who.id, name: who.name, kind: who.kind, look: who.look } });
148
157
  const said = now.messages.at(-1);
149
158
  const named = (Array.isArray(to) ? to : []).map((x) => members.find((m) => m.id === x && m.kind === 'ai')).filter(Boolean);
150
159
  const host = members.find((m) => m.id === room.host);
151
160
  for (const ai of named.length ? named : host ? [host] : []) {
152
161
  this.#think(room.id, ai.id, true);
153
- await this.#say(ai.ref, said.text, { by: { id: who.id, name: who.name, kind: who.kind, look: who.look }, room: { id: room.id, name: room.name, message: said.id } });
162
+ await this.#say(ai.ref, text, { by: { id: who.id, name: who.name, kind: who.kind, look: who.look }, room: { id: room.id, name: room.name, message: said.id } });
154
163
  }
155
164
  /* Handed to its AIs: read, as a conversation's agent would say it (06-11: the clock stayed on every message). */
156
165
  try { t.seen?.(); } catch { /* an older Parley */ }
@@ -169,7 +178,15 @@ export class Rooms {
169
178
  const all = () => t.read({ all: true }).messages;
170
179
  const find = (id) => (typeof id === 'string' && id.length >= 8 ? all().find((m) => m.id.startsWith(id)) : undefined);
171
180
  const re = find(entry.re)?.id;
172
- if (kind !== 'doing') this.#think(room.id, me.id, false);
181
+ /* What it does: on the room's status line only, never a line of its thread (06-11, the owner's choice). */
182
+ if (kind === 'doing') {
183
+ this.#think(room.id, me.id, true, masked(entry.text));
184
+ /* A box it is said to still says it aloud (first, at once, what it is about to do). */
185
+ const boxes = (Array.isArray(entry.to) ? entry.to : []).map((x) => members.find((m) => m.id === x && m.kind === 'box')).filter(Boolean).map((m) => m.ref);
186
+ if (boxes.length) try { this.#speak(`room:${room.id}`, masked(entry.text), boxes, { doing: true, asked: false }); } catch { /* the boxes' */ }
187
+ return 'doing';
188
+ }
189
+ this.#think(room.id, me.id, false);
173
190
  const ids = new Set(members.map((m) => m.id));
174
191
  const to = Array.isArray(entry.to) ? entry.to.filter((x) => ids.has(x) && x !== me.id) : [];
175
192
  /* The other AIs it is sent to (#280): they get it in their own chat, as said in the room -- never beyond a few
@@ -192,7 +209,7 @@ export class Rooms {
192
209
  }
193
210
  if (!String(entry.text ?? '').trim()) return null;
194
211
  /* @Name of a member, exactly: kept as its id (the screen says its name of the moment). */
195
- const text = String(entry.text).replace(/@([^\s@{][^@\n]{0,40}?)(?=[\s,.;:!?)]|$)/g, (whole, name) => { const m = members.find((x) => x.name.toLowerCase() === name.toLowerCase()); return m ? `@{${m.id}}` : whole; });
212
+ const text = masked(entry.text).replace(/@([^\s@{][^@\n]{0,40}?)(?=[\s,.;:!?)]|$)/g, (whole, name) => { const m = members.find((x) => x.name.toLowerCase() === name.toLowerCase()); return m ? `@{${m.id}}` : whole; });
196
213
  const id = t.relay({ text, by: { id: me.id, name: me.name, kind: 'ai', look: me.look }, to, re, kind: kind === 'doing' ? 'doing' : 'say' });
197
214
  /* The boxes it is sent to say it aloud (#281): its words, a member named by its name, never an id. */
198
215
  const boxes = to.map((x) => members.find((m) => m.id === x && m.kind === 'box')).filter(Boolean).map((m) => m.ref);
package/web/app.js CHANGED
@@ -5319,8 +5319,11 @@
5319
5319
  load: (asked = {}) => fetch(`${API}/rooms/${id}/talk${asked.last ? `?last=${asked.last}` : ''}`).then((x) => x.json()).then((d) => {
5320
5320
  /* Who was given a message and has not answered yet (#282): « Hugo réfléchit… ». */
5321
5321
  const who = thinkingOf(d);
5322
- $('salon-thinking').hidden = who.length === 0;
5323
- $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(who.length > 1 ? uiSaid('room-thinking-many', '{names} are thinking\u2026', { names: who.join(', ') }) : uiSaid('room-thinking', '{name} is thinking\u2026', { name: who[0] ?? '' })));
5322
+ /* What they say they do (06-11): on this line, « Thomas : je demande à MSM… », never in the thread. */
5323
+ const doing = (Array.isArray(d.doing) ? d.doing : []).filter((x) => x && typeof x.name === 'string' && typeof x.text === 'string' && x.text);
5324
+ $('salon-thinking').hidden = who.length === 0 && doing.length === 0;
5325
+ if (doing.length) $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(doing.map((x) => `${x.name} : ${x.text}`).join(' \u00b7 ')));
5326
+ else $('salon-thinking').replaceChildren(KIT.StatusDot({ state: 'work' }), document.createTextNode(who.length > 1 ? uiSaid('room-thinking-many', '{names} are thinking\u2026', { names: who.join(', ') }) : uiSaid('room-thinking', '{name} is thinking\u2026', { name: who[0] ?? '' })));
5324
5327
  /* Its bar says it too, as its row in the list: its dot at work, « Cuisine parle… » under its name. */
5325
5328
  salonLive(who);
5326
5329
  const known = rooms.find((x) => x.id === id);