clavarium 0.2.252-beta.1 → 0.2.253-beta.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.252-beta.1",
3
+ "version": "0.2.253-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.252-beta.1",
9
+ "version": "0.2.253-beta.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.252-beta.1",
3
+ "version": "0.2.253-beta.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/api.mjs CHANGED
@@ -494,7 +494,7 @@ export async function handleApi(request, response, conversations, headers, resou
494
494
  if (pathname === '/api/wifi/scan' && wifi) return send(200, await wifi.scan()), true;
495
495
  if (pathname === '/api/meshcentral' && meshcentral) return send(200, await meshcentral.status()), true;
496
496
  /* Each account with its role and, for a member, the conversations it was given (#419). */
497
- if (pathname === '/api/operators') return send(200, team ? { operators: team.list().map((o) => ({ ...o, role: team.people?.roleOf(o.email) ?? 'admin', ...(team.people?.roleOf(o.email) === 'member' ? { given: team.grants?.of(`person:${o.email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) ?? [] } : {}) })), me: identity, defaultRole: team.people?.defaultRole?.() ?? 'admin' } : { local: true }), true;
497
+ if (pathname === '/api/operators') return send(200, team ? { operators: team.list().map((o) => ({ ...o, role: team.people?.roleOf(o.email) ?? 'admin', ...(team.people?.roleOf(o.email) === 'member' ? { given: team.grants?.of(`person:${o.email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) ?? [], quota: team.people?.quotaOf?.(o.email) ?? null } : {}) })), me: identity, defaultRole: team.people?.defaultRole?.() ?? 'admin' } : { local: true }), true;
498
498
  if (pathname === '/api/binder/people' && binders) return send(200, { people: binders.people(identity), changes: `${BOOT}:${binders.changes()}` }), true;
499
499
  if (pathname === '/api/certificate' && certificate) return send(200, await certificate.about({ fresh: query.get('fresh') === '1' })), true;
500
500
  /* This server's disk and memory (capacity.mjs): everything for Settings; only whether it is high for the list. */
@@ -830,6 +830,14 @@ export async function handleApi(request, response, conversations, headers, resou
830
830
  team.people.changed?.();
831
831
  return send(200, { given: team.grants.of(`person:${email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) }), true;
832
832
  }
833
+ /* The memory a member's own conversations may take together (29-11): 0, it makes none. */
834
+ const quota = /^\/api\/operators\/([^/]{3,200})\/quota$/.exec(pathname);
835
+ if (quota && team?.people) {
836
+ const email = decodeURIComponent(quota[1]).trim().toLowerCase();
837
+ if (!team.list().some((o) => o.email === email)) throw new Refusal(404, 'No such account.');
838
+ team.people.setQuota(email, { mb: body.mb, diskGb: body.diskGb, cpus: body.cpus });
839
+ return send(200, { operators: team.people.list() }), true;
840
+ }
833
841
  const op = /^\/api\/operators\/([^/]{3,200})\/(password|disable|enable|remove)$/.exec(pathname);
834
842
  if (op && team) {
835
843
  const email = decodeURIComponent(op[1]).trim().toLowerCase();
@@ -350,7 +350,7 @@ export class Conversations {
350
350
  }
351
351
 
352
352
  /* `after`: a promise its build waits for (a copy reads its original first); resolving false, no build. */
353
- create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine, machineMb, after }) {
353
+ create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine, machineMb, after, owner }) {
354
354
  const { name, title } = this.#naming({ name: given, title: read });
355
355
  /* IN A SHARED MACHINE (#221), named: its work is always kept here (mounted into its place there). */
356
356
  if (machine !== undefined && (typeof machine !== 'string' || !isConversationName(machine))) throw new Refusal(400, 'A machine name is 1 to 32 lower-case letters, digits or hyphens; it starts with a letter.');
@@ -378,8 +378,10 @@ export class Conversations {
378
378
  if (memory > size) throw new Refusal(400, `The machine ${machine} has ${size} MB of memory: this conversation cannot have more (${memory} MB).`);
379
379
  }
380
380
  if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
381
+ /* Made by a member (29-11): whose it is, shown to the administrators and counted in that member's memory. */
382
+ if (owner !== undefined && (typeof owner !== 'string' || !/^[^\s@]{1,64}@[^\s@]{1,200}$/.test(owner))) throw new Refusal(400, 'Its owner is an account address.');
381
383
  const now = new Date().toISOString();
382
- const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine, machineMb: size, ...this.#machineSizesOf(machine) } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
384
+ const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), ...(owner ? { owner } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine, machineMb: size, ...this.#machineSizesOf(machine) } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
383
385
  /* A new one comes first in its folder (or first of those in none). */
384
386
  const { order, groups } = this.#order();
385
387
  this.#store.put(conversation);
package/server/door.mjs CHANGED
@@ -47,7 +47,7 @@
47
47
  * given to the device for itself stay its own, whatever it was given of a
48
48
  * conversation.)
49
49
  */
50
- import { Refusal } from './conversations.mjs';
50
+ import { Refusal, DISK_GB } from './conversations.mjs';
51
51
  import { readCookie, sessionCookie, cookieNameOf, isPairingId } from './devices.mjs';
52
52
  import { WORK_TAB } from './resources.mjs';
53
53
  import { list, download, importFile, page, PAGE_HEADERS, changeRoute, CHANGE_ROUTES, IMAGE_HEADERS, mailFile, mailPage } from './files.mjs';
@@ -161,12 +161,46 @@ export async function handleDoor(request, response, { devices, conversations, re
161
161
  return resources.folder(ways[0].name);
162
162
  };
163
163
 
164
+ /* A MEMBER MAKES A CONVERSATION OF ITS OWN (29-11): a name and a tool, under the memory an administrator
165
+ gave it for all of them together. It signs in to its own AI account there; nothing else is set here
166
+ (no folder, no key, no shared machine): an administrator gives those. */
167
+ if (person && request.method === 'GET' && route === '/tools') {
168
+ return send(200, { quota: person.quota(), used: person.used(), diskMinGb: DISK_GB, tools: conversations.tools().map((t) => ({ id: t.id, label: t.label, memoryMb: t.memoryMb })) });
169
+ }
170
+ if (person && request.method === 'POST' && route === '/conversations') {
171
+ const body = await readJson(request);
172
+ if (!person.still()) throw new Refusal(403, 'This account may not use this page now.');
173
+ const quota = person.quota();
174
+ if (!(quota.mb > 0)) throw new Refusal(403, 'An administrator has not let you make conversations.');
175
+ const tool = conversations.tools().find((t) => t.id === body.tool);
176
+ if (!tool) throw new Refusal(400, 'Choose an AI.');
177
+ const want = { mb: body.memoryMb === undefined ? tool.memoryMb : Number(body.memoryMb), diskGb: body.diskGb === undefined ? DISK_GB : Number(body.diskGb), cpus: body.cpus === undefined ? 1 : Number(body.cpus) };
178
+ await conversations.admit?.({ title: body.title, tool: tool.id, memoryMb: want.mb });
179
+ /* Counted after the wait, just before it is made: two at once never go past it together. */
180
+ const used = person.used();
181
+ const over = [['mb', 'memory', 'MB'], ['diskGb', 'disk', 'GB'], ['cpus', 'cores', '']].find(([k]) => quota[k] > 0 && used[k] + want[k] > quota[k]);
182
+ if (over) { const [k, what, unit] = over; throw new Refusal(409, `Not enough ${what} left: ${quota[k] - used[k]}${unit ? ` ${unit}` : ''} of your ${quota[k]}${unit ? ` ${unit}` : ''}, this one needs ${want[k]}${unit ? ` ${unit}` : ''}.`); }
183
+ const made = conversations.create({ title: String(body.title ?? '').trim() || undefined, tool: tool.id, memoryMb: want.mb, diskGb: want.diskGb, cpus: want.cpus, owner: person.email });
184
+ person.own(made.name);
185
+ /* Its chat on once it is built, as for one an administrator makes. */
186
+ if (talk) {
187
+ const until = Date.now() + 30 * 60_000;
188
+ const on = async () => {
189
+ const c = conversations.list().find((x) => x.name === made.name);
190
+ if (!c || Date.now() > until) return;
191
+ if (c.phase === 'ready') { try { await talk.set(made.name, true); } catch { /* turned on from its settings */ } return; }
192
+ setTimeout(() => { void on(); }, 2000).unref?.();
193
+ };
194
+ void on();
195
+ }
196
+ return send(201, { name: made.name, title: made.title, tool: made.tool, memoryMb: made.memoryMb });
197
+ }
164
198
  if (request.method === 'GET' && route === '/me') {
165
199
  /* `conversations`: all this pairing may use. `shared`: what it was given for itself. */
166
200
  /* `terminal` and `chat`: the parts it was given, for the page to show only those. */
167
201
  /* Each attached one with its type: the page draws it as the asset it is (assets step 6). */
168
202
  const about = mine ? { name: mine.name, toolLabel: mine.toolLabel, chatName: mine.chatName, voiceMark: mine.voiceMark, phase: mine.phase, step: mine.step, progress: mine.progress, error: mine.error, work: mine.work, resources: resources.of(name).map((r) => ({ ...r, type: resources.get(r.name)?.type ?? 'folder' })), ...part } : { name: null, resources: [] };
169
- return send(200, { ...about, conversations: names.filter((n) => conversations.list().some((c) => c.name === n)), shared: own });
203
+ return send(200, { ...about, conversations: names.filter((n) => conversations.list().some((c) => c.name === n)), shared: own, ...(person ? { quota: person.quota(), used: person.used() } : {}) });
170
204
  }
171
205
  /* The files a device was given for itself need no conversation; everything else does. */
172
206
  const forFiles = route === '/files' || route === '/files/download' || route === '/files/page' || route === '/files/mail' || route === '/files/import' || CHANGE_ROUTES.includes(route) || route === '/leave' || route === '/mail/open' || route === '/mail/page';
@@ -715,6 +715,12 @@ export class GitKeeper {
715
715
  conversation to make them: asked again under the lock by the send. */
716
716
  if (!remoteTip && !s.create) return once('create', { what: `Not sent: ${b} does not exist on the remote, and ${conversation} may not create branches by itself.`, ai: `${plain(b)} was not sent: it does not exist on the remote, and only the owner can make it` }), false;
717
717
  if (s.checks) {
718
+ /* Said once per commit (#430): what is not online yet, and why -- the agent and its owner see the
719
+ true state instead of guessing; what comes meanwhile goes at the next turn. */
720
+ if (held.checking?.get(b) !== tip.id) {
721
+ (held.checking ??= new Map()).set(b, tip.id);
722
+ this.#say(name, [conversation], { kind: 'checking', text: `Not online yet: ${name} → ${b} (${tip.id.slice(0, 7)}) is being checked before it is sent; commits made meanwhile go next.`, topic: 'Checking', brief: b });
723
+ }
718
724
  const checks = await this.#check(name, { head: tip.id, branch: b, target: b, remoteTip }, conversation);
719
725
  if (checks.status !== 'passed') {
720
726
  /* Its machine did not run them: tried again later, when it may. */
@@ -739,6 +745,8 @@ export class GitKeeper {
739
745
  if (sent.already) { this.#log(name, { branch: b, head: tip.id, conversation, ok: true, what: `Already on the remote: ${b}.` }, { sent: true, by: conversation }); return true; }
740
746
  this.#log(name, { branch: b, head: tip.id, conversation, ok: true, what: `Sent automatically for ${conversation}: ${sent.commits} commit(s) to ${sent.branch}${sent.made ? ' (a new branch)' : ''}, ${checked}.${sent.note ? ` ${sent.note}` : ''}` }, { sent: true, by: conversation });
741
747
  if (alert) this.#tell(`${name}: sent to ${sent.branch}`, `${sent.commits} commit(s), automatically for ${conversation}, ${checked}.`);
748
+ /* Its agent knows it is online (#430): one line, it no longer has to guess or look. */
749
+ this.#toAgent(name, `${sent.branch} is online: ${commitsOf(sent.commits)} sent (${tip.id.slice(0, 7)}), ${checked}`, conversation);
742
750
  this.#say(name, [conversation], { kind: 'sent', text: `Sent: ${name} → ${sent.branch}, ${commitsOf(sent.commits)}${sent.made ? ', a new branch' : ''}${s.checks ? '' : ', no checks'}.`, topic: 'Sent', brief: sent.branch, actions: seeCommits(name, sent.head, sent.base, sent.commits) });
743
751
  return true;
744
752
  } catch (error) {
@@ -838,7 +838,13 @@ export class GitReview {
838
838
  if (review.auto === true && !now && review.create !== true) throw new GitFailure(409, 'no-branch', `Not sent: ${target} does not exist on the remote, and automatic sending may not create branches here.`);
839
839
  /* (3) Exactly what was reviewed, on both sides. */
840
840
  const mine = got.branches.find((b) => b.name === branch);
841
- if (!mine || mine.id !== head) throw new GitFailure(409, 'agent-moved', `Not sent: the agent changed ${branch} since you looked. Look again.`);
841
+ /* Sent automatically (#430, 29-11): the commit that was checked goes even when the agent
842
+ committed again during its checks (ten minutes), as long as it is still in the branch --
843
+ the newer commits are checked and sent at the next turn. Thrown away and begun again at
844
+ every new commit, an agent committing every few minutes was never sent. Shown to a person
845
+ (Send), the branch must be exactly what was shown. */
846
+ const stillIn = review.auto === true && mine && mine.id !== head && await this.#isAncestor(got.path, head, mine.id);
847
+ if (!mine || (mine.id !== head && !stillIn)) throw new GitFailure(409, 'agent-moved', `Not sent: the agent changed ${branch} since you looked. Look again.`, review.auto === true ? { ai: `${branch} changed while it was checked, and the checked commit is no longer in it (history rewritten?): it is checked again before it goes` } : {});
842
848
  if (now !== remoteTip) throw new GitFailure(409, 'remote-moved', `Not sent: the remote's ${target} moved since you looked. Look again.`, { ai: `origin/${target} moved: pull origin/${target} first` });
843
849
  const ws = got.path;
844
850
  const only = `${got.branches.map((b) => `delete refs/heads/${b.name}\n`).join('')}create refs/clavarium/send ${head}\n`;
package/server/main.mjs CHANGED
@@ -400,6 +400,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
400
400
  grantsOf: () => grants.of(subject).filter((g) => g.type === 'conversation'),
401
401
  rightsOn: (_key, name) => grants.rightsOf(subject, `conversation:${name}`),
402
402
  conversationOf: (wanted) => { const m = mine(); if (wanted === undefined || wanted === '') return m[0]; return m.includes(wanted) ? wanted : undefined; },
403
+ /* ITS OWN CONVERSATIONS (29-11): the memory an administrator lets them take together, and what they take. */
404
+ quota: () => team.people?.quotaOf?.(email) ?? { mb: 0, diskGb: 0, cpus: 0 },
405
+ used: () => all.list().filter((c) => c.owner === email).reduce((n, c) => ({ mb: n.mb + (c.memoryMb ?? 0), diskGb: n.diskGb + (c.diskGb ?? 0), cpus: n.cpus + (c.cpus ?? 1) }), { mb: 0, diskGb: 0, cpus: 0 }),
406
+ own: (name) => grants.give(subject, `conversation:${name}`, 'rwx'),
403
407
  };
404
408
  } : null;
405
409
  /* Folder-style boxes the owner drops assets into, to tidy the views and hand a whole box at once (groups.mjs). */
package/server/people.mjs CHANGED
@@ -22,6 +22,13 @@ import { readFileSync, writeFileSync, renameSync, existsSync, copyFileSync, mkdi
22
22
  import { dirname } from 'node:path';
23
23
  import { Refusal } from './conversations.mjs';
24
24
 
25
+ /* A member's room, as kept: { mb, diskGb, cpus }, whole numbers; none without memory. */
26
+ const cleanQuota = (v) => {
27
+ const n = (x) => (Number.isInteger(x) && x >= 0 ? x : 0);
28
+ const q = typeof v === 'number' ? { mb: n(v), diskGb: 0, cpus: 0 } : v && typeof v === 'object' ? { mb: n(v.mb), diskGb: n(v.diskGb), cpus: n(v.cpus) } : null;
29
+ return q && q.mb > 0 ? q : null;
30
+ };
31
+
25
32
  export const ROLES = Object.freeze(['admin', 'member']);
26
33
  /* What deploy/updater.mjs looks for in a release before going back to it: it reads these lists (#419). */
27
34
  export const PEOPLE_LISTS = 1;
@@ -45,7 +52,9 @@ export class People {
45
52
  #read(file) {
46
53
  const data = JSON.parse(readFileSync(file, 'utf8'));
47
54
  if (!data || !Array.isArray(data.admins) || !Array.isArray(data.members)) throw new Error('not a roles file');
48
- return { admins: [...new Set(data.admins.map(low))], members: [...new Set(data.members.map(low))] };
55
+ const quotas = {};
56
+ for (const [k, v] of Object.entries(data.quotas && typeof data.quotas === 'object' ? data.quotas : {})) { const q = cleanQuota(v); if (q) quotas[low(k)] = q; }
57
+ return { admins: [...new Set(data.admins.map(low))], members: [...new Set(data.members.map(low))], quotas };
49
58
  }
50
59
  #load() {
51
60
  if (!existsSync(this.#path) && !existsSync(`${this.#path}.bak`)) { this.#lists = null; return; }
@@ -57,7 +66,9 @@ export class People {
57
66
  }
58
67
  #save() {
59
68
  const tmp = `${this.#path}.new`;
60
- writeFileSync(tmp, `${JSON.stringify(this.#lists, null, 1)}\n`, { mode: 0o600 });
69
+ const { quotas, ...lists } = this.#lists;
70
+ /* No room given to anyone: the file as before it existed (going back reads it the same). */
71
+ writeFileSync(tmp, `${JSON.stringify(quotas && Object.keys(quotas).length ? { ...lists, quotas } : lists, null, 1)}\n`, { mode: 0o600 });
61
72
  if (existsSync(this.#path)) { try { this.#read(this.#path); copyFileSync(this.#path, `${this.#path}.bak`); } catch { /* the old one was bad: no copy of it */ } }
62
73
  renameSync(tmp, this.#path);
63
74
  this.#damaged = false;
@@ -83,7 +94,21 @@ export class People {
83
94
  }
84
95
 
85
96
  /* The lists written out at the first member: every account there is now an administrator, as it was. */
86
- #seed() { if (this.#lists === null) this.#lists = { admins: this.#all().map((a) => a.email), members: [] }; }
97
+ #seed() { if (this.#lists === null) this.#lists = { admins: this.#all().map((a) => a.email), members: [], quotas: {} }; this.#lists.quotas ??= {}; }
98
+ /* A MEMBER'S OWN CONVERSATIONS (29-11): what all of them may take together -- memory (MB), disk (GB), cores --
99
+ set by an administrator. A memory of 0: it makes none; a disk or cores of 0: not counted. */
100
+ quotaOf(email) { const q = this.#lists?.quotas?.[low(email)]; return q ? { ...q } : { mb: 0, diskGb: 0, cpus: 0 }; }
101
+ setQuota(email, given) {
102
+ const e = low(email);
103
+ if (this.#damaged) throw new Refusal(409, 'The file of the roles cannot be read: repair it first.');
104
+ if (this.roleOf(e) !== 'member') throw new Refusal(409, 'Only a member is given room of its own: an administrator makes what it wants.');
105
+ const q = { mb: Number(given?.mb ?? 0), diskGb: Number(given?.diskGb ?? 0), cpus: Number(given?.cpus ?? 0) };
106
+ if (!Number.isInteger(q.mb) || q.mb < 0 || q.mb > 262144) throw new Refusal(400, 'Its memory is 0 (makes none) to 262144 MB.');
107
+ if (!Number.isInteger(q.diskGb) || q.diskGb < 0 || q.diskGb > 10000) throw new Refusal(400, 'Its disk is 0 to 10000 GB.');
108
+ if (!Number.isInteger(q.cpus) || q.cpus < 0 || q.cpus > 256) throw new Refusal(400, 'Its cores are 0 to 256.');
109
+ this.#seed(); if (q.mb === 0) delete this.#lists.quotas[e]; else this.#lists.quotas[e] = q; this.#save();
110
+ return this.quotaOf(e);
111
+ }
87
112
  #put(e, role) {
88
113
  this.#lists.admins = this.#lists.admins.filter((x) => x !== e);
89
114
  this.#lists.members = this.#lists.members.filter((x) => x !== e);
@@ -109,7 +134,7 @@ export class People {
109
134
  const e = low(email);
110
135
  if (!ROLES.includes(role) || this.#damaged) return () => {};
111
136
  if (this.#lists === null && role === 'admin') return () => {};
112
- const before = this.#lists === null ? null : { admins: [...this.#lists.admins], members: [...this.#lists.members] };
137
+ const before = this.#lists === null ? null : { admins: [...this.#lists.admins], members: [...this.#lists.members], quotas: { ...(this.#lists.quotas ?? {}) } };
113
138
  this.#seed(); this.#put(e, role); this.#save();
114
139
  return () => {
115
140
  if (before === null) { this.#lists = null; rmSync(this.#path, { force: true }); rmSync(`${this.#path}.bak`, { force: true }); return; }
@@ -122,6 +147,7 @@ export class People {
122
147
  if (this.#lists === null || this.#damaged) return;
123
148
  this.#lists.admins = this.#lists.admins.filter((x) => x !== e);
124
149
  this.#lists.members = this.#lists.members.filter((x) => x !== e);
150
+ if (this.#lists.quotas) delete this.#lists.quotas[e];
125
151
  this.#save();
126
152
  }
127
153
  /* Accounts gone outside the page (the host program): their roles forgotten. Returns the addresses forgotten. */
@@ -132,10 +158,11 @@ export class People {
132
158
  const gone = [...this.#lists.admins, ...this.#lists.members].filter((e) => !here.has(e));
133
159
  if (!gone.length) return [];
134
160
  this.#lists.admins = this.#lists.admins.filter((e) => here.has(e)); this.#lists.members = this.#lists.members.filter((e) => here.has(e));
161
+ for (const e of gone) if (this.#lists.quotas) delete this.#lists.quotas[e];
135
162
  this.#save();
136
163
  return gone;
137
164
  }
138
165
  /* The role a new account gets when none is said: a member (24-11, its owner's choice); an administrator is ticked. */
139
166
  defaultRole() { return 'member'; }
140
- list() { return this.#all().map((a) => ({ ...a, role: this.roleOf(a.email) })); }
167
+ list() { return this.#all().map((a) => ({ ...a, role: this.roleOf(a.email), ...(this.roleOf(a.email) === 'member' ? { quota: this.quotaOf(a.email) } : {}) })); }
141
168
  }
@@ -59,6 +59,7 @@ export const SETTINGS_WORDS_FR = {
59
59
  'set-lang-device': 'La langue de chaque appareil', 'set-res-now': 'Mémoire {m} % · disque {d} %',
60
60
  'set-share-memory': 'Mémoire par machine', 'set-share-disk': 'Disque par machine', 'set-share-others': 'Autres',
61
61
  'set-share-rest': 'Système et autres', 'set-share-else': 'Tout le reste', 'set-share-free': 'Libre', 'set-share-used': 'Utilisé', 'set-share-of': 'sur {total}',
62
+ 'set-room': 'Ses propres conversations', 'set-room-mem': 'Mémoire', 'set-room-disk': 'Disque', 'set-room-cpus': 'Cœurs', 'set-room-off': 'Non',
62
63
  'set-binders-max': 'Les agents en font {n} au plus', 'set-admin-1': '1 administrateur', 'set-admins': '{n} administrateurs', 'set-member-1': '1 membre', 'set-members': '{n} membres', 'set-member-gone': 'Plus rien n\'est partagé avec vous.', 'set-give-read': 'Lecture seule', 'set-give-chat': 'Chat', 'set-give-both': 'Chat + terminal', 'set-give-terminal': 'Terminal', 'set-give-none': 'Retirer l\'accès', 'set-given-none': 'Rien de partagé pour l\'instant.', 'set-given-ai': 'Chat et terminal : tout ce que son IA atteint.', 'set-give-add': 'Partager une conversation…', 'set-role-admin': 'Administrateur', 'set-role-member': 'Membre', 'set-add-account': 'Ajouter un compte', 'set-ch-s-operators-about': 'Qui se connecte, et ce qu\'il voit.',
63
64
  'set-backup-now': 'Exporter · importer', 'set-git-key': '1 clé git', 'set-git-keys': '{n} clés git', 'set-restart': 'redémarrer',
64
65
  'set-logs-now': 'Clavarium, machines, système',
package/server/talk.mjs CHANGED
@@ -164,6 +164,8 @@ export const LEVELS = Object.freeze(['needs-you', 'news', 'trace']);
164
164
  export const RESTART_ASKED = 'restart-asked';
165
165
  export const EVENT_LEVELS = Object.freeze({
166
166
  sent: 'news',
167
+ /* A branch waiting for its checks before it goes (#430, 29-11): a trace, shown when one asks. */
168
+ checking: 'trace',
167
169
  'room-hops': 'news',
168
170
  refused: 'needs-you',
169
171
  'sent-by-hand': 'news',
package/web/app.js CHANGED
@@ -1476,6 +1476,8 @@
1476
1476
  const chips = [];
1477
1477
  /* Found by a search while hidden: said. */
1478
1478
  if (c.hidden === true && query) chips.push({ text: uiSaid('set-list-hidden', 'hidden'), cls: 'shared-mark', tone: 'note' });
1479
+ /* Made by a member (29-11): whose it is, by the name before the @. */
1480
+ if (c.owner && !DEVICE) chips.push({ text: String(c.owner).split('@')[0], icon: 'person', cls: 'shared-mark', tone: 'note', wide: true });
1479
1481
  /* Several models answer its simple questions; or they stopped, and it waits for its owner. */
1480
1482
  const waking = (c.wakeups?.items ?? []).filter((w) => w.on).length;
1481
1483
  if (waking > 0) chips.push({ text: uiSaid(waking > 1 ? 'set-list-wakeups' : 'set-list-wakeup', waking > 1 ? '{n} wake-ups' : '1 wake-up', { n: waking }), cls: 'shared-mark', tone: 'note' });
@@ -4270,6 +4272,7 @@
4270
4272
  /* Settings: what the chat's thread shows of each kind of event (server/talk.mjs EVENT_LEVELS). */
4271
4273
  const THREAD_KINDS = [
4272
4274
  ['sent', 'Sent automatically', 'A branch went to the remote by itself'],
4275
+ ['checking', 'Checking before sending', 'Commits wait for their checks before going'],
4273
4276
  ['sent-by-hand', 'Sent by hand', 'Sent from the review'],
4274
4277
  ['refused', 'Not sent', 'An automatic sending was refused: what to do'],
4275
4278
  ['origin', 'Origin updated', 'The remote brought commits'],
@@ -8363,6 +8366,30 @@
8363
8366
  sel.addEventListener('change', () => void set(name, sel.value));
8364
8367
  return sel;
8365
8368
  };
8369
+ /* ITS OWN CONVERSATIONS (29-11): the memory, disk and cores all of them may take together; Off, it makes none. */
8370
+ const q = o.quota ?? { mb: 0, diskGb: 0, cpus: 0 };
8371
+ const room = el('div', 'op-room');
8372
+ room.append(el('span', '', uiSaid('set-room', 'Its own conversations')));
8373
+ const pick = (what, aria, choices, value) => {
8374
+ const sel = el('select', `op-room-${what}`); sel.setAttribute('aria-label', `${aria} — ${o.email}`);
8375
+ for (const [v, l] of choices) { const opt = el('option', '', l); opt.value = String(v); sel.append(opt); }
8376
+ sel.value = String(choices.some(([v]) => v === value) ? value : choices[0][0]);
8377
+ return sel;
8378
+ };
8379
+ const mem = pick('mb', uiSaid('set-room-mem', 'Memory'), [[0, uiSaid('set-room-off', 'Off')], [2048, '2 GB RAM'], [4096, '4 GB RAM'], [8192, '8 GB RAM'], [16384, '16 GB RAM'], [32768, '32 GB RAM']], q.mb);
8380
+ const disk = pick('disk', uiSaid('set-room-disk', 'Disk'), [[20, '20 GB disk'], [40, '40 GB disk'], [80, '80 GB disk'], [160, '160 GB disk'], [320, '320 GB disk']], q.diskGb || 40);
8381
+ const cores = pick('cpus', uiSaid('set-room-cpus', 'Cores'), [[1, '1 core'], [2, '2 cores'], [4, '4 cores'], [8, '8 cores']], q.cpus || 2);
8382
+ const on = () => { disk.hidden = cores.hidden = mem.value === '0'; };
8383
+ on();
8384
+ for (const sel of [mem, disk, cores]) sel.addEventListener('change', async () => {
8385
+ on();
8386
+ $('operators-error').hidden = true;
8387
+ try { await post(`${API}/operators/${encodeURIComponent(o.email)}/quota`, { mb: Number(mem.value), diskGb: Number(disk.value), cpus: Number(cores.value) }); }
8388
+ catch (error) { $('operators-error').textContent = error.message; $('operators-error').hidden = false; }
8389
+ await paintOperators();
8390
+ });
8391
+ room.append(mem, disk, cores);
8392
+ box.append(room);
8366
8393
  if (given.size === 0) box.append(el('small', '', uiSaid('set-given-none', 'Nothing shared yet.')));
8367
8394
  /* What a chat or a terminal really gives (audit 24-11): what its AI can reach -- its folders, mail, keys. */
8368
8395
  else box.append(el('small', 'hint', uiSaid('set-given-ai', 'Chat and terminal: all its AI can reach.')));
@@ -13892,8 +13919,9 @@
13892
13919
  /* ---------- the other conversations of this device ---------- */
13893
13920
  /* A device may have been given several conversations, each by a code of
13894
13921
  its own. One is shown at a time; the others are a tap away. */
13922
+ let memberMayMake = false;
13895
13923
  function offerOthers(others) {
13896
- $('others').hidden = MEMBER && others.length === 0;
13924
+ $('others').hidden = MEMBER && others.length === 0 && !memberMayMake;
13897
13925
  $('others').textContent = others.length > 0 ? `Conversations (${others.length + 1})` : MEMBER ? 'Conversations' : 'This device';
13898
13926
  $('others').onclick = () => {
13899
13927
  const rows = $('others-rows');
@@ -13910,13 +13938,50 @@
13910
13938
  });
13911
13939
  row.append(name, open, leave); rows.append(row);
13912
13940
  };
13913
- line(current || 'Shared files', pairing, true, current || null);
13941
+ if (current || !MEMBER) line(current || 'Shared files', pairing, true, current || null);
13914
13942
  for (const o of others) line(o.name ?? 'Shared files', o.pairing, false, o.name);
13943
+ if (MEMBER) { $('others-add').hidden = true; $('others-head').textContent = 'Your conversations'; $('others-hint').textContent = 'Shared with you by an administrator, or made by you.'; void offerNew(); }
13915
13944
  $('files').hidden = true; $('copy').hidden = true;
13916
13945
  $('others-sheet').hidden = false;
13917
13946
  };
13918
13947
  }
13919
13948
  $('others-close').addEventListener('click', () => { $('others-sheet').hidden = true; focusTerminal(); });
13949
+ /* A MEMBER'S OWN CONVERSATIONS (29-11): offered when an administrator gave it room; sizes only within what is left. */
13950
+ const gbWords = (mb) => `${Math.round(mb / 1024 * 10) / 10} GB`;
13951
+ async function offerNew() {
13952
+ const got = await fetch('/m/api/tools').then((r) => (r.ok ? r.json() : null)).catch(() => null);
13953
+ const form = $('others-new');
13954
+ form.hidden = !got || !(got.quota?.mb > 0);
13955
+ if (form.hidden) return false;
13956
+ const left = { mb: got.quota.mb - got.used.mb, diskGb: got.quota.diskGb > 0 ? got.quota.diskGb - got.used.diskGb : Infinity, cpus: got.quota.cpus > 0 ? got.quota.cpus - got.used.cpus : Infinity };
13957
+ const fill = (sel, values, word) => { const was = sel.value; sel.replaceChildren(...values.map((v) => { const o = document.createElement('option'); o.value = String(v); o.textContent = word(v); return o; })); if (values.map(String).includes(was)) sel.value = was; sel.disabled = values.length === 0; };
13958
+ const tools = got.tools.filter((t) => t.memoryMb <= left.mb);
13959
+ fill($('new-tool'), tools.map((t) => t.id), (id) => tools.find((t) => t.id === id).label);
13960
+ const sizes = () => {
13961
+ const min = tools.find((t) => t.id === $('new-tool').value)?.memoryMb ?? 1024;
13962
+ fill($('new-mb'), [...new Set([min, 2048, 4096, 8192, 16384])].filter((v) => v >= min && v <= left.mb && v <= 16384).sort((a, b) => a - b), (v) => `${gbWords(v)} RAM`);
13963
+ fill($('new-disk'), [got.diskMinGb, 20, 40, 80].filter((v, i, a) => v >= got.diskMinGb && v <= left.diskGb && a.indexOf(v) === i), (v) => `${v} GB disk`);
13964
+ fill($('new-cpus'), [1, 2, 4].filter((v) => v <= left.cpus), (v) => (v === 1 ? '1 core' : `${v} cores`));
13965
+ };
13966
+ $('new-tool').onchange = sizes; sizes();
13967
+ const room = [`${gbWords(Math.max(0, left.mb))} RAM`, Number.isFinite(left.diskGb) ? `${Math.max(0, left.diskGb)} GB disk` : '', Number.isFinite(left.cpus) ? `${Math.max(0, left.cpus)} ${left.cpus === 1 ? 'core' : 'cores'}` : ''].filter(Boolean).join(' · ');
13968
+ $('new-left').textContent = `Left for you: ${room}`;
13969
+ const none = !tools.length || $('new-mb').disabled || $('new-disk').disabled || $('new-cpus').disabled;
13970
+ $('new-go').disabled = none;
13971
+ if (none) $('new-left').textContent = `No room left (${room}). Ask an administrator for more.`;
13972
+ return true;
13973
+ }
13974
+ $('others-new').addEventListener('submit', async (event) => {
13975
+ event.preventDefault();
13976
+ $('new-error').hidden = true; $('new-go').disabled = true;
13977
+ try {
13978
+ const r = await fetch('/m/api/conversations', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ title: $('new-title').value.trim(), tool: $('new-tool').value, memoryMb: Number($('new-mb').value), diskGb: Number($('new-disk').value), cpus: Number($('new-cpus').value) }) });
13979
+ const out = await r.json().catch(() => ({}));
13980
+ if (!r.ok) throw new Error(out.error ?? `The server answered ${r.status}.`);
13981
+ $('new-title').value = '';
13982
+ await window.clavariumShowPairing('member', out.name);
13983
+ } catch (error) { $('new-error').textContent = error.message; $('new-error').hidden = false; $('new-go').disabled = false; }
13984
+ });
13920
13985
  /* A link pasted instead of scanned: only its code is taken, and it is
13921
13986
  handed to this page exactly as a scanned one would be. */
13922
13987
  $('others-add').addEventListener('submit', (event) => {
@@ -13934,6 +13999,9 @@
13934
13999
  const fresh = location.hash.length > 1; /* arriving with a code: a first visit */
13935
14000
  say(fresh ? 'pairing' : 'connecting', 'connecting');
13936
14001
  const door = await window.clavariumDoor();
14002
+ memberMayMake = MEMBER && door.mayMake === true;
14003
+ /* Nothing yet, room to make one (29-11): its form at once. */
14004
+ if (!door.ok && memberMayMake) { pairing = 'member'; current = ''; shut(door.message); $('state').hidden = true; offerOthers([]); $('others').onclick(); return; }
13937
14005
  if (!door.ok) { shut(door.message); return; }
13938
14006
  pairing = door.pairing; API = MEMBER ? '/m/api' : `/c/api/${pairing}`; current = door.conversation ?? '';
13939
14007
  document.documentElement.dataset.pairing = pairing; /* not a secret: a name, useless without the key */
package/web/device.html CHANGED
@@ -49,9 +49,23 @@
49
49
  <div class="row"><button type="button" id="paste-send">Send to the terminal</button></div>
50
50
  </div>
51
51
  <div id="others-sheet" class="sheet" hidden>
52
- <div class="panel-top"><b>Conversations on this device</b><button type="button" id="others-close">Close</button></div>
53
- <p class="hint">Each conversation was shared with this device by a code of its own. To add another, scan its code. Removing one here takes it off this device only.</p>
52
+ <div class="panel-top"><b id="others-head">Conversations on this device</b><button type="button" id="others-close">Close</button></div>
53
+ <p class="hint" id="others-hint">Each conversation was shared with this device by a code of its own. To add another, scan its code. Removing one here takes it off this device only.</p>
54
54
  <div id="others-rows"></div>
55
+ <!-- A MEMBER MAKES ITS OWN (29-11): a name, an AI, its size, under the room an administrator gave. -->
56
+ <form id="others-new" autocomplete="off" hidden>
57
+ <b>New conversation</b>
58
+ <input id="new-title" maxlength="60" placeholder="Its name" aria-label="Its name" required>
59
+ <select id="new-tool" aria-label="AI"></select>
60
+ <div class="row new-sizes">
61
+ <select id="new-mb" aria-label="Memory"></select>
62
+ <select id="new-disk" aria-label="Disk"></select>
63
+ <select id="new-cpus" aria-label="Cores"></select>
64
+ </div>
65
+ <p id="new-left" class="hint"></p>
66
+ <div class="row"><button type="submit" class="primary" id="new-go">Create</button></div>
67
+ <p id="new-error" class="error" role="alert" hidden></p>
68
+ </form>
55
69
  <form id="others-add" autocomplete="off">
56
70
  <label for="others-link">Add a conversation: paste the link you were sent</label>
57
71
  <div class="row"><input id="others-link" inputmode="url" spellcheck="false" autocapitalize="off" placeholder="https://.../c/#..." required>
package/web/member.js CHANGED
@@ -12,9 +12,11 @@
12
12
  if (!r.ok) throw new Error(`The server answered ${r.status}.`);
13
13
  const me = await r.json();
14
14
  const names = Array.isArray(me.conversations) ? me.conversations : [];
15
- if (names.length === 0 && !(me.shared ?? []).length) return { ok: false, message: 'Nothing has been given to you yet. Ask an administrator to give you a conversation.' };
15
+ /* Given room for its own (29-11): it may make one, even with nothing yet. */
16
+ const mayMake = (me.quota?.mb ?? 0) > 0;
17
+ if (names.length === 0 && !(me.shared ?? []).length) return mayMake ? { ok: false, mayMake, message: 'No conversation yet. Make your first one.' } : { ok: false, message: 'Nothing has been given to you yet. Ask an administrator to give you a conversation.' };
16
18
  const current = names.includes(kept()) ? kept() : (names[0] ?? null);
17
- return { ok: true, pairing: 'member', conversation: current, others: names.filter((n) => n !== current).map((name) => ({ pairing: 'member', name })) };
19
+ return { ok: true, mayMake, pairing: 'member', conversation: current, others: names.filter((n) => n !== current).map((name) => ({ pairing: 'member', name })) };
18
20
  } catch (error) {
19
21
  return { ok: false, message: error.message };
20
22
  }
package/web/style.css CHANGED
@@ -270,6 +270,10 @@ footer button.careful { border-style: dashed; color: var(--ink2); }
270
270
 
271
271
  #others-add { display: grid; gap: 6px; margin-top: 12px; }
272
272
  #others-add input { flex: 1; min-width: 0; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
273
+ #others-new { display: grid; gap: 8px; max-width: 560px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
274
+ #others-new input, #others-new select { min-width: 0; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
275
+ #others-new .new-sizes { display: flex; flex-wrap: wrap; gap: 6px; }
276
+ #others-new .new-sizes select { flex: 1 1 8em; }
273
277
 
274
278
  /* A word said for a moment (text copied). */
275
279
  #flash { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 7; display: flex; align-items: center; gap: 10px; max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 999px; background: var(--panel); color: var(--ink); border: 1px solid var(--brass); font-weight: 600; font-size: .8125rem; pointer-events: none; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); }
@@ -2897,6 +2901,7 @@ header.topbar .kit-stack:focus-visible { outline: 2px solid var(--brass); outlin
2897
2901
  .kit-chip-ic { width: 11px; height: 11px; flex: none; background: currentColor; -webkit-mask: var(--kit-ic) center / contain no-repeat; mask: var(--kit-ic) center / contain no-repeat; }
2898
2902
  .kit-ic-room { --kit-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M22 21v-2a4 4 0 0 0-3-3.87'/%3E%3Cpath d='M16 3.13a4 4 0 0 1 0 7.75'/%3E%3C/svg%3E"); }
2899
2903
  .kit-ic-box { --kit-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='6' y='2.5' width='12' height='19' rx='3'/%3E%3Ccircle cx='12' cy='14.5' r='3.2'/%3E%3C/svg%3E"); }
2904
+ .kit-ic-person { --kit-ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='12' cy='7' r='4'/%3E%3C/svg%3E"); }
2900
2905
  /* SWITCH: yes / no. */
2901
2906
  button.kit-switch { position: relative; width: 40px; height: 24px; min-height: 0 !important; flex: none; padding: 0; border-radius: 999px; background: var(--bg); }
2902
2907
  button.kit-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink2); transition: left .15s, background .15s; }
@@ -3460,4 +3465,7 @@ span.tile-spark { display: block; height: 22px; }
3460
3465
  .op-given{display:flex;flex-direction:column;gap:6px;margin:-4px 0 10px 18px;padding-left:10px;border-left:2px solid var(--line, #ccc)}
3461
3466
  .op-given-line{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
3462
3467
  .op-given-line span{min-width:0;overflow-wrap:anywhere}
3468
+ .op-room{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding-bottom:6px;border-bottom:1px solid var(--line)}
3469
+ .op-room>span{flex:1 1 100%;font-size:.9em;color:var(--ink2)}
3470
+ .op-room select{flex:0 1 auto;min-width:0}
3463
3471
  .op-role{margin-right:6px}