clavarium 0.2.216-beta.1 → 0.2.217-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.216-beta.1",
3
+ "version": "0.2.217-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.216-beta.1",
9
+ "version": "0.2.217-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -14,7 +14,7 @@
14
14
  "clavarium-binder": "0.1.63-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
16
  "clavarium-parley": "0.17.95-next.1",
17
- "clavarium-tether": "0.1.0-next.68",
17
+ "clavarium-tether": "0.1.0-next.70",
18
18
  "mammoth": "1.13.0",
19
19
  "mermaid": "11.17.2",
20
20
  "node-pty": "^1.1.0",
@@ -800,9 +800,9 @@
800
800
  }
801
801
  },
802
802
  "node_modules/clavarium-tether": {
803
- "version": "0.1.0-next.68",
804
- "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.68.tgz",
805
- "integrity": "sha512-SVPlyIGWSRUkS0G7OCca38xru05NMxCgc7XSR7pBDetNhdGKJFlSG3p3ZsjY6p5iCdgfpjSFhAyH/VnDFHdMoQ==",
803
+ "version": "0.1.0-next.70",
804
+ "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.70.tgz",
805
+ "integrity": "sha512-W8lJN/xNh3az7tc9c8OImvkBD7FWogxqiFJcLDqk+ZzrQoxTyGbj40s+tZ4Z+QSwn9wuItfLy22n0EPIvQqhog==",
806
806
  "license": "MIT",
807
807
  "bin": {
808
808
  "tether": "bin/cli.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.216-beta.1",
3
+ "version": "0.2.217-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.",
@@ -48,7 +48,7 @@
48
48
  "clavarium-binder": "0.1.63-next.1",
49
49
  "clavarium-docket": "0.1.2-next.2",
50
50
  "clavarium-parley": "0.17.95-next.1",
51
- "clavarium-tether": "0.1.0-next.68",
51
+ "clavarium-tether": "0.1.0-next.70",
52
52
  "mammoth": "1.13.0",
53
53
  "mermaid": "11.17.2",
54
54
  "node-pty": "^1.1.0",
package/server/agenda.mjs CHANGED
@@ -73,6 +73,9 @@ const timeOf = (v) => {
73
73
  };
74
74
  /* An online meeting's link: a web address, nothing else (never a script's). */
75
75
  const linkOf = (v) => { try { const u = new URL(String(v ?? '')); return u.protocol === 'https:' ? u.href.slice(0, 2000) : null; } catch { return null; } };
76
+ /* An invitation's text, as text: lines kept, control characters dropped, short. The page shows it as text only. */
77
+ export const NOTES_MAX = 2000;
78
+ const notesOf = (v) => String(v ?? '').replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, '').replace(/\n{3,}/g, '\n\n').trim().slice(0, NOTES_MAX);
76
79
  const SHOW = { busy: 'busy', free: 'free', tentative: 'tentative', oof: 'away', away: 'away', workingelsewhere: 'elsewhere', elsewhere: 'elsewhere' };
77
80
 
78
81
  /* One event Tether handed as data, kept to the fields the page shows. */
@@ -83,7 +86,7 @@ export function eventOf(e) {
83
86
  const n = Number(e.attendees);
84
87
  return {
85
88
  id: line(e.id, 2048), title: line(e.title) || '(no title)', start, end: timeOf(e.end), allDay,
86
- location: line(e.location), organizer: line(e.organizer, 320), online: linkOf(e.online),
89
+ location: line(e.location), organizer: line(e.organizer, 320), online: linkOf(e.online), notes: notesOf(e.notes),
87
90
  attendees: Number.isInteger(n) && n >= 0 ? n : null, show: SHOW[String(e.show ?? '').toLowerCase()] ?? null,
88
91
  };
89
92
  }
package/server/api.mjs CHANGED
@@ -541,8 +541,10 @@ export async function handleApi(request, response, conversations, headers, resou
541
541
  provider. A page, not JSON; its state is the proof it was started from this page. */
542
542
  if (pathname === BACK_PATH && tethers?.oauth) {
543
543
  let page;
544
- try { const done = await tethers.oauth.finish({ tethers }, { code: query.get('code'), state: query.get('state'), error: query.get('error') }); page = backPage({ ok: true, title: done.title }); }
545
- catch (error) { page = backPage({ ok: false, message: error instanceof Refusal ? error.message : 'The sign-in failed.' }); }
544
+ /* Said in the language of the page that started it; one never started here, in the browser's. */
545
+ const lang = String(request.headers['accept-language'] ?? '').slice(0, 2);
546
+ try { const done = await tethers.oauth.finish({ tethers }, { code: query.get('code'), state: query.get('state'), error: query.get('error') }); page = backPage({ ok: true, title: done.title, lang: done.lang, back: done.back, sameTab: done.sameTab }); }
547
+ catch (error) { page = backPage({ ok: false, message: error instanceof Refusal ? error.message : '', why: error?.why ?? 'failed', lang: error?.lang ?? lang, back: error?.back }); }
546
548
  response.writeHead(200, { ...headers, 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'referrer-policy': 'no-referrer' }).end(page);
547
549
  return true;
548
550
  }
@@ -14,10 +14,21 @@
14
14
  * answers a fresh access token, refreshed here first when it is near its end. No token is ever logged, said in
15
15
  * an error or returned by a route.
16
16
  *
17
+ * A CLIENT THE OWNER PASTED (16-11): a service that registers no client by itself (Slack, GitHub...) is given an
18
+ * app once by its owner, its client id AND secret pasted in the page. Both are kept host-only in the vault
19
+ * (MCP_<ID>_CLI), never sent back to the page, never to an AI; the token endpoint is shown the secret the way
20
+ * the service's metadata says (token_endpoint_auth_methods_supported: client_secret_post, else _basic, the
21
+ * default of RFC 8414). The permissions asked are those the owner kept (by default those the server's metadata
22
+ * lists); a refusal for them is said plainly.
23
+ *
24
+ * RECONNECT (16-11): Tether, refused with a token, asks once for a fresh one (access(name, { fresh: true })):
25
+ * refreshed here when it can be; when it cannot, the error carries `reconnect` and Tether shows the server as
26
+ * "to reconnect". Reconnecting is always the owner's own click (the same sign-in, the client kept).
27
+ *
17
28
  * `fetch` is injected, so the tests run against a fake authorization server with no network. */
18
29
  import { Refusal } from './conversations.mjs';
19
30
  import { pkcePair, newState } from './oauth.mjs';
20
- import { KEY_PREFIX, keyName, oauthName } from './mcpx.mjs';
31
+ import { KEY_PREFIX, keyName, oauthName, clientName } from './mcpx.mjs';
21
32
 
22
33
  export const TOKEN_SUFFIX = '_TOK';
23
34
  export const BACK_PATH = '/api/tether/mcp-oauth/back';
@@ -28,6 +39,22 @@ const FETCH_MS = 15_000;
28
39
  /* Refreshed this long before its end: a call that starts now still has a valid token when it lands. */
29
40
  const EARLY_MS = 60_000;
30
41
  const KIND = 'mcp-oauth';
42
+ const CLIENT_KIND = 'mcp-client';
43
+ /* A scope as RFC 6749 s.3.3 writes one: printable, no space, no quote or backslash. */
44
+ const SCOPE_OK = /^[\x21\x23-\x5B\x5D-\x7E]{1,200}$/;
45
+ const scopeList = (x) => [...new Set((Array.isArray(x) ? x : String(x ?? '').split(/[\s,]+/)).map((v) => String(v).trim()).filter((v) => SCOPE_OK.test(v)))].slice(0, 100);
46
+ /* Where the owner's browser goes back to after (a path of this site only), and the language it is said in. */
47
+ const backOf = (x) => { const b = String(x ?? ''); return /^\/(?![/\\])[^\s]{0,499}$/.test(b) ? b : '/'; };
48
+ const langOf = (x) => (String(x ?? '').toLowerCase().split('-')[0] === 'fr' ? 'fr' : 'en');
49
+ /* An error code a provider says back, kept only when it is one plain word. */
50
+ const codeOf = (x) => (/^[a-z_.]{1,60}$/.test(String(x ?? '')) ? String(x) : '');
51
+ /* What a provider's refusal means for the owner: the page says it in their words (backPage). */
52
+ function whyOf(code) {
53
+ if (code === 'invalid_scope') return 'scope';
54
+ if (['invalid_client', 'unauthorized_client', 'bad_client_secret', 'invalid_client_id', 'bad_redirect_uri', 'invalid_redirect_uri'].includes(code)) return 'client';
55
+ if (code === 'access_denied') return 'denied';
56
+ return 'failed';
57
+ }
31
58
 
32
59
  /* The vault's name for a server's tokens: as long as its key's name, so every server id fits. */
33
60
  export const tokenName = oauthName;
@@ -117,7 +144,11 @@ export class McpOAuth {
117
144
  if (!meta || !safeUrl(meta.authorization_endpoint, allowHttp) || !safeUrl(meta.token_endpoint, allowHttp)) throw new Refusal(502, 'This server does not say how to sign in (no OAuth metadata).');
118
145
  if (Array.isArray(meta.code_challenge_methods_supported) && !meta.code_challenge_methods_supported.includes('S256')) throw new Refusal(502, 'This server does not offer PKCE (S256): refused.');
119
146
  const resource = oneLine(prm?.resource || server.href, 1000);
120
- return { resource, meta, scope: scope || (Array.isArray(prm?.scopes_supported) ? prm.scopes_supported.map(String).join(' ').slice(0, 1000) : '') };
147
+ /* What may be asked: the 401's scope, else what the resource's metadata lists (never the authorization
148
+ server's whole list: a service's app holds only some of them). */
149
+ const listed = scopeList(prm?.scopes_supported);
150
+ const scopes = scope ? scopeList(scope) : listed;
151
+ return { resource, meta, scope: scopes.join(' ').slice(0, 1000), scopes: [...new Set([...scopes, ...listed])] };
121
152
  }
122
153
 
123
154
  /* A client registered by itself (RFC 7591), public (no secret) where the server allows it. */
@@ -130,11 +161,13 @@ export class McpOAuth {
130
161
  } catch { throw new Refusal(502, 'The server\'s registration could not be reached.'); }
131
162
  const j = await res.json().catch(() => null);
132
163
  if (!res.ok || !j?.client_id) throw new Refusal(502, `The server refused to register this Clavarium (HTTP ${res.status}).`);
133
- return { clientId: oneLine(j.client_id, 500), clientSecret: typeof j.client_secret === 'string' ? j.client_secret : '' };
164
+ return { clientId: oneLine(j.client_id, 500), clientSecret: typeof j.client_secret === 'string' ? j.client_secret : '', registered: true };
134
165
  }
