clavarium 0.2.539-next.1 → 0.2.541-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.539-next.1",
3
+ "version": "0.2.541-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.539-next.1",
9
+ "version": "0.2.541-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.66-next.1",
15
15
  "clavarium-docket": "0.1.2-next.3",
16
- "clavarium-parley": "0.17.102-next.1",
16
+ "clavarium-parley": "0.17.103-next.1",
17
17
  "clavarium-tether": "0.1.0-next.79",
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.102-next.1",
791
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.102-next.1.tgz",
792
- "integrity": "sha512-RUGpMBGs1ibNjVZnz0ghMP9YJPRlIYQtqlaI94WP354gzcwoUiQ/0G/m8HiWNxXGLVvcWU0hy7pM+3lFvvvosw==",
790
+ "version": "0.17.103-next.1",
791
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.103-next.1.tgz",
792
+ "integrity": "sha512-3gb9swir4OJefi2daaija5RA1GObk+XVwK4iu+Bp6vokei5JiByQk45FoFMZtZYYv+hGo5WpOIHpmuoxK/FXtg==",
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.539-next.1",
3
+ "version": "0.2.541-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.",
@@ -47,7 +47,7 @@
47
47
  "@xterm/xterm": "^6.0.0",
48
48
  "clavarium-binder": "0.1.66-next.1",
49
49
  "clavarium-docket": "0.1.2-next.3",
50
- "clavarium-parley": "0.17.102-next.1",
50
+ "clavarium-parley": "0.17.103-next.1",
51
51
  "clavarium-tether": "0.1.0-next.79",
52
52
  "mammoth": "1.13.0",
53
53
  "mermaid": "11.17.2",
@@ -0,0 +1,84 @@
1
+ /* WHAT A MEMBER MAY CALL (#431, 29-11): the same routes as an administrator, filtered by the server -- never a
2
+ * second API to keep in step. One table, here, says which routes a member reaches at all; every other one is
3
+ * refused, so a route added one day stays closed to members until it is put here on purpose.
4
+ *
5
+ * Each line: a method, the route, and what it needs:
6
+ * 'any' -- nothing of anyone's: the same answer for every account (the tools that can be chosen);
7
+ * 'list' -- answered with what this member may see only (the handler filters, by `request.member`);
8
+ * 'create' -- a conversation of its own, under the room an administrator gave it;
9
+ * 'own' -- what is kept per person (its desk), read and written under its own name only;
10
+ * 'owner' -- a route of one conversation it owns (it made it, or it was made its own);
11
+ * 'asset-owner' -- a route of one asset it owns (its own folder);
12
+ * 'key-owner' -- a route of one key it owns;
13
+ * 'files' -- the files of a folder: which folder it may reach is decided where it is chosen (api.mjs, attached);
14
+ * 'r' / 'w' / 'x' -- a route of one conversation (its name is the route's first part): that right on it,
15
+ * read from the one table of who may do what (grants.mjs), at each request.
16
+ * Administrators are not looked at here: they reach everything, as before. */
17
+
18
+ const NAME = '([a-z][a-z0-9-]{0,31})';
19
+ export const MEMBER_ROUTES = Object.freeze([
20
+ ['GET', /^\/api\/conversations$/, 'list'],
21
+ ['POST', /^\/api\/conversations$/, 'create'],
22
+ ['GET', /^\/api\/tools$/, 'any'],
23
+ /* Its own desk, the home page (desktop.mjs keeps one per person, by the name the sign-in gives). */
24
+ ['GET', /^\/api\/desktop$/, 'own'],
25
+ ['PUT', /^\/api\/desktop$/, 'own'],
26
+ /* The chat's words in the reader's language: the same for everybody. */
27
+ ['GET', /^\/api\/talk\/words$/, 'any'],
28
+ ['GET', new RegExp(`^/api/conversations/${NAME}/talk$`), 'r'],
29
+ ['GET', new RegExp(`^/api/conversations/${NAME}/talk/search$`), 'r'],
30
+ ['POST', new RegExp(`^/api/conversations/${NAME}/talk$`), 'w'],
31
+ ['POST', new RegExp(`^/api/conversations/${NAME}/talk/remind$`), 'w'],
32
+ ['POST', new RegExp(`^/api/conversations/${NAME}/talk/file$`), 'w'],
33
+ ['GET', new RegExp(`^/api/conversations/${NAME}/health$`), 'r'],
34
+ /* Its OWN conversations (it is their owner): their settings and their machine's life -- a name, sleep,
35
+ wake, restart, delete. Not those it was only given. */
36
+ ['POST', new RegExp(`^/api/conversations/${NAME}/title$`), 'owner'],
37
+ ['POST', new RegExp(`^/api/conversations/${NAME}/chat-name$`), 'owner'],
38
+ ['POST', new RegExp(`^/api/conversations/${NAME}/sleep$`), 'owner'],
39
+ ['POST', new RegExp(`^/api/conversations/${NAME}/resume$`), 'owner'],
40
+ ['POST', new RegExp(`^/api/conversations/${NAME}/restart$`), 'owner'],
41
+ ['POST', new RegExp(`^/api/conversations/${NAME}/erase$`), 'owner'],
42
+ ['POST', new RegExp(`^/api/conversations/${NAME}/machine$`), 'owner'],
43
+ /* ITS OWN ASSETS (#431 step 2): its folders -- listed, made, removed, given to its own conversations. */
44
+ ['GET', /^\/api\/resources$/, 'list'],
45
+ ['POST', /^\/api\/resources$/, 'create'],
46
+ ['POST', new RegExp(`^/api/resources/${NAME}/remove$`), 'asset-owner'],
47
+ ['POST', new RegExp(`^/api/conversations/${NAME}/resources$`), 'owner'],
48
+ /* Its own keys: listed (names only), made under a new name, replaced, removed, given to its own conversations. */
49
+ ['GET', /^\/api\/secrets$/, 'list'],
50
+ ['POST', /^\/api\/secrets$/, 'create'],
51
+ ['POST', /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/(replace|remove)$/, 'key-owner'],
52
+ ['POST', new RegExp(`^/api/conversations/${NAME}/secrets$`), 'owner'],
53
+ /* The files of its own folders and of its conversations' work (checked where the folder is chosen: api.mjs). */
54
+ ['GET', /^\/api\/files$/, 'files'],
55
+ ['GET', /^\/api\/files\/(download|page|thumb|text)$/, 'files'],
56
+ ['POST', /^\/api\/files\/(import|make|move|remove|rename|save|taken)$/, 'files'],
57
+ ]);
58
+
59
+ /* { ok: false } or { ok: true, need, conversation? }. `rightsOn(name)`: the member's rights on that conversation. */
60
+ export function memberMay(method, pathname, rightsOn, owns = () => false, ownsAsset = () => false, ownsKey = () => false) {
61
+ for (const [m, route, need] of MEMBER_ROUTES) {
62
+ if (m !== method) continue;
63
+ const hit = route.exec(pathname);
64
+ if (!hit) continue;
65
+ if (need === 'any' || need === 'list' || need === 'create' || need === 'own' || need === 'files') return { ok: true, need };
66
+ const conversation = hit[1];
67
+ if (need === 'key-owner') return ownsKey(hit[1]) ? { ok: true, need, key: hit[1] } : { ok: false, why: 'Only its owner does that.' };
68
+ if (need === 'asset-owner') return ownsAsset(conversation) ? { ok: true, need, asset: conversation } : { ok: false, why: 'Only its owner does that.' };
69
+ if (need === 'owner') return owns(conversation) ? { ok: true, need, conversation } : { ok: false, why: 'Only its owner does that.' };
70
+ return String(rightsOn(conversation) ?? '').includes(need) ? { ok: true, need, conversation } : { ok: false, why: 'This conversation is not shared with you for that.' };
71
+ }
72
+ return { ok: false, why: 'This is for administrators.' };
73
+ }
74
+
75
+ /* What of a conversation a member's list shows: what the list draws, never what is the server's (its keys, its
76
+ folders, its machine's user, its wake-ups, its answerer). */
77
+ export const MEMBER_FIELDS = Object.freeze(['name', 'title', 'chatName', 'group', 'tool', 'toolLabel', 'phase', 'step', 'progress', 'error', 'asleep', 'stopped', 'owner', 'memoryMb', 'cpus', 'diskGb', 'voiceMark', 'hidden']);
78
+ export function memberView(c, rights, email) {
79
+ return {
80
+ ...Object.fromEntries(MEMBER_FIELDS.filter((k) => c[k] !== undefined).map((k) => [k, c[k]])),
81
+ mine: c.owner === email,
82
+ parts: { terminal: rights.includes('x'), chat: rights.includes('r') ? (rights.includes('w') ? 'write' : 'read') : null },
83
+ };
84
+ }
package/server/api.mjs CHANGED
@@ -189,6 +189,8 @@
189
189
  * A request that changes something must come from this site's own pages: the
190
190
  * Origin header is compared, and the body must be JSON, which a form on
191
191
  * another site cannot send. */
192
+ import { memberView } from './access.mjs';
193
+ import { memberCreate } from './door.mjs';
192
194
  import { addMachine } from './sshmachine.mjs';
193
195
  import { openCodeConfig } from './catalog.mjs';
194
196
  import { writeFileSync } from 'node:fs';