135
166
 
136
- /* START: { target, clientId?, clientSecret? } and this server's address -> { url } to open, or { need: 'client' }
137
- when the server registers no client by itself (the page then asks for its id). */
167
+ /* START: { target, clientId?, clientSecret?, scope?, lang?, back?, tab? } and this server's address -> { url } to
168
+ open, or { need: 'client', secret, redirect, scopes } when the server registers no client by itself: the page
169
+ then asks for its id and, when the service wants one, its secret (`redirect`: the address its app must name;
170
+ `missing: 'secret'` when only the secret lacks). A client pasted once is kept host-only: no paste after. */
138
171
  async start({ tethers }, body = {}, origin = '') {
139
172
  const t = tethers.store().target(String(body.target ?? ''));
140
173
  if (!t || t.kind !== 'mcp') throw new Refusal(404, 'No such MCP server.');
@@ -142,12 +175,28 @@ export class McpOAuth {
142
175
  const back = safeUrl(`${String(origin).replace(/\/+$/, '')}${BACK_PATH}`, true);
143
176
  if (!back) throw new Refusal(500, 'This server does not know its own address.');
144
177
  const redirectUri = back.href;
145
- const { resource, meta, scope } = await this.discover(t.config?.url, { allowHttp });
146
- let client = null;
178
+ const { resource, meta, scope: asked, scopes } = await this.discover(t.config?.url, { allowHttp });
179
+ const methods = Array.isArray(meta.token_endpoint_auth_methods_supported) ? meta.token_endpoint_auth_methods_supported.map(String) : [];
180
+ /* A secret is needed unless the service says it takes public clients ("none"). */
181
+ const wantsSecret = !methods.includes('none');
182
+ const need = { need: 'client', secret: wantsSecret, redirect: redirectUri, scopes };
183
+ const kept = this.#client(t.id);
147
184
  const given = oneLine(body.clientId, 500);
148
- if (given) client = { clientId: given, clientSecret: typeof body.clientSecret === 'string' ? body.clientSecret.trim() : '' };
185
+ const secret = typeof body.clientSecret === 'string' ? body.clientSecret.trim() : '';
186
+ if (/[\r\n]/.test(secret) || secret.length > 2000) throw new Refusal(400, 'A client secret is one line.');
187
+ let client = null;
188
+ if (given) client = { clientId: given, clientSecret: secret || (kept?.clientId === given ? kept.clientSecret : '') };
189
+ else if (kept) client = { clientId: kept.clientId, clientSecret: kept.clientSecret };
149
190
  else client = await this.#register(meta, redirectUri, allowHttp);
150
- if (!client) return { need: 'client' };
191
+ if (!client) return need;
192
+ if (wantsSecret && !client.clientSecret && !client.registered) return { ...need, missing: 'secret' };
193
+ /* The permissions: those the owner kept now, else those kept with the client, else what the server asks. */
194
+ const keptScope = body.scope !== undefined ? scopeList(body.scope) : null;
195
+ const scope = (keptScope ?? (kept?.scope !== undefined ? scopeList(kept.scope) : scopeList(asked))).join(' ').slice(0, 2000);
196
+ const auth = !client.clientSecret ? 'none' : methods.includes('client_secret_post') ? 'post' : methods.includes('client_secret_basic') || !methods.length ? 'basic' : '';
197
+ if (!auth) throw new Refusal(502, 'This service wants a way of proving the client that Clavarium does not offer.');
198
+ /* Pasted: kept host-only, with the permissions kept, for every sign-in after. */
199
+ if (given || (keptScope && kept)) this.#keepClient(t.id, { clientId: client.clientId, clientSecret: client.clientSecret, scope });
151
200
  this.#sweep();
152
201
  if (this.#pending.size >= PENDING_MAX) throw new Refusal(429, 'Too many sign-ins in progress; try again shortly.');
153
202
  const state = newState();
@@ -155,12 +204,22 @@ export class McpOAuth {
155
204
  const url = new URL(meta.authorization_endpoint);
156
205
  const ask = { response_type: 'code', client_id: client.clientId, redirect_uri: redirectUri, state, code_challenge: challenge, code_challenge_method: 'S256', resource, ...(scope ? { scope } : {}) };
157
206
  for (const [k, v] of Object.entries(ask)) url.searchParams.set(k, v);
158
- const methods = Array.isArray(meta.token_endpoint_auth_methods_supported) ? meta.token_endpoint_auth_methods_supported : [];
159
- const auth = !client.clientSecret ? 'none' : methods.includes('client_secret_post') || !methods.length ? 'post' : 'basic';
160
- this.#pending.set(state, { target: t.id, title: t.title, url: t.config.url, allowHttp, redirectUri, verifier, resource, scope, token: meta.token_endpoint, ...client, auth, at: this.#now() });
207
+ const { registered, ...plain } = client;
208
+ this.#pending.set(state, { target: t.id, title: t.title, url: t.config.url, allowHttp, redirectUri, verifier, resource, scope, token: meta.token_endpoint, ...plain, auth,
209
+ lang: langOf(body.lang), back: backOf(body.back), sameTab: body.tab === 'same', at: this.#now() });
161
210
  return { url: url.href };
162
211
  }
163
212
 
213
+ /* The client the owner pasted for a server, from the vault: { clientId, clientSecret, scope? } or null. */
214
+ #client(id) {
215
+ let raw;
216
+ try { raw = this.#secrets.reveal(clientName(id)); } catch { return null; }
217
+ try { const r = JSON.parse(String(raw ?? '')); return r?.kind === CLIENT_KIND && typeof r.clientId === 'string' && r.clientId ? r : null; } catch { return null; }
218
+ }
219
+ #keepClient(id, { clientId, clientSecret, scope }) {
220
+ this.#secrets.set({ name: clientName(id), value: JSON.stringify({ kind: CLIENT_KIND, clientId, clientSecret, scope }), hostOnly: true });
221
+ }
222
+
164
223
  #sweep() { for (const [k, p] of this.#pending) if (this.#now() - p.at > PENDING_MS) this.#pending.delete(k); }
165
224
 
166
225
  /* The token endpoint, by the client's way of proving itself. Never says back what it was sent or answered. */
@@ -172,10 +231,14 @@ export class McpOAuth {
172
231
  else { form.set('client_id', rec.clientId); if (rec.auth === 'post') form.set('client_secret', rec.clientSecret); }
173
232
  let res;
174
233
  try { res = await this.#get(rec.token, { method: 'POST', headers, body: form.toString() }); } catch { throw new Refusal(502, 'The sign-in server could not be reached.'); }
175
- const j = await res.json().catch(() => null);
176
- if (!res.ok || typeof j?.access_token !== 'string' || !j.access_token) {
177
- const why = /^[a-z_]{1,40}$/.test(String(j?.error ?? '')) ? j.error : `HTTP ${res.status}`;
178
- throw Object.assign(new Refusal(502, `The sign-in server refused (${why}).`), { grant: why === 'invalid_grant' });
234
+ const raw = await res.json().catch(() => null);
235
+ /* Some services answer 200 { ok: false, error } (Slack); some put a user's token under authed_user. */
236
+ const j = raw && typeof raw.access_token !== 'string' && raw.authed_user && typeof raw.authed_user.access_token === 'string' ? { ...raw.authed_user, ok: raw.ok } : raw;
237
+ if (!res.ok || j?.ok === false || typeof j?.access_token !== 'string' || !j.access_token) {
238
+ const code = codeOf(j?.error);
239
+ const why = whyOf(code);
240
+ const said = why === 'client' ? 'The service refused the client id or secret' : why === 'scope' ? 'The service refused the permissions asked' : 'The sign-in server refused';
241
+ throw Object.assign(new Refusal(502, `${said} (${code || `HTTP ${res.status}`}).`), { grant: code === 'invalid_grant' || code === 'invalid_refresh_token', why });
179
242
  }
180
243
  if (/[\r\n]/.test(j.access_token)) throw new Refusal(502, 'The sign-in server answered a token that is not one line.');
181
244
  const life = Number(j.expires_in);
@@ -198,29 +261,35 @@ export class McpOAuth {
198
261
  async finish({ tethers }, { code, state, error } = {}) {
199
262
  this.#sweep();
200
263
  const p = state ? this.#pending.get(String(state)) : null;
201
- if (!p) throw new Refusal(400, 'This sign-in has expired or was already used; start it again.');
264
+ if (!p) throw Object.assign(new Refusal(400, 'This sign-in has expired or was already used; start it again.'), { why: 'expired' });
202
265
  this.#pending.delete(String(state));
203
- if (error) throw new Refusal(400, /^[a-z_]{1,40}$/.test(String(error)) ? `The sign-in was not allowed (${error}).` : 'The sign-in was not allowed.');
204
- if (!code) throw new Refusal(400, 'The provider sent back no code.');
205
- const got = await this.#token(p, { grant_type: 'authorization_code', code: String(code), redirect_uri: p.redirectUri, code_verifier: p.verifier }, p.allowHttp);
266
+ /* Said in the owner's language, and back to where they were, whatever comes next. */
267
+ const said = (e) => Object.assign(e, { lang: p.lang, back: p.back, sameTab: p.sameTab, why: e.why ?? 'failed' });
268
+ if (error) { const c = codeOf(error); throw said(Object.assign(new Refusal(400, c ? `The sign-in was not allowed (${c}).` : 'The sign-in was not allowed.'), { why: whyOf(c || 'access_denied') })); }
269
+ if (!code) throw said(new Refusal(400, 'The provider sent back no code.'));
270
+ let got;
271
+ try { got = await this.#token(p, { grant_type: 'authorization_code', code: String(code), redirect_uri: p.redirectUri, code_verifier: p.verifier }, p.allowHttp); } catch (e) { throw said(e); }
206
272
  const name = tokenName(p.target);
207
273
  this.#keep(name, { ...p, ...got });
208
274
  const before = tethers.store().target(p.target);
209
275
  /* Its key, if it had one kept here, is no longer used: it goes. The header for a key goes too (a token is Bearer). */
210
276
  const r = await tethers.act('mcp-add', { id: p.target, name: before?.title ?? p.title, url: before?.config?.url ?? p.url, secret: name, ...(p.allowHttp ? { allowHttp: true } : {}) }, '');
211
- if (!r.ok) throw new Refusal(400, 'Signed in, but the server could not be set again.');
277
+ if (!r.ok) throw said(new Refusal(400, 'Signed in, but the server could not be set again.'));
212
278
  if (before?.secrets?.token === keyName(p.target)) { try { this.#secrets.remove(keyName(p.target)); } catch { /* not there */ } }
213
- return { target: p.target, title: before?.title ?? p.title };
279
+ return { target: p.target, title: before?.title ?? p.title, lang: p.lang, back: p.back, sameTab: p.sameTab };
214
280
  }
215
281
 
216
282
  /* THE CONNECTOR'S TOKEN (tethers.mjs, reveal): a fresh access token for a name of ours, refreshed first when near
217
- its end; undefined for any other secret (revealed as it is). One refresh at a time per server. */
218
- async access(name) {
283
+ its end -- or at once with `fresh` (the server refused the one it had: revoked before its end); undefined for
284
+ any other secret (revealed as it is). One refresh at a time per server. Signed out for good: an error that
285
+ carries `reconnect` (Tether then shows the server as to reconnect, and tells its AIs so). */
286
+ async access(name, { fresh = false } = {}) {
219
287
  if (!isTokenName(name)) return undefined;
220
288
  const rec = this.#open(name);
221
289
  if (!rec) return undefined;
222
- if (!rec.expiresAt || rec.expiresAt - EARLY_MS > this.#now()) return rec.access;
223
- if (!rec.refresh) throw new Error('signed out of this server: sign in again in Assets > Access');
290
+ if (!fresh && (!rec.expiresAt || rec.expiresAt - EARLY_MS > this.#now())) return rec.access;
291
+ const out = () => Object.assign(new Error('signed out of this server: its owner must reconnect it (Assets > Access)'), { reconnect: true });
292
+ if (!rec.refresh) throw out();
224
293
  let running = this.#refreshing.get(name);
225
294
  if (!running) {
226
295
  running = (async () => {
@@ -230,7 +299,7 @@ export class McpOAuth {
230
299
  this.#keep(name, { ...rec, ...got, refresh: got.refresh || rec.refresh });
231
300
  return got.access;
232
301
  } catch (e) {
233
- if (e?.grant) throw new Error('signed out of this server: sign in again in Assets > Access');
302
+ if (e?.grant || e?.why === 'client') throw out();
234
303
  throw new Error(`could not refresh the sign-in: ${e?.message ?? 'failed'}`);
235
304
  } finally { this.#refreshing.delete(name); }
236
305
  })();
@@ -240,11 +309,27 @@ export class McpOAuth {
240
309
  }
241
310
  }
242
311
 
243
- /* The page the owner's browser lands on: said plainly, nothing to copy, no script. */
244
- export function backPage({ ok, title = '', message = '' }) {
312
+ /* The page the owner's browser lands on: said plainly in their language (16-11), nothing to copy, no script. Opened
313
+ in its own tab, it says to go back; in the page's own tab (a phone that opened no new one), it goes back by itself
314
+ to where the owner was (`back`, a path of this site). */
315
+ const BACK_WORDS = {
316
+ en: { ok: 'Connected to {title}.', close: 'You can close this tab and go back to Clavarium.', go: 'Back to Clavarium', expired: 'This sign-in has expired or was already used. Start it again.',
317
+ denied: 'Sign-in cancelled. Nothing changed.', scope: 'The service refused the permissions asked. Keep only those its app has, then try again.',
318
+ client: 'The service refused the client id or secret. Check them, then try again.', failed: 'The sign-in failed.' },
319
+ fr: { ok: 'Connecté à {title}.', close: 'Vous pouvez fermer cet onglet et revenir à Clavarium.', go: 'Revenir à Clavarium', expired: 'Cette connexion a expiré ou a déjà servi. Recommencez.',
320
+ denied: 'Connexion annulée. Rien n\'a changé.', scope: 'Le service refuse les autorisations demandées. Gardez seulement celles de son appli, puis réessayez.',
321
+ client: 'Le service refuse l\'identifiant ou le secret client. Vérifiez-les, puis réessayez.', failed: 'La connexion a échoué.' },
322
+ };
323
+ export function backPage({ ok, title = '', message = '', why = '', lang = 'en', back = '', sameTab = false }) {
245
324
  const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
246
- const said = ok ? `Signed in to ${esc(title)}. You can close this tab.` : esc(message || 'The sign-in failed.');
247
- return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Clavarium</title>`
248
- + '<style>body{font:16px/1.5 system-ui,sans-serif;margin:0;padding:48px 16px;background:#fff;color:#222}@media (prefers-color-scheme: dark){body{background:#16181c;color:#eee}}main{max-width:32rem;margin:auto}</style>'
249
- + `</head><body><main><p>${said}</p></main></body></html>`;
325
+ const w = BACK_WORDS[langOf(lang)];
326
+ const to = backOf(back);
327
+ const lead = ok ? w.ok.replace('{title}', title) : (w[why] && why !== 'failed' ? w[why] : (message || w.failed));
328
+ /* The provider's own word (its error code), under the plain sentence. */
329
+ const detail = !ok && w[why] && why !== 'failed' && message ? `<p class="d">${esc(message)}</p>` : '';
330
+ const more = ok && !sameTab ? `<p>${esc(w.close)}</p>` : '';
331
+ const refresh = ok && sameTab ? `<meta http-equiv="refresh" content="1;url=${esc(to)}">` : '';
332
+ return `<!doctype html><html lang="${langOf(lang)}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">${refresh}<title>Clavarium</title>`
333
+ + '<style>body{font:16px/1.5 system-ui,sans-serif;margin:0;padding:48px 16px;background:#fff;color:#222}a{color:inherit}.d{opacity:.7;font-size:14px}@media (prefers-color-scheme: dark){body{background:#16181c;color:#eee}}main{max-width:32rem;margin:auto}</style>'
334
+ + `</head><body><main><p>${esc(lead)}</p>${detail}${more}<p><a href="${esc(to)}">${esc(w.go)}</a></p></main></body></html>`;
250
335
  }
package/server/mcpx.mjs CHANGED
@@ -149,10 +149,15 @@ export async function mcpSeen({ tethers }, body = {}) {
149
149
 
150
150
  /* The vault's name for a server's OAuth tokens (mcpoauth.mjs): as long as its key's name. */
151
151
  export const oauthName = (id) => `${keyName(id).slice(0, -KEY_SUFFIX.length)}_TOK`;
152
+ /* The vault's name for the client the owner pasted for it (an id and a secret, 16-11): host-only too. */
153
+ export const clientName = (id) => `${keyName(id).slice(0, -KEY_SUFFIX.length)}_CLI`;
152
154
 
153
- /* A server taken away: its key goes with it, or its OAuth tokens (only those kept for it here). */
155
+ /* A server taken away: its key goes with it, or its OAuth tokens (only those kept for it here), and its client. */
154
156
  export function forgetKey(secrets, target) {
155
- const ref = target?.kind === 'mcp' ? String(target.secrets?.token ?? '') : '';
157
+ if (target?.kind !== 'mcp') return;
158
+ /* The client pasted for it goes as well, signed in or not. */
159
+ try { secrets?.remove(clientName(target.id)); } catch { /* not there */ }
160
+ const ref = String(target.secrets?.token ?? '');
156
161
  if (!ref || (ref !== keyName(target.id) && ref !== oauthName(target.id))) return;
157
162
  try { secrets?.remove(ref); } catch { /* not there */ }
158
163
  }
@@ -196,7 +196,12 @@ export const SETTINGS_WORDS_FR = {
196
196
  'set-mcp-need': 'Collez le bloc, ou donnez nom et adresse.', 'set-mcp-tools': 'Outils', 'set-mcp-refresh': 'Actualiser', 'set-mcp-seen': 'Marquer comme vu',
197
197
  'set-mcp-none': 'Aucun outil listé pour l\'instant.', 'set-mcp-unreached': 'Injoignable : {why}', 'set-mcp-open': 'atteint l\'extérieur',
198
198
  'set-mcp-fresh': 'Nouveau : demandé jusqu\'à ce que vous l\'ayez vu',
199
- 'set-mcp-oauth': 'Se connecter (OAuth)', 'set-mcp-client': 'Identifiant client', 'set-mcp-client-need': 'Collez son identifiant client.',
199
+ 'set-mcp-oauth': 'Se connecter', 'set-mcp-client': 'Identifiant client', 'set-mcp-client-need': 'Collez son identifiant et son secret, une fois.',
200
+ /* Its client pasted once, the permissions asked, signed out (16-11). */
201
+ 'set-mcp-reconnect': 'Reconnecter', 'set-mcp-client-box': 'Identifiant et secret client', 'set-mcp-secret': 'Secret client',
202
+ 'set-mcp-scopes': 'Autorisations demandées', 'set-mcp-redirect': 'Adresse de retour de son appli', 'set-mcp-client-kept': 'Gardés sur le serveur. Aucune IA ne les voit.',
203
+ 'set-mcp-secret-need': 'Collez aussi son secret client.', 'set-ap-edit': 'Modifier', 'set-ap-send-edited': 'Accepter ainsi modifié',
204
+ 'set-mcp-guess': 'semble seulement lire', 'set-mcp-out': '{name} est déconnecté. Reconnectez-le.',
200
205
  'set-mcp-c-read': 'Lecture seule', 'set-mcp-c-write': 'Écrit', 'set-mcp-c-destructive': 'Supprime ou écrase',
201
206
  'set-mcp-custom': 'Droits personnalisés', 'set-mcp-yes': 'Oui', 'set-mcp-ask': 'Demander', 'set-mcp-no': 'Non',
202
207
  'set-rt-mcp-none': 'Coupé', 'set-rt-mcp-watch': 'Lit', 'set-rt-mcp-propose': 'Tout, approuvé', 'set-rt-mcp-free': 'Tout', 'set-rt-mcp-frame': 'Personnalisé',
@@ -305,7 +310,7 @@ export const SETTINGS_WORDS_FR = {
305
310
  'set-ag-failed': 'Agenda illisible pour le moment.', 'set-ag-none': 'Aucun événement cette semaine', 'set-ag-free-day': 'Rien aujourd\'hui',
306
311
  'set-ag-more': 'Certains événements ne sont pas affichés', 'set-ag-partial': 'Heures de début seules, pour l\'instant',
307
312
  'set-ag-when': 'Quand', 'set-ag-where': 'Où', 'set-ag-link': 'Lien', 'set-ag-join': 'Rejoindre en ligne', 'set-ag-organizer': 'Organisateur',
308
- 'set-ag-guests': 'Invités', 'set-ag-shown': 'Affiché comme', 'set-ag-show-free': 'Libre', 'set-ag-show-tentative': 'Provisoire',
313
+ 'set-ag-guests': 'Invités', 'set-ag-notes': 'Invitation', 'set-ag-shown': 'Affiché comme', 'set-ag-show-free': 'Libre', 'set-ag-show-tentative': 'Provisoire',
309
314
  'set-ag-show-away': 'Absent', 'set-ag-show-elsewhere': 'Ailleurs',
310
315
  'set-ml-short': 'Manque de mémoire', 'set-ml-short-what': 'La plus grosse machine', 'set-ml-force': 'Forcer l’arrêt', 'set-ml-sleep': 'Mettre en veille', 'set-ml-alert': 'Alerter seulement',
311
316
  };
@@ -121,7 +121,7 @@ export class Tethers {
121
121
  this.#resources = resources; this.#conversations = conversations; this.#secrets = secrets; this.#dockets = dockets;
122
122
  this.#offered = new JsonFile(`${dataDir}/tether-offered.json`, []);
123
123
  this.#noticed = new JsonFile(`${dataDir}/tether-notices-seen.json`, []);
124
- this.#keeper = make(`${dataDir}/tether`, { sides: () => this.#sides(), secrets: (name) => this.#reveal(name), notify: (n) => this.#notified(n), now, ...(connectors ? { connectors } : {}) });
124
+ this.#keeper = make(`${dataDir}/tether`, { sides: () => this.#sides(), secrets: (name, opts) => this.#reveal(name, opts), notify: (n) => this.#notified(n), now, ...(connectors ? { connectors } : {}) });
125
125
  /* Every change a page shows -- a new approval waiting, one decided, the targets,
126
126
  the journal -- bumps the counter the client watches, so the approvals screen
127
127
  sees them all at once, not only when a store change happens to wake it. */
@@ -247,9 +247,10 @@ export class Tethers {
247
247
 
248
248
  /* A secret's value for a connector, by name, from this server's vault; never seen by the agent.
249
249
  An unknown or expired secret is a plain refusal the connector turns into "Refused". */
250
- async #reveal(name) {
251
- /* An MCP server signed in with OAuth (mcpoauth.mjs): its current access token, refreshed here when due. */
252
- const fresh = await this.oauth?.access?.(name);
250
+ async #reveal(name, opts) {
251
+ /* An MCP server signed in with OAuth (mcpoauth.mjs): its current access token, refreshed here when due, or
252
+ at once when Tether says the server refused the one it had (opts.fresh, 16-11). */
253
+ const fresh = await this.oauth?.access?.(name, { fresh: opts?.fresh === true });
253
254
  if (fresh !== undefined) return fresh;
254
255
  const value = this.#secrets?.reveal?.(name);
255
256
  if (value === undefined || value === null) throw new Error(`no secret named "${name}" on this server`);
package/web/app.js CHANGED
@@ -5347,14 +5347,15 @@
5347
5347
  const made = justMade?.to === current ? justMade : null;
5348
5348
  const kind = made ? '' : giveNew.kind;
5349
5349
  const levels = newLevels(kind);
5350
- if (kind && !levels.includes(giveNew.level)) giveNew.level = levels[0] ?? '';
5350
+ /* An MCP server made here is given at Write (« propose »: each action asked, 16-11); the rest at the first. */
5351
+ if (kind && !levels.includes(giveNew.level)) giveNew.level = (kind === 'mcp' ? 'write' : levels[0]) ?? '';
5351
5352
  const level = levels.length ? { options: levels.map((l) => ({ value: l, label: KIT.rightWord(l, 'pick') })), value: giveNew.level, label: uiSaid('set-na-level', 'What it may do'), onChange: (v) => { giveNew.level = v; } } : null;
5352
5353
  const box = newAssetBox({
5353
5354
  kind, title: '',
5354
5355
  context: kind && !made ? { line: uiSaid('set-na-will', 'Will be given to {name}', { name: who }), level } : null,
5355
5356
  made: made ? { said: uiSaid('set-na-made-to', '{name} created and given to {to}', { name: made.name, to: who }), note: made.note } : null,
5356
5357
  onKind: (k) => {
5357
- giveNew.kind = k; justMade = null; $('cassets-error').hidden = true; void paintRoomAssets();
5358
+ giveNew.kind = k; giveNew.level = ''; justMade = null; $('cassets-error').hidden = true; void paintRoomAssets();
5358
5359
  /* Its keys, read here too: Assets may not have been opened yet. */
5359
5360
  if (k === 'git') void getJson('/git-keys', []).then((keys) => paintKeys(keys));
5360
5361
  },
@@ -5602,9 +5603,9 @@
5602
5603
  }
5603
5604
  /* Accept or refuse a Tether call that is waiting for a person. `after` repaints the
5604
5605
  surface the row sits in (the Assets page by default; the room passes its own). */
5605
- async function decideTether(id, decision, after) {
5606
+ async function decideTether(id, decision, after, args) {
5606
5607
  $(asErrId()).hidden = true;
5607
- try { await post(`${API}/tether/decide`, { id, decision }); }
5608
+ try { await post(`${API}/tether/decide`, { id, decision, ...(args ? { args } : {}) }); }
5608
5609
  catch (error) { sayAsErr(error); }
5609
5610
  if (after) await after(); else await repaintAsset();
5610
5611
  }
@@ -5812,6 +5813,12 @@
5812
5813
  }
5813
5814
  /* AN EXTERNAL MCP SERVER (mcpx.mjs, Tether's mcp target): its address, its tools each with its kind, « Refresh »;
5814
5815
  a new tool marked until seen (« Mark as seen »); then, for each conversation at Custom, what each kind may do. */
5816
+ /* A sign-in under way (its provider's tab open): the panel is painted again when this page is looked at again.
5817
+ The client form opened, and what the server said it needs, per server. */
5818
+ let mcpSigningIn = ''; let mcpClientOpen = ''; const mcpClientNeed = new Map();
5819
+ const backFromSignin = () => { if (!mcpSigningIn || document.visibilityState !== 'visible') return; mcpSigningIn = ''; void repaintAsset(); };
5820
+ document.addEventListener('visibilitychange', backFromSignin);
5821
+ window.addEventListener('focus', backFromSignin);
5815
5822
  const MCP_CLASS = { read: ['set-mcp-c-read', 'Reads only'], write: ['set-mcp-c-write', 'Writes'], destructive: ['set-mcp-c-destructive', 'Deletes or overwrites'] };
5816
5823
  const mcpClass = (c) => uiSaid(...(MCP_CLASS[c] ?? MCP_CLASS.destructive));
5817
5824
  function mcpParts(t) {
@@ -5825,22 +5832,57 @@
5825
5832
  catch (error) { sayAsErr(error); }
5826
5833
  await repaintAsset();
5827
5834
  });
5828
- /* Signed in with OAuth where the service offers no key (mcpoauth.mjs): the consent in a new tab, back here by
5829
- itself. A server that registers no client by itself asks for its client id once. */
5830
- const oauth = el('button', '', uiSaid('set-mcp-oauth', 'Sign in with OAuth')); oauth.type = 'button'; oauth.dataset.act = 'mcp-oauth';
5831
- const clientRow = el('div', 'set-row mcp-client'); clientRow.hidden = true;
5832
- const clientId = el('input'); clientId.type = 'text'; clientId.autocomplete = 'off'; clientId.spellcheck = false;
5833
- clientId.setAttribute('aria-label', uiSaid('set-mcp-client', 'Client id'));
5834
- clientId.placeholder = uiSaid('set-mcp-client', 'Client id');
5835
- clientRow.append(el('span', '', uiSaid('set-mcp-client-need', 'Paste its client id.')), clientId);
5835
+ /* Signed in with OAuth where the service offers no key (mcpoauth.mjs). PHONE-SAFE (16-11): the provider's tab is
5836
+ opened IN the click, before anything is awaited (a browser lets only a click open one), then sent to its
5837
+ address; none opened (a blocked pop-up), this tab goes there and comes back by itself. A service that
5838
+ registers no client by itself asks once for its client id and secret (kept on the server, never shown
5839
+ again) and the permissions to ask; the address its app must name is shown to copy. */
5840
+ const signedOut = t.catalog?.needs === 'reconnect';
5841
+ const oauth = el('button', signedOut ? 'primary' : '', signedOut ? uiSaid('set-mcp-reconnect', 'Reconnect') : uiSaid('set-mcp-oauth', 'Sign in')); oauth.type = 'button'; oauth.dataset.act = 'mcp-oauth';
5842
+ const clientBox = el('details', 'mcp-client'); clientBox.open = mcpClientOpen === t.id;
5843
+ clientBox.append(el('summary', '', uiSaid('set-mcp-client-box', 'Client ID and secret')));
5844
+ const field = (key, fallback, input) => { const l = el('label', 'mcp-client-field'); l.append(el('span', '', uiSaid(key, fallback)), input); return l; };
5845
+ const clientId = el('input'); clientId.type = 'text'; clientId.autocomplete = 'off'; clientId.spellcheck = false; clientId.name = 'mcp-client-id';
5846
+ const clientSecret = el('input'); clientSecret.type = 'password'; clientSecret.autocomplete = 'new-password'; clientSecret.name = 'mcp-client-secret';
5847
+ const scopes = el('input'); scopes.type = 'text'; scopes.autocomplete = 'off'; scopes.spellcheck = false; scopes.name = 'mcp-scopes';
5848
+ const redirect = el('input'); redirect.type = 'text'; redirect.readOnly = true; redirect.name = 'mcp-redirect';
5849
+ const said = el('p', 'hint mcp-client-said', uiSaid('set-mcp-client-kept', 'Kept on the server. No AI sees them.'));
5850
+ const asked = mcpClientNeed.get(t.id);
5851
+ if (asked) { redirect.value = asked.redirect ?? ''; scopes.value = (asked.scopes ?? []).join(' '); }
5852
+ redirect.hidden = !redirect.value;
5853
+ clientBox.append(field('set-mcp-client', 'Client ID', clientId), field('set-mcp-secret', 'Client secret', clientSecret),
5854
+ field('set-mcp-scopes', 'Permissions asked', scopes), ...(redirect.value ? [field('set-mcp-redirect', 'Its app\'s redirect address', redirect)] : []), said);
5855
+ clientBox.addEventListener('toggle', () => { mcpClientOpen = clientBox.open ? t.id : ''; });
5836
5856
  oauth.addEventListener('click', async () => {
5837
- oauth.disabled = true; $(asErrId()).hidden = true;
5857
+ $(asErrId()).hidden = true;
5858
+ /* Opened now, empty; never told who opened it (the provider's page cannot reach this one). */
5859
+ let tab = null;
5860
+ try { tab = window.open('', '_blank'); if (tab) tab.opener = null; } catch { tab = null; }
5861
+ oauth.disabled = true; oauth.setAttribute('aria-busy', 'true');
5862
+ const body = { target: t.id, lang: deviceLang(), back: location.pathname + location.search, tab: tab ? 'new' : 'same' };
5863
+ if (clientId.value.trim()) body.clientId = clientId.value.trim();
5864
+ if (clientSecret.value.trim()) body.clientSecret = clientSecret.value.trim();
5865
+ if (asked && scopes.value.trim() !== (asked.scopes ?? []).join(' ')) body.scope = scopes.value.trim();
5866
+ else if (clientId.value.trim() && scopes.value.trim()) body.scope = scopes.value.trim();
5867
+ /* Not kept in the page a moment longer. */
5868
+ clientSecret.value = '';
5838
5869
  try {
5839
- const r = await post(`${API}/tether/mcp-oauth`, { target: t.id, ...(clientId.value.trim() ? { clientId: clientId.value.trim() } : {}) });
5840
- if (r?.need === 'client') { clientRow.hidden = false; clientId.focus(); }
5841
- else if (r?.url) window.open(r.url, '_blank', 'noopener');
5842
- } catch (error) { sayAsErr(error); }
5843
- oauth.disabled = false;
5870
+ const r = await post(`${API}/tether/mcp-oauth`, body);
5871
+ if (r?.url) {
5872
+ mcpSigningIn = t.id;
5873
+ if (tab) tab.location.href = r.url; else { location.assign(r.url); return; }
5874
+ } else {
5875
+ try { tab?.close(); } catch { /* gone */ }
5876
+ if (r?.need === 'client') {
5877
+ mcpClientNeed.set(t.id, { redirect: r.redirect, scopes: r.scopes, secret: r.secret });
5878
+ mcpClientOpen = t.id;
5879
+ sayAsErr(new Error(r.missing === 'secret' ? uiSaid('set-mcp-secret-need', 'Paste its client secret too.') : uiSaid('set-mcp-client-need', 'Paste its client ID and secret, once.')));
5880
+ await repaintAsset();
5881
+ return;
5882
+ }
5883
+ }
5884
+ } catch (error) { try { tab?.close(); } catch { /* gone */ } sayAsErr(error); }
5885
+ oauth.disabled = false; oauth.removeAttribute('aria-busy');
5844
5886
  });
5845
5887
  const fresh = tools.filter((x) => x.fresh === true);
5846
5888
  const seen = fresh.length ? el('button', '', uiSaid('set-mcp-seen', 'Mark as seen')) : null;
@@ -5860,13 +5902,17 @@
5860
5902
  const kind = el('small', 'mcp-tool-class', mcpClass(x.class)); kind.dataset.class = x.class;
5861
5903
  li.append(nm, kind);
5862
5904
  if (x.open && x.class !== 'read') li.append(el('small', 'hint', uiSaid('set-mcp-open', 'reaches outside')));
5905
+ /* Declares nothing, seems to only read (Tether, 16-11): offered at Read, each call asked. */
5906
+ if (x.guess === 'read') li.append(el('small', 'hint', uiSaid('set-mcp-guess', 'seems to only read')));
5863
5907
  if (x.fresh === true) li.append(el('small', 'mcp-tool-fresh', uiSaid('set-mcp-fresh', 'New — asked until you\'ve seen it')));
5864
5908
  list.append(li);
5865
5909
  }
5866
5910
  const body = [];
5867
- if (t.catalog?.error) body.push(el('p', 'error', uiSaid('set-mcp-unreached', 'Not reached: {why}', { why: t.catalog.error })));
5911
+ /* Signed out for good (Tether, 16-11): said once, plainly, the button to reconnect beside it. */
5912
+ if (signedOut) body.push(el('p', 'error mcp-out', uiSaid('set-mcp-out', '{name} is disconnected. Reconnect it.', { name: t.title })));
5913
+ else if (t.catalog?.error) body.push(el('p', 'error', uiSaid('set-mcp-unreached', 'Not reached: {why}', { why: t.catalog.error })));
5868
5914
  body.push(tools.length ? list : el('p', 'hint', uiSaid('set-mcp-none', 'No tools listed yet.')));
5869
- body.push(clientRow);
5915
+ body.push(clientBox);
5870
5916
  out.push({ title: uiSaid('set-mcp-tools', 'Tools'), extra: [seen, oauth, refresh], body, cls: 'as-mcp-tools' });
5871
5917
  /* Custom: each kind of tool Yes / Ask / No, for each conversation set to it. */
5872
5918
  const custom = Object.entries(t.grants ?? {}).filter(([id, g]) => id.startsWith('conversation:') && g?.level === 'frame');
@@ -6153,7 +6199,26 @@
6153
6199
  const yes = el('button', 'primary', 'Accept'); yes.type = 'button'; yes.addEventListener('click', () => { yes.disabled = true; void decideTether(q.id, 'yes', repaintAsset); });
6154
6200
  const no = el('button', 'danger', 'Refuse'); no.type = 'button'; no.addEventListener('click', () => { no.disabled = true; void decideTether(q.id, 'no', repaintAsset); });
6155
6201
  const acts = el('div', 'levels'); acts.append(yes, no);
6156
- line.append(what, acts); box.append(line);
6202
+ line.append(what, acts);
6203
+ /* EDIT BEFORE APPROVING (16-11): an MCP call's texts shown whole (a reply's text...), changed here, then
6204
+ approved as changed; Tether checks them again against the tool. */
6205
+ const editable = q.card?.kind === 'mcp' && Array.isArray(q.editable) ? q.editable : [];
6206
+ if (editable.length) {
6207
+ const edit = el('button', '', uiSaid('set-ap-edit', 'Edit')); edit.type = 'button'; edit.dataset.act = 'edit-call';
6208
+ const form = el('div', 'ap-edit'); form.hidden = true;
6209
+ const boxes = editable.map((name) => {
6210
+ const area = el('textarea'); area.name = name; area.rows = 3; area.value = (q.card.args ?? []).find((x) => x.name === name)?.value ?? '';
6211
+ const l = el('label', 'mcp-client-field'); l.append(el('span', '', name), area); form.append(l);
6212
+ return area;
6213
+ });
6214
+ const send = el('button', 'primary', uiSaid('set-ap-send-edited', 'Accept as edited')); send.type = 'button';
6215
+ send.addEventListener('click', () => { send.disabled = true; void decideTether(q.id, 'yes', repaintAsset, Object.fromEntries(boxes.map((b) => [b.name, b.value]))); });
6216
+ form.append(send);
6217
+ edit.addEventListener('click', () => { form.hidden = !form.hidden; yes.hidden = !form.hidden; if (!form.hidden) boxes[0]?.focus(); });
6218
+ acts.append(edit);
6219
+ line.append(form);
6220
+ }
6221
+ box.append(line);
6157
6222
  }
6158
6223
  parts.push({ title: 'Waiting for you', body: [box] });
6159
6224
  }
@@ -6235,6 +6300,15 @@
6235
6300
  if (ev.online) { const a = el('a', '', uiSaid('set-ag-join', 'Join online')); a.href = ev.online; a.target = '_blank'; a.rel = 'noopener noreferrer'; fact(uiSaid('set-ag-link', 'Link'), a); }
6236
6301
  fact(uiSaid('set-ag-organizer', 'Organizer'), ev.organizer ? document.createTextNode(ev.organizer) : null);
6237
6302
  if (Number.isInteger(ev.attendees) && ev.attendees > 0) fact(uiSaid('set-ag-guests', 'Guests'), document.createTextNode(String(ev.attendees)));
6303
+ /* ITS INVITATION'S TEXT (16-11): text nodes only -- never HTML, nothing in it runs; a web address (https) alone is a link. */
6304
+ if (ev.notes) {
6305
+ const text = el('div', 'ag-notes');
6306
+ for (const part of String(ev.notes).split(/(https:\/\/[^\s<>"')\]]+)/)) {
6307
+ if (/^https:\/\//.test(part)) { const a = el('a', '', part.length > 60 ? `${part.slice(0, 57)}…` : part); a.href = part; a.target = '_blank'; a.rel = 'noopener noreferrer'; text.append(a); }
6308
+ else if (part) text.append(document.createTextNode(part));
6309
+ }
6310
+ fact(uiSaid('set-ag-notes', 'Invitation'), text);
6311
+ }
6238
6312
  if (ev.show && ev.show !== 'busy') fact(uiSaid('set-ag-shown', 'Shown as'), document.createTextNode(uiSaid(`set-ag-show-${ev.show}`, { free: 'Free', tentative: 'Tentative', away: 'Away', elsewhere: 'Elsewhere' }[ev.show] ?? ev.show)));
6239
6313
  box.append(head, facts);
6240
6314
  return box;
package/web/kit.js CHANGED
@@ -518,6 +518,8 @@
518
518
  /* The table's key of an asset: a live link is a connexion, whatever it links; else its kind. */
519
519
  const rightsKey = (a) => (a?.target?.kind === 'mcp' ? 'mcp' : a?.live || a?.target ? 'connexion' : a?.kind ?? '');
520
520
  const rightsFor = (key, holder = 'conversation') => [...(RIGHTS[key]?.[HOLDERS.includes(holder) ? holder : 'conversation'] ?? [])];
521
+ /* The level a new grant starts at, where it is not the lightest (16-11): an MCP server's actions each asked. */
522
+ const FIRST_LEVEL = { mcp: 'propose' };
521
523
  /* The lightest real level (what "give the group" gives): the first after none. */
522
524
  const lightest = (key, holder) => rightsFor(key, holder)[1] ?? null;
523
525
  /* AS THE SERVER KEEPS THEM -> a level, and back. A secret is 'off' / 'use' (secrets.mjs); a device's
@@ -853,7 +855,8 @@
853
855
  const key = rightsKey(a);
854
856
  const levels = rightsFor(key).filter((l) => l !== 'none');
855
857
  if (!levels.length) return null;
856
- let level = levels[0];
858
+ /* An MCP server is given at « All with approval » first (16-11, the owner's choice): each action asked. */
859
+ let level = levels.includes(FIRST_LEVEL[key]) ? FIRST_LEVEL[key] : levels[0];
857
860
  const bar = node('div', 'kit-aspick-give');
858
861
  const pick = Segmented({ options: levels.map((l) => ({ value: l, label: wordOf(key, l, 'pick') })), value: level, label: say('set-acc-what', 'What {who} may do with {name}').replace('{who}', w.who ?? '').replace('{name}', a.name ?? ''), onChange: (l) => { level = l; } });
859
862
  addClass(pick, 'kit-rights-pick');
package/web/style.css CHANGED
@@ -1282,6 +1282,7 @@ header .ic, #folders .ic { width: 18px; height: 18px; fill: none; stroke: curren
1282
1282
  .ag-facts dt { color: var(--ink2); }
1283
1283
  .ag-facts dd { margin: 0; overflow-wrap: anywhere; }
1284
1284
  .ag-facts a { color: var(--brass-ink); }
1285
+ .ag-notes { white-space: pre-wrap; max-height: 16em; overflow: auto; color: var(--ink2); overflow-wrap: anywhere; }
1285
1286
  .ag-now { display: flex; align-items: center; gap: 6px; color: var(--brass-ink); font-size: .6875rem; font-weight: 600; text-transform: uppercase; }
1286
1287
  .ag-now::after { content: ""; flex: 1; border-top: 1.5px solid var(--brass-ink); }
1287
1288
  @media (max-width: 600px) {
@@ -2256,6 +2257,11 @@ details.commit > pre { margin: 6px 0 0 1.6em; white-space: pre-wrap; overflow-wr
2256
2257
  .mcp-tool-class { color: var(--ink2); }
2257
2258
  .mcp-tool-class[data-class="destructive"] { color: var(--danger); }
2258
2259
  .mcp-tool-fresh { color: var(--warn); }
2260
+ /* The client pasted once for a service that registers none (16-11): stacked, full width, on a phone too. */
2261
+ .mcp-client { margin: .4rem 0; }
2262
+ .mcp-client summary { cursor: pointer; color: var(--ink2); }
2263
+ .mcp-client-field { display: flex; flex-direction: column; gap: 2px; margin: .4rem 0; }
2264
+ .mcp-client-field input { width: 100%; box-sizing: border-box; min-width: 0; }
2259
2265
  .mcp-custom { display: flex; flex-direction: column; gap: 4px; margin: .4rem 0 .8rem; }
2260
2266
  .mcp-custom-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
2261
2267
  #mcp-config { width: 100%; font: .8125rem var(--mono, monospace); }
@@ -3211,3 +3217,5 @@ span.tile-spark { display: block; height: 22px; }
3211
3217
  .share-donut.kit-bone { border-radius: 50%; }
3212
3218
  .server-parts-bones { display: grid; gap: 8px; flex: 1 1 auto; min-width: 0; padding-top: 4px; }
3213
3219
  .list-bones { display: grid; gap: 10px; padding: 8px 0; }
3220
+ .ap-edit { flex: 1 1 100%; }
3221
+ .ap-edit textarea { width: 100%; box-sizing: border-box; }