@@ -246,6 +248,16 @@ export async function handleApi(request, response, conversations, headers, resou
246
248
  /* A sign-in, said once in a while for the same person (events.mjs). */
247
249
  events?.seen(identity);
248
250
  const attached = (need) => {
251
+ /* A MEMBER (#431 step 2): its own folders; the work folder of a conversation it owns or was given the terminal
252
+ of (its files are the terminal's anyway); nothing else, whatever the address says. */
253
+ if (request.member) {
254
+ const m = request.member;
255
+ if (query.get('r') === WORK_TAB) {
256
+ const c = conversations.list().find((x) => x.name === query.get('c'));
257
+ if (!c || !(c.owner === m.email || m.rightsOn(m.key, c.name).includes('x'))) throw new Refusal(403, 'This conversation\'s files are not yours.');
258
+ } else if (!m.ownsAsset(query.get('r') ?? '')) throw new Refusal(403, 'This folder is not yours.');
259
+ if (!m.still()) throw new Refusal(403, 'This account may not use this page now.');
260
+ }
249
261
  /* The conversation's own work folder, when the server keeps it. */
250
262
  if (query.get('r') === WORK_TAB && resources) {
251
263
  const c = conversations.list().find((x) => x.name === query.get('c'));
@@ -351,12 +363,32 @@ export async function handleApi(request, response, conversations, headers, resou
351
363
  }
352
364
  if (request.method === 'GET') {
353
365
  if (pathname === '/api/tools') return send(200, conversations.tools()), true;
366
+ if (pathname === '/api/conversations' && request.member) {
367
+ /* A member (#431): those it was given and those it made, as the list draws them, nothing of the server's. */
368
+ const m = request.member;
369
+ const names = new Set(m.grantsOf().map((g) => g.name));
370
+ return send(200, conversations.list().filter((c) => names.has(c.name)).map((c) => {
371
+ const rights = m.rightsOn(m.key, c.name);
372
+ return { ...memberView(c, rights, m.email), talk: rights.includes('r') ? (talk?.brief(c.name) ?? null) : null };
373
+ })), true;
374
+ }
354
375
  if (pathname === '/api/conversations') {
355
376
  const lists = binders?.given() ?? {};
356
377
  return send(200, conversations.list().map((c) => ({ ...c, lists: lists[c.name] ?? null, resources: resources?.of(c.name) ?? [], secrets: secrets?.of(c.name) ?? [], ephemeralSecrets: secrets?.liveFor(c.name) ?? [], answerer: answerer?.of(c.name) ?? null, wakeups: wakeups?.of(c.name) ?? null, health: health?.of(c.name) ?? null, talk: talk?.brief(c.name) ?? null }))), true;
357
378
  }
379
+ /* A member's (#431 step 2): its own folders, and to which of ITS conversations each is given -- never
380
+ the administrators' conversations' names. */
381
+ if (pathname === '/api/resources' && resources && request.member) {
382
+ const mine = new Set(request.member.grantsOf().map((g) => g.name));
383
+ return send(200, resources.list().filter((r) => r.owner === request.member.email).map((r) => ({ ...r, attachments: Object.fromEntries(Object.entries(r.attachments ?? {}).filter(([c]) => mine.has(c))) }))), true;
384
+ }
358
385
  if (pathname === '/api/resources' && resources) return send(200, resources.list()), true;
359
386
  if (pathname === '/api/shortcuts' && shortcuts) return send(200, shortcuts.list()), true;
387
+ /* A member's (#431 step 2): its own keys' names, and which of ITS conversations has each. */
388
+ if (pathname === '/api/secrets' && secrets && request.member) {
389
+ const mine = new Set(request.member.grantsOf().map((g) => g.name));
390
+ return send(200, secrets.list().filter((x) => x.owner === request.member.email).map((x) => ({ ...x, conversations: (x.conversations ?? []).filter((c) => mine.has(typeof c === 'string' ? c : c?.name)) }))), true;
391
+ }
360
392
  if (pathname === '/api/secrets' && secrets) return send(200, secrets.list()), true;
361
393
  /* The providers and models OpenCode knows (models.dev), for a conversation made with it (03-11). */
362
394
  if (pathname === '/api/catalog/models' && catalogue) return send(200, { providers: await catalogue.providers() }), true;
@@ -494,7 +526,7 @@ export async function handleApi(request, response, conversations, headers, resou
494
526
  if (pathname === '/api/wifi/scan' && wifi) return send(200, await wifi.scan()), true;
495
527
  if (pathname === '/api/meshcentral' && meshcentral) return send(200, await meshcentral.status()), true;
496
528
  /* 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;
529
+ 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
530
  if (pathname === '/api/binder/people' && binders) return send(200, { people: binders.people(identity), changes: `${BOOT}:${binders.changes()}` }), true;
499
531
  if (pathname === '/api/certificate' && certificate) return send(200, await certificate.about({ fresh: query.get('fresh') === '1' })), true;
500
532
  /* This server's disk and memory (capacity.mjs): everything for Settings; only whether it is high for the list. */
@@ -574,7 +606,10 @@ export async function handleApi(request, response, conversations, headers, resou
574
606
  const attaching = /^\/api\/conversations\/([^/]+)\/talk\/file$/.exec(pathname);
575
607
  if (attaching && talk) {
576
608
  if (!originOk(request.headers) || request.headers['content-type'] !== 'application/octet-stream') return send(403, { error: 'This request does not come from this site.' }), true;
577
- return send(201, await talk.attach(decodeURIComponent(attaching[1]), query.get('name') ?? '', request)), true;
609
+ const attached = await talk.attach(decodeURIComponent(attaching[1]), query.get('name') ?? '', request);
610
+ /* A member whose right went while its file came: not given back to it (#431, audit 10 of the door). */
611
+ if (request.member && !request.member.still()) return send(403, { error: 'This conversation is not shared with you any more.' }), true;
612
+ return send(201, attached), true;
578
613
  }
579
614
  /* A file the person attaches in a room (06-11): the same as in a chat, kept in the room. */
580
615
  const roomAttaching = /^\/api\/rooms\/([0-9a-f-]{36})\/talk\/file$/.exec(pathname);
@@ -605,6 +640,7 @@ export async function handleApi(request, response, conversations, headers, resou
605
640
  if (r && r[2] === '/remove') { rooms.remove(r[1]); return send(200, { removed: r[1] }), true; }
606
641
  if (r && r[2] === '/talk') return send(201, await rooms.say(r[1], body?.text, { to: body?.to, files: body?.files })), true;
607
642
  }
643
+ if (pathname === '/api/conversations' && request.member) return send(201, await memberCreate({ conversations, talk, person: request.member, body: body ?? {} })), true;
608
644
  if (pathname === '/api/conversations') {
609
645
  await conversations.admit?.(body);
610
646
  const made = conversations.create(body);
@@ -665,6 +701,8 @@ export async function handleApi(request, response, conversations, headers, resou
665
701
  return send(404, { error: 'Not found.' }), true;
666
702
  }
667
703
  /* A folder, or a git repository (empty, or cloned from `from`). A mailbox has its own way in. */
704
+ /* A member's own folder (#431 step 2): a folder only, its own -- no repository, nothing cloned. */
705
+ if (pathname === '/api/resources' && resources && request.member) return send(201, await resources.create({ name: body.name, type: 'folder', owner: request.member.email })), true;
668
706
  if (pathname === '/api/resources' && resources) {
669
707
  const made = await resources.create({ name: body.name, type: body.type === 'git' ? 'git' : 'folder', from: body.from, via: body.via });
670
708
  /* One an import was waiting for: attached where the file said. */
@@ -768,6 +806,7 @@ export async function handleApi(request, response, conversations, headers, resou
768
806
  return send(200, { ok: true, signature }), true;
769
807
  }
770
808
  if (pathname === '/api/shortcuts' && shortcuts) return send(201, shortcuts.add(body)), true;
809
+ if (pathname === '/api/secrets' && secrets && request.member) return send(201, secrets.set({ name: body.name, value: body.value, expires: body.expires, owner: request.member.email })), true;
771
810
  if (pathname === '/api/secrets' && secrets) { const made = secrets.set(body); setup?.secretAdded(made.name); return send(201, made), true; }
772
811
  /* Asset groups (groups.mjs): a folder-style tidy-up, not a right. */
773
812
  if (pathname === '/api/asset-groups' && groups) return send(201, groups.create(body.label)), true;
@@ -830,6 +869,14 @@ export async function handleApi(request, response, conversations, headers, resou
830
869
  team.people.changed?.();
831
870
  return send(200, { given: team.grants.of(`person:${email}`, 'conversation').map((g) => ({ name: g.name, rights: g.rights })) }), true;
832
871
  }
872
+ /* The memory a member's own conversations may take together (29-11): 0, it makes none. */
873
+ const quota = /^\/api\/operators\/([^/]{3,200})\/quota$/.exec(pathname);
874
+ if (quota && team?.people) {
875
+ const email = decodeURIComponent(quota[1]).trim().toLowerCase();
876
+ if (!team.list().some((o) => o.email === email)) throw new Refusal(404, 'No such account.');
877
+ team.people.setQuota(email, { mb: body.mb, diskGb: body.diskGb, cpus: body.cpus });
878
+ return send(200, { operators: team.people.list() }), true;
879
+ }
833
880
  const op = /^\/api\/operators\/([^/]{3,200})\/(password|disable|enable|remove)$/.exec(pathname);
834
881
  if (op && team) {
835
882
  const email = decodeURIComponent(op[1]).trim().toLowerCase();
@@ -926,6 +973,23 @@ export async function handleApi(request, response, conversations, headers, resou
926
973
  const talking = /^\/api\/conversations\/([^/]+)\/talk(\/invite|\/remind|\/react|\/pin|\/split)?$/.exec(pathname);
927
974
  if (talking && talk) {
928
975
  const conversation = decodeURIComponent(talking[1]);
976
+ /* A member (#431): it writes, as a member, and reminds -- nothing else (turning the chat on or off,
977
+ reacting or answering for the owner, pins); its right looked at again once the body is read
978
+ (audits 6, 8, 10 of the member's door). */
979
+ if (request.member) {
980
+ if (!request.member.still()) return send(403, { error: 'This conversation is not shared with you any more.' }), true;
981
+ if (talking[2] === '/remind') return send(200, await talk.remind(conversation)), true;
982
+ /* Its own conversation's chat, on or off (#431); not one it was only given. */
983
+ if (talking[2] === undefined && typeof body.on === 'boolean' && conversations.list().some((c) => c.name === conversation && c.owner === request.member.email)) { const now = await talk.set(conversation, body.on); retell(conversation); return send(200, now), true; }
984
+ if (talking[2] !== undefined || typeof body.on === 'boolean') return send(403, { error: 'This is for administrators.' }), true;
985
+ /* A sign-in code pasted while its sign-in waits: typed into its tool, never in the thread (#405) -- by a
986
+ member given its terminal only, as on its door (audit 29-11). */
987
+ if (request.member.rightsOn(request.member.key, conversation).includes('x') && conversations.signinHelp?.codeInChat(conversation, body.text, body.files)) return send(201, { ...(await conversations.signinHelp.enterCode(conversation, body.text)), told: 'signin' }), true;
988
+ const mark = `[${request.member.email}, a member]`;
989
+ const clean = (t) => String(t ?? '').replace(/[\u200B-\u200F\u2060\uFEFF]/g, '').replace(/[[\uFF3B]/g, '(');
990
+ const files = Array.isArray(body.files) ? body.files.map((f) => (f && typeof f === 'object' ? { ...f, note: `${mark} ${clean(f.note)}`.trim() } : f)) : body.files;
991
+ return send(201, await talk.say(conversation, `${mark} ${clean(body.text)}`.trim(), undefined, files, undefined, { quick: false })), true;
992
+ }
929
993
  if (talking[2] === '/invite') return send(200, await talk.invite(conversation, typeof body.lang === 'string' ? body.lang : 'en')), true;
930
994
  if (talking[2] === '/remind') return send(200, await talk.remind(conversation, { urgent: body?.urgent === true })), true;
931
995
  if (talking[2] === '/react') return send(200, await talk.react(conversation, body.to, body.reaction ?? null)), true;
@@ -972,6 +1036,8 @@ export async function handleApi(request, response, conversations, headers, resou
972
1036
  const handed = /^\/api\/conversations\/([^/]+)\/secrets$/.exec(pathname);
973
1037
  if (handed && secrets) {
974
1038
  const conversation = decodeURIComponent(handed[1]);
1039
+ /* A member: its own key to its own conversation (the table checked the conversation). */
1040
+ if (request.member && !request.member.ownsKey(String(body.secret ?? ''))) return send(403, { error: 'Only your own keys, to your own conversations.' }), true;
975
1041
  await handSecret(conversation, String(body.secret ?? ''), body.attached === true);
976
1042
  return send(200, { ok: true, secrets: secrets.of(conversation) }), true;
977
1043
  }
@@ -1035,6 +1101,9 @@ export async function handleApi(request, response, conversations, headers, resou
1035
1101
  const attach = /^\/api\/conversations\/([^/]+)\/resources$/.exec(pathname);
1036
1102
  if (attach && resources) {
1037
1103
  const conversation = decodeURIComponent(attach[1]);
1104
+ /* A member (#431 step 2): its own folder to its own conversation (the table checked the conversation), read
1105
+ or write, or taken back; never another's folder. */
1106
+ if (request.member && (!request.member.ownsAsset(String(body.resource ?? '')) || !['read', 'write', 'none', ''].includes(String(body.access ?? '')) || body.shared === true)) return send(403, { error: 'Only your own folders, to your own conversations.' }), true;
1038
1107
  await attachResource(conversation, String(body.resource ?? ''), String(body.access ?? ''), body.shared === true);
1039
1108
  return send(200, { ok: true, resources: resources.of(conversation) }), true;
1040
1109
  }
@@ -1071,6 +1140,21 @@ export async function handleApi(request, response, conversations, headers, resou
1071
1140
  await health.check(conversation, { asked: true }); return send(200, health.of(conversation)), true;
1072
1141
  }
1073
1142
  if (machine[2] === 'restart') return send(202, await conversations.restart(conversation)), true;
1143
+ /* A member, its own conversation (#431): start, stop or cut off (force) its machine -- not its size (that is counted
1144
+ against its room: later), its watchdog nor its way down. */
1145
+ /* Its size (#431): memory, disk, cores, within the room an administrator gave it for all its own together. */
1146
+ if (request.member && typeof body?.action !== 'string') {
1147
+ const m = request.member; const c = conversations.list().find((x) => x.name === conversation);
1148
+ if (!c || body?.machineMb !== undefined || body?.machineDiskGb !== undefined || body?.machineCpus !== undefined || body?.watchdog !== undefined || body?.escalate !== undefined) return send(403, { error: 'This is for administrators.' }), true;
1149
+ const quota = m.quota(); const used = m.used();
1150
+ const want = { mb: body.memoryMb ?? c.memoryMb ?? 0, diskGb: body.diskGb ?? c.diskGb ?? 0, cpus: body.cpus ?? c.cpus ?? 1 };
1151
+ const was = { mb: c.memoryMb ?? 0, diskGb: c.diskGb ?? 0, cpus: c.cpus ?? 1 };
1152
+ for (const [k, what, unit] of [['mb', 'memory', ' MB'], ['diskGb', 'disk', ' GB'], ['cpus', 'cores', '']]) {
1153
+ if (!Number.isFinite(Number(want[k]))) return send(400, { error: `Its ${what} is a number.` }), true;
1154
+ if (quota[k] > 0 && used[k] - was[k] + Number(want[k]) > quota[k]) return send(409, { error: `Not enough ${what} left: ${quota[k] - used[k] + was[k]}${unit} for this conversation, of your ${quota[k]}${unit}.` }), true;
1155
+ }
1156
+ }
1157
+ if (request.member && typeof body?.action === 'string' && !['start', 'stop', 'force'].includes(body.action)) return send(403, { error: 'This is for administrators.' }), true;
1074
1158
  /* One action on its machine, or the owner's choice for its way down (conversations.mjs, machineAction). */
1075
1159
  if (typeof body?.action === 'string') return send(202, await conversations.machineAction(conversation, body.action)), true;
1076
1160
  if (typeof body?.escalate === 'boolean') return send(200, conversations.setStopEscalate(conversation, body.escalate)), true;
@@ -1144,18 +1228,27 @@ export async function handleApi(request, response, conversations, headers, resou
1144
1228
  const action = /^\/api\/conversations\/([^/]+)\/(sleep|archive|erase)$/.exec(pathname);
1145
1229
  if (action?.[2] === 'erase' && String(body?.confirm ?? '') !== decodeURIComponent(action[1])) throw new Refusal(400, 'Type the name of the conversation to delete it for good.');
1146
1230
  if (!action) return send(404, { error: 'Not found.' }), true;
1147
- await conversations[action[2]](decodeURIComponent(action[1]));
1148
- if (action[2] === 'erase') action[2] = 'archive'; /* what it leaves behind is forgotten as for an archive */
1149
- if (action[2] === 'archive') resources?.forget(decodeURIComponent(action[1]));
1150
- if (action[2] === 'archive') gitKeeper?.forgetConversation(decodeURIComponent(action[1]));
1151
- if (action[2] === 'archive') sharing?.devices.forget(decodeURIComponent(action[1]));
1152
- if (action[2] === 'archive') secrets?.forget(decodeURIComponent(action[1]));
1153
- if (action[2] === 'archive') signin?.forget(decodeURIComponent(action[1]));
1154
- if (action[2] === 'archive') answerer?.forget(decodeURIComponent(action[1]));
1155
- if (action[2] === 'archive') wakeups?.forget(decodeURIComponent(action[1]));
1156
- if (action[2] === 'archive') talk?.forget(decodeURIComponent(action[1]));
1157
- if (action[2] === 'archive') guide?.forget(decodeURIComponent(action[1]));
1158
- if (action[2] === 'archive') health?.forget(decodeURIComponent(action[1]));
1231
+ /* The cleaning once its record is gone, even when the deleting failed half-way (audit 29-11): what it was
1232
+ given never waits for a new conversation of the same name. */
1233
+ const forget = () => {
1234
+ if (conversations.list().some((c) => c.name === decodeURIComponent(action[1]))) return;
1235
+ if (action[2] === 'erase') action[2] = 'archive'; /* what it leaves behind is forgotten as for an archive */
1236
+ if (action[2] === 'archive') resources?.forget(decodeURIComponent(action[1]));
1237
+ if (action[2] === 'archive') gitKeeper?.forgetConversation(decodeURIComponent(action[1]));
1238
+ if (action[2] === 'archive') sharing?.devices.forget(decodeURIComponent(action[1]));
1239
+ if (action[2] === 'archive') secrets?.forget(decodeURIComponent(action[1]));
1240
+ if (action[2] === 'archive') signin?.forget(decodeURIComponent(action[1]));
1241
+ if (action[2] === 'archive') answerer?.forget(decodeURIComponent(action[1]));
1242
+ /* What a member was given of it goes with it: a new conversation of that name is nobody's but its maker's (29-11). */
1243
+ if (action[2] === 'archive') team?.grants?.forgetAsset(`conversation:${decodeURIComponent(action[1])}`);
1244
+ if (action[2] === 'archive') wakeups?.forget(decodeURIComponent(action[1]));
1245
+ if (action[2] === 'archive') talk?.forget(decodeURIComponent(action[1]));
1246
+ if (action[2] === 'archive') guide?.forget(decodeURIComponent(action[1]));
1247
+ if (action[2] === 'archive') health?.forget(decodeURIComponent(action[1]));
1248
+ tethers?.forgetConversation?.(decodeURIComponent(action[1]));
1249
+ binders?.forgetConversation?.(decodeURIComponent(action[1]));
1250
+ };
1251
+ try { await conversations[action[2]](decodeURIComponent(action[1])); } finally { if (action[2] !== 'sleep') { action[2] = 'archive'; forget(); } }
1159
1252
  return send(200, { ok: true }), true;
1160
1253
  } catch (error) {
1161
1254
  /* A git failure also says which (`kind`), and an fsck id the owner may waive (`offer`). */
@@ -139,6 +139,11 @@ export class Binders {
139
139
  if (level === 'read' || level === 'write') this.#keeper.store.grant(l.id, `${AGENT}${to}`, level, keeper);
140
140
  }
141
141
  }
142
+ /* A conversation archived or deleted (audit 29-11): its lists are no longer given to its name. */
143
+ forgetConversation(name) {
144
+ const keeper = { id: 'person:keeper', kind: 'person', name: 'keeper' };
145
+ for (const l of this.#keeper.store.lists(keeper)) if (l.grants?.[`${AGENT}${name}`] !== undefined) { try { this.#keeper.store.grant(l.id, `${AGENT}${name}`, null, keeper); } catch { /* gone meanwhile */ } }
146
+ }
142
147
  /* WHAT IT WAS GIVEN, for a whole export (carry.mjs): each list by its id, with its access; and the same given
143
148
  again, on an import, where the list exists here -> the ids not found. */
144
149
  grantsOf(name) {
package/server/bridge.mjs CHANGED
@@ -133,9 +133,17 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
133
133
  still = () => ask() === name;
134
134
  } else if (url.pathname === PATH) {
135
135
  name = url.searchParams.get('c') ?? '';
136
- if (!isConversationName(name) || !originOk(request.headers) || gate(request.headers) === undefined) { socket.destroy(); return; }
137
- /* An administrator made a member, or an account disabled: its open terminals end too (#419). */
138
- still = () => gate(request.headers) !== undefined;
136
+ if (!isConversationName(name) || !originOk(request.headers)) { socket.destroy(); return; }
137
+ if (gate(request.headers) !== undefined) {
138
+ /* An administrator made a member, or an account disabled: its open terminals end too (#419). */
139
+ still = () => gate(request.headers) !== undefined;
140
+ } else {
141
+ /* A member on the common route (#431): the terminal of a conversation it was given it, only; ends when
142
+ that right goes. Its own door's path stays for its older page. */
143
+ const ask = () => memberName(request.headers, name) ?? '';
144
+ if (ask() !== name) { socket.destroy(); return; }
145
+ still = () => ask() === name;
146
+ }
139
147
  } else return;
140
148
  const cols = Number(url.searchParams.get('cols'));
141
149
  const rows = Number(url.searchParams.get('rows'));
@@ -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);
@@ -143,9 +143,10 @@ export class Dockets {
143
143
  #heard(name, e) {
144
144
  if (e.type === 'acked') { try { void Promise.resolve(this.#acked(name, { event: e.event, ack: e.ack })).catch(() => {}); } catch { /* a hook that fails stops nothing */ } }
145
145
  if (e.type === 'acked' && e.ack.kind === 'done' && hidden(e.event)) { this.#line(name, { kind: 'docket-done', text: 'Handled: a sign-in for another conversation.', topic: 'Handled', brief: 'Sign-in' }); return; }
146
- if (e.type === 'acked' && e.ack.kind === 'done') this.#line(name, { kind: 'docket-done', text: `Handled: ${cut(e.event.text, 80)}${e.ack.note ? ` -- ${cut(e.ack.note, 120)}` : ''}`, topic: 'Handled', brief: e.event.text.slice(0, 60) });
146
+ /* In the reader's words (Parley's { k, v, t }, 29-11): its English `t` where a page has no such word. */
147
+ if (e.type === 'acked' && e.ack.kind === 'done') this.#line(name, { kind: 'docket-done', text: e.ack.note ? { k: 'line-docket-done-said', v: { text: cut(e.event.text, 80), said: cut(e.ack.note, 120) }, t: `Handled: ${cut(e.event.text, 80)} -- ${cut(e.ack.note, 120)}` } : { k: 'line-docket-done', v: { text: cut(e.event.text, 80) }, t: `Handled: ${cut(e.event.text, 80)}` }, topic: { k: 'line-topic-docket-done', t: 'Handled' }, brief: e.event.text.slice(0, 60) });
147
148
  if (e.type === 'acked' && e.ack.kind === 'failed') {
148
- this.#line(name, { kind: 'docket-failed', text: `Could not be handled: ${e.event.text} -- ${e.ack.note}`, tone: 'warn', topic: 'Not handled' });
149
+ this.#line(name, { kind: 'docket-failed', text: { k: 'line-docket-failed', v: { text: e.event.text, said: e.ack.note }, t: `Could not be handled: ${e.event.text} -- ${e.ack.note}` }, tone: 'warn', topic: { k: 'line-topic-docket-failed', t: 'Not handled' } });
149
150
  try { this.#alert({ title: `${name}: could not be handled`, body: `${e.event.text}: ${e.ack.note}`, url: `/?c=${name}` }); } catch { /* as said */ }
150
151
  }
151
152
  if (e.type === 'planned') this.#line(name, { kind: 'docket-reminder', text: `Reminder set by ${this.#setBy.has(e.plan.id) ? `API key "${this.#setBy.get(e.plan.id)}"` : 'the tool'}: ${e.plan.text} (${e.plan.cron ? `"${e.plan.cron}", next ` : ''}${new Date(e.plan.next ?? e.plan.due).toISOString().slice(0, 16).replace('T', ' ')} UTC)`, topic: 'Reminder' });
@@ -182,7 +183,7 @@ export class Dockets {
182
183
  const t = told[e.id];
183
184
  if (t && t.count >= TOLD_MAX && !t.said && now - t.at >= AGAIN_MS) {
184
185
  if (waiting.some((o) => told[o.id]?.said === true)) { t.said = 'grouped'; grouped += 1; continue; }
185
- this.#line(name, { kind: 'docket-unhandled', text: `Not handled, told ${t.count} times: ${e.text}`, tone: 'warn', topic: 'Not handled' });
186
+ this.#line(name, { kind: 'docket-unhandled', text: { k: 'line-docket-unhandled', v: { count: t.count, text: e.text }, t: `Not handled, told ${t.count} times: ${e.text}` }, tone: 'warn', topic: { k: 'line-topic-docket-unhandled', t: 'Not handled' } });
186
187
  t.said = true;
187
188
  }
188
189
  }
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,21 @@ 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
+ return send(201, await memberCreate({ conversations, talk, person, body: await readJson(request) }));
172
+ }
164
173
  if (request.method === 'GET' && route === '/me') {
165
174
  /* `conversations`: all this pairing may use. `shared`: what it was given for itself. */
166
175
  /* `terminal` and `chat`: the parts it was given, for the page to show only those. */
167
176
  /* Each attached one with its type: the page draws it as the asset it is (assets step 6). */
168
177
  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 });
178
+ 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
179
  }
171
180
  /* The files a device was given for itself need no conversation; everything else does. */
172
181
  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';
@@ -287,3 +296,39 @@ export async function handleDoor(request, response, { devices, conversations, re
287
296
  return send(500, { error: 'Something failed on the server.' });
288
297
  }
289
298
  }
299
+
300
+ /* A MEMBER MAKES A CONVERSATION OF ITS OWN (29-11), through its door or the application's route (#431): a
301
+ name and a tool, under the memory, disk and cores an administrator gave it for all of them together. It signs
302
+ in to its own AI account there; nothing else is set here (no folder, no key, no shared machine). */
303
+ export async function memberCreate({ conversations, talk, person, body }) {
304
+ if (!person.still()) throw new Refusal(403, 'This account may not use this page now.');
305
+ const quota = person.quota();
306
+ if (!(quota.mb > 0)) throw new Refusal(403, 'An administrator has not let you make conversations.');
307
+ const tool = conversations.tools().find((t) => t.id === body.tool);
308
+ if (!tool) throw new Refusal(400, 'Choose an AI.');
309
+ 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) };
310
+ /* Its own room said first (the server's memory after): what the member can act on. Counted again after
311
+ the wait, just before it is made: two at once never go past it together. */
312
+ const room = () => {
313
+ const used = person.used();
314
+ const over = [['mb', 'memory', 'MB'], ['diskGb', 'disk', 'GB'], ['cpus', 'cores', '']].find(([k]) => quota[k] > 0 && used[k] + want[k] > quota[k]);
315
+ 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}` : ''}.`); }
316
+ };
317
+ room();
318
+ await conversations.admit?.({ title: body.title, tool: tool.id, memoryMb: want.mb });
319
+ room();
320
+ 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 });
321
+ person.own(made.name);
322
+ /* Its chat on once it is built, as for one an administrator makes. */
323
+ if (talk) {
324
+ const until = Date.now() + 30 * 60_000;
325
+ const on = async () => {
326
+ const c = conversations.list().find((x) => x.name === made.name);
327
+ if (!c || Date.now() > until) return;
328
+ if (c.phase === 'ready') { try { await talk.set(made.name, true); } catch { /* turned on from its settings */ } return; }
329
+ setTimeout(() => { void on(); }, 2000).unref?.();
330
+ };
331
+ void on();
332
+ }
333
+ return { name: made.name, title: made.title, tool: made.tool, memoryMb: made.memoryMb };
334
+ }
package/server/files.mjs CHANGED
@@ -31,7 +31,8 @@ export function isFileName(name) {
31
31
 
32
32
  /* The real path of `relative` under `root`, or a refusal. */
33
33
  export async function inside(root, relative) {
34
- const base = await realpath(root);
34
+ /* A folder not made yet (a work folder before its first start): said as missing, not a failure (audit 29-11). */
35
+ const base = await realpath(root).catch(() => { throw new Refusal(404, 'No such file or folder.'); });
35
36
  let real;
36
37
  try { real = await realpath(join(base, String(relative ?? ''))); }
37
38
  catch { throw new Refusal(404, 'No such file or folder.'); }
@@ -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`;