clavarium 0.2.205-beta.1 → 0.2.206-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.205-beta.1",
3
+ "version": "0.2.206-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.205-beta.1",
9
+ "version": "0.2.206-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.205-beta.1",
3
+ "version": "0.2.206-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/api.mjs CHANGED
@@ -187,6 +187,7 @@ import { transcribe, AUDIO_MAX } from './voice.mjs';
187
187
  import { FILE_MAX } from './setup.mjs';
188
188
  import { demandeView } from './demandes.mjs';
189
189
  import { mcpAdd, mcpImport, mcpRefresh, mcpRights, mcpSeen, forgetKey } from './mcpx.mjs';
190
+ import { BACK_PATH, backPage } from './mcpoauth.mjs';
190
191
 
191
192
  const BODY_MAX = 16 * 1024;
192
193
  /* A setup file travels inside the JSON of a request: room for it, escaped. */
@@ -523,6 +524,15 @@ export async function handleApi(request, response, conversations, headers, resou
523
524
  if (paired && sharing) return send(200, sharing.devices.of(decodeURIComponent(paired[1]))), true;
524
525
  const sending = /^\/api\/conversations\/([^/]+)\/git\/([a-z0-9-]{1,32})\/auto$/.exec(pathname);
525
526
  if (sending && gitKeeper) return send(200, gitKeeper.auto(sending[2], decodeURIComponent(sending[1]))), true;
527
+ /* Back from signing in to an external MCP server (mcpoauth.mjs): the owner's browser, sent here by the
528
+ provider. A page, not JSON; its state is the proof it was started from this page. */
529
+ if (pathname === BACK_PATH && tethers?.oauth) {
530
+ let page;
531
+ 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 }); }
532
+ catch (error) { page = backPage({ ok: false, message: error instanceof Refusal ? error.message : 'The sign-in failed.' }); }
533
+ response.writeHead(200, { ...headers, 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'referrer-policy': 'no-referrer' }).end(page);
534
+ return true;
535
+ }
526
536
  return send(404, { error: 'Not found.' }), true;
527
537
  }
528
538
  if (request.method !== 'POST') return send(405, { error: 'Method not allowed.' }), true;
@@ -676,6 +686,8 @@ export async function handleApi(request, response, conversations, headers, resou
676
686
  keeper runs as the owner (person), never as an agent. */
677
687
  /* External MCP servers (mcpx.mjs): added with their key (kept host-only in the vault, Tether given its name),
678
688
  imported from a pasted mcpServers block, listed again, a conversation's rights on their tools, new tools seen. */
689
+ /* Signing in to one with OAuth: the link the owner opens ({ url }), or { need: 'client' } for a client id to paste. */
690
+ if (pathname === '/api/tether/mcp-oauth' && tethers?.oauth) return send(200, await tethers.oauth.start({ tethers }, body ?? {}, sharing?.origin?.(request.headers) ?? `http://${request.headers.host}`)), true;
679
691
  const mcpOp = /^\/api\/tether\/mcp-(add|import|refresh|rights|seen)$/.exec(pathname);
680
692
  if (mcpOp && tethers) {
681
693
  const ctx = { tethers, secrets };
package/server/main.mjs CHANGED
@@ -73,6 +73,7 @@ import { Wifi } from './wifi.mjs';
73
73
  import { MeshCentral } from './meshcentral.mjs';
74
74
  import { Binders } from './binders.mjs';
75
75
  import { Tethers } from './tethers.mjs';
76
+ import { McpOAuth } from './mcpoauth.mjs';
76
77
  import { Browsers } from './browsers.mjs';
77
78
  import { Accounts } from './accounts.mjs';
78
79
  import { ServerLogs } from './serverlogs.mjs';
@@ -492,6 +493,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
492
493
  let tethers = null;
493
494
  const browsers = new Browsers({ dataDir, store: () => tethers?.store(), log: (line) => console.log(line) });
494
495
  tethers = new Tethers({ dataDir, resources: folders, conversations: () => all.list().map((c) => c.name), secrets, dockets, browsers, connectors: { voicebox: { run: (...a) => voiceboxConnector(boxes).run(...a) }, ...(tetherConnectors ?? {}) } });
496
+ /* External MCP servers signed in with OAuth: their tokens held here, refreshed here (mcpoauth.mjs). */
497
+ tethers.oauth = new McpOAuth({ secrets });
495
498
  const stopTethers = tethers.start();
496
499
  /* Connecting a mailbox, calendar or address book by token: the consent happens
497
500
  in the owner's browser, the refresh token is kept host-only (never in a
@@ -0,0 +1,250 @@
1
+ /* SIGNING IN TO AN EXTERNAL MCP SERVER WITH OAUTH (14-11). Some services offer no key, only a sign-in. This is
2
+ * the MCP authorization spec (2025-06-18) seen from the client: the server's 401 names its protected resource
3
+ * metadata (RFC 9728), that names its authorization server, whose metadata (RFC 8414) gives the endpoints; a
4
+ * client is registered by itself where the server offers it (RFC 7591), else the owner pastes a client id; then
5
+ * an authorization code with PKCE (S256), the `resource` said at each step (RFC 8707), and refresh tokens.
6
+ *
7
+ * WHO DOES WHAT. The owner allows it in their own browser, from a link the Access page opens; the provider
8
+ * sends the browser back to THIS server's own address (/api/tether/mcp-oauth/back, behind the same sign-in as
9
+ * the page), which trades the code. Nothing to paste.
10
+ *
11
+ * THE TOKENS STAY HERE, like a key: one host-only secret of the vault (secrets.mjs: never put in a machine,
12
+ * never listed on the page), named MCP_<ID>_TOK, holding the access token, the refresh token and what is needed
13
+ * to refresh. Tether is handed only that NAME; when its connector asks for it (tethers.mjs, reveal), access()
14
+ * answers a fresh access token, refreshed here first when it is near its end. No token is ever logged, said in
15
+ * an error or returned by a route.
16
+ *
17
+ * `fetch` is injected, so the tests run against a fake authorization server with no network. */
18
+ import { Refusal } from './conversations.mjs';
19
+ import { pkcePair, newState } from './oauth.mjs';
20
+ import { KEY_PREFIX, keyName, oauthName } from './mcpx.mjs';
21
+
22
+ export const TOKEN_SUFFIX = '_TOK';
23
+ export const BACK_PATH = '/api/tether/mcp-oauth/back';
24
+ const PROTOCOL = '2025-06-18';
25
+ const PENDING_MS = 10 * 60_000;
26
+ const PENDING_MAX = 20;
27
+ const FETCH_MS = 15_000;
28
+ /* Refreshed this long before its end: a call that starts now still has a valid token when it lands. */
29
+ const EARLY_MS = 60_000;
30
+ const KIND = 'mcp-oauth';
31
+
32
+ /* The vault's name for a server's tokens: as long as its key's name, so every server id fits. */
33
+ export const tokenName = oauthName;
34
+ export const isTokenName = (name) => typeof name === 'string' && name.startsWith(KEY_PREFIX) && name.endsWith(TOKEN_SUFFIX);
35
+
36
+ const oneLine = (x, n = 200) => String(x ?? '').replace(/[\r\n\0]/g, ' ').trim().slice(0, n);
37
+
38
+ /* https only, but plain http where the owner allowed it for that server (a local network), or on this machine. */
39
+ function safeUrl(raw, allowHttp) {
40
+ let u;
41
+ try { u = new URL(String(raw ?? '')); } catch { return null; }
42
+ if (u.username || u.password || u.hash) return null;
43
+ const local = u.hostname === '127.0.0.1' || u.hostname === 'localhost' || u.hostname === '[::1]';
44
+ if (u.protocol === 'https:' || (u.protocol === 'http:' && (allowHttp || local))) return u;
45
+ return null;
46
+ }
47
+
48
+ /* The resource a metadata names is this server: its origin, and its path or a parent of it. */
49
+ function sameResource(server, resource) {
50
+ let r;
51
+ try { r = new URL(String(resource)); } catch { return false; }
52
+ const path = r.pathname.replace(/\/+$/, '');
53
+ return r.origin === server.origin && (!path || server.pathname === path || server.pathname.startsWith(`${path}/`) || server.pathname === `${path}/`);
54
+ }
55
+
56
+ /* One field of a WWW-Authenticate: Bearer header, quoted or not. */
57
+ function authParam(header, key) {
58
+ const m = new RegExp(`(?:^|[\\s,])${key}\\s*=\\s*(?:"([^"]*)"|([^\\s,]+))`, 'i').exec(String(header ?? ''));
59
+ return m ? (m[1] ?? m[2]) : '';
60
+ }
61
+
62
+ /* The well-known addresses to try for a URL with a path (RFC 8414 / RFC 9728: inserted before the path). */
63
+ function wellKnown(base, suffix) {
64
+ const u = new URL(base);
65
+ const path = u.pathname.replace(/\/+$/, '');
66
+ return path ? [`${u.origin}/.well-known/${suffix}${path}`, `${u.origin}/.well-known/${suffix}`] : [`${u.origin}/.well-known/${suffix}`];
67
+ }
68
+
69
+ export class McpOAuth {
70
+ #secrets; #fetch; #now; #pending = new Map(); #refreshing = new Map();
71
+
72
+ constructor({ secrets, fetch = globalThis.fetch, now = () => Date.now() }) {
73
+ this.#secrets = secrets; this.#fetch = fetch; this.#now = now;
74
+ }
75
+
76
+ async #get(url, init = {}) {
77
+ const abort = new AbortController();
78
+ const timer = setTimeout(() => abort.abort(), FETCH_MS); timer.unref?.();
79
+ try { return await this.#fetch(url, { redirect: 'manual', ...init, signal: abort.signal }); }
80
+ finally { clearTimeout(timer); }
81
+ }
82
+ async #json(url, allowHttp) {
83
+ if (!safeUrl(url, allowHttp)) return null;
84
+ let res;
85
+ try { res = await this.#get(url, { headers: { accept: 'application/json', 'mcp-protocol-version': PROTOCOL } }); } catch { return null; }
86
+ if (!res.ok) return null;
87
+ try { const j = await res.json(); return j && typeof j === 'object' && !Array.isArray(j) ? j : null; } catch { return null; }
88
+ }
89
+
90
+ /* FROM THE SERVER'S ADDRESS TO ITS AUTHORIZATION SERVER: { resource, meta, scope }. */
91
+ async discover(serverUrl, { allowHttp = false } = {}) {
92
+ const server = safeUrl(serverUrl, allowHttp);
93
+ if (!server) throw new Refusal(400, 'The server\'s address must be https.');
94
+ /* Asked as a client would, without a token: an OAuth server answers 401 and says where its metadata is. */
95
+ let res;
96
+ try {
97
+ res = await this.#get(server.href, { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', 'mcp-protocol-version': PROTOCOL },
98
+ body: JSON.stringify({ jsonrpc: '2.0', id: 'clv-oauth', method: 'initialize', params: { protocolVersion: PROTOCOL, capabilities: {}, clientInfo: { name: 'Clavarium', version: '1' } } }) });
99
+ } catch { throw new Refusal(502, 'The server could not be reached.'); }
100
+ try { await res.body?.cancel?.(); } catch { /* nothing to read */ }
101
+ if (res.ok) throw new Refusal(409, 'This server answers without signing in: no OAuth needed.');
102
+ const challenge = res.status === 401 ? String(res.headers.get('www-authenticate') ?? '') : '';
103
+ const scope = oneLine(authParam(challenge, 'scope'), 1000);
104
+ const named = authParam(challenge, 'resource_metadata');
105
+ const tries = [...(named ? [named] : []), ...wellKnown(server.href, 'oauth-protected-resource')];
106
+ let prm = null;
107
+ for (const at of tries) { prm = await this.#json(at, allowHttp); if (prm) break; }
108
+ /* The metadata must be about this server (RFC 9728 s.3.3): another resource's would send its token here. */
109
+ if (prm?.resource && !sameResource(server, prm.resource)) throw new Refusal(502, 'The server\'s metadata names another address: refused.');
110
+ /* An older server (MCP 2025-03-26) has no such metadata: its own origin is its authorization server. */
111
+ const issuer = Array.isArray(prm?.authorization_servers) && prm.authorization_servers.length ? String(prm.authorization_servers[0]) : server.origin;
112
+ if (!safeUrl(issuer, allowHttp)) throw new Refusal(502, 'The server\'s sign-in address is not https.');
113
+ let meta = null;
114
+ for (const at of [...wellKnown(issuer, 'oauth-authorization-server'), ...wellKnown(issuer, 'openid-configuration'), `${issuer.replace(/\/+$/, '')}/.well-known/openid-configuration`]) {
115
+ meta = await this.#json(at, allowHttp); if (meta) break;
116
+ }
117
+ 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
+ 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
+ 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) : '') };
121
+ }
122
+
123
+ /* A client registered by itself (RFC 7591), public (no secret) where the server allows it. */
124
+ async #register(meta, redirectUri, allowHttp) {
125
+ if (!safeUrl(meta.registration_endpoint, allowHttp)) return null;
126
+ let res;
127
+ try {
128
+ res = await this.#get(meta.registration_endpoint, { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json' },
129
+ body: JSON.stringify({ client_name: 'Clavarium', redirect_uris: [redirectUri], grant_types: ['authorization_code', 'refresh_token'], response_types: ['code'], token_endpoint_auth_method: 'none' }) });
130
+ } catch { throw new Refusal(502, 'The server\'s registration could not be reached.'); }
131
+ const j = await res.json().catch(() => null);
132
+ 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 : '' };
134
+ }
135
+
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). */
138
+ async start({ tethers }, body = {}, origin = '') {
139
+ const t = tethers.store().target(String(body.target ?? ''));
140
+ if (!t || t.kind !== 'mcp') throw new Refusal(404, 'No such MCP server.');
141
+ const allowHttp = t.config?.allowHttp === true;
142
+ const back = safeUrl(`${String(origin).replace(/\/+$/, '')}${BACK_PATH}`, true);
143
+ if (!back) throw new Refusal(500, 'This server does not know its own address.');
144
+ const redirectUri = back.href;
145
+ const { resource, meta, scope } = await this.discover(t.config?.url, { allowHttp });
146
+ let client = null;
147
+ const given = oneLine(body.clientId, 500);
148
+ if (given) client = { clientId: given, clientSecret: typeof body.clientSecret === 'string' ? body.clientSecret.trim() : '' };
149
+ else client = await this.#register(meta, redirectUri, allowHttp);
150
+ if (!client) return { need: 'client' };
151
+ this.#sweep();
152
+ if (this.#pending.size >= PENDING_MAX) throw new Refusal(429, 'Too many sign-ins in progress; try again shortly.');
153
+ const state = newState();
154
+ const { verifier, challenge } = pkcePair();
155
+ const url = new URL(meta.authorization_endpoint);
156
+ const ask = { response_type: 'code', client_id: client.clientId, redirect_uri: redirectUri, state, code_challenge: challenge, code_challenge_method: 'S256', resource, ...(scope ? { scope } : {}) };
157
+ 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() });
161
+ return { url: url.href };
162
+ }
163
+
164
+ #sweep() { for (const [k, p] of this.#pending) if (this.#now() - p.at > PENDING_MS) this.#pending.delete(k); }
165
+
166
+ /* The token endpoint, by the client's way of proving itself. Never says back what it was sent or answered. */
167
+ async #token(rec, params, allowHttp) {
168
+ if (!safeUrl(rec.token, allowHttp)) throw new Refusal(502, 'The sign-in address is not https.');
169
+ const form = new URLSearchParams({ ...params, ...(rec.resource ? { resource: rec.resource } : {}) });
170
+ const headers = { 'content-type': 'application/x-www-form-urlencoded', accept: 'application/json' };
171
+ if (rec.auth === 'basic') headers.authorization = `Basic ${Buffer.from(`${encodeURIComponent(rec.clientId)}:${encodeURIComponent(rec.clientSecret)}`).toString('base64')}`;
172
+ else { form.set('client_id', rec.clientId); if (rec.auth === 'post') form.set('client_secret', rec.clientSecret); }
173
+ let res;
174
+ 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' });
179
+ }
180
+ if (/[\r\n]/.test(j.access_token)) throw new Refusal(502, 'The sign-in server answered a token that is not one line.');
181
+ const life = Number(j.expires_in);
182
+ return { access: j.access_token, refresh: typeof j.refresh_token === 'string' && j.refresh_token ? j.refresh_token : '', expiresAt: life > 0 ? this.#now() + life * 1000 : null };
183
+ }
184
+
185
+ #keep(name, rec) {
186
+ const { access, refresh, expiresAt, token, clientId, clientSecret, auth, resource, allowHttp } = rec;
187
+ this.#secrets.set({ name, value: JSON.stringify({ kind: KIND, access, refresh, expiresAt, token, clientId, clientSecret, auth, resource, allowHttp }), hostOnly: true });
188
+ }
189
+ #open(name) {
190
+ let raw;
191
+ try { raw = this.#secrets.reveal(name); } catch { return null; }
192
+ if (typeof raw !== 'string') return null;
193
+ try { const r = JSON.parse(raw); return r?.kind === KIND ? r : null; } catch { return null; }
194
+ }
195
+
196
+ /* BACK FROM THE PROVIDER (the owner's browser, /api/tether/mcp-oauth/back?code&state): trade the code, keep the
197
+ tokens host-only, and point the server's target at them. -> { target, title }. */
198
+ async finish({ tethers }, { code, state, error } = {}) {
199
+ this.#sweep();
200
+ 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.');
202
+ 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);
206
+ const name = tokenName(p.target);
207
+ this.#keep(name, { ...p, ...got });
208
+ const before = tethers.store().target(p.target);
209
+ /* 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
+ 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.');
212
+ 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 };
214
+ }
215
+
216
+ /* 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) {
219
+ if (!isTokenName(name)) return undefined;
220
+ const rec = this.#open(name);
221
+ 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');
224
+ let running = this.#refreshing.get(name);
225
+ if (!running) {
226
+ running = (async () => {
227
+ try {
228
+ const got = await this.#token(rec, { grant_type: 'refresh_token', refresh_token: rec.refresh }, rec.allowHttp);
229
+ /* A server that rotates refresh tokens sends a new one; one that does not keeps the old one valid. */
230
+ this.#keep(name, { ...rec, ...got, refresh: got.refresh || rec.refresh });
231
+ return got.access;
232
+ } catch (e) {
233
+ if (e?.grant) throw new Error('signed out of this server: sign in again in Assets > Access');
234
+ throw new Error(`could not refresh the sign-in: ${e?.message ?? 'failed'}`);
235
+ } finally { this.#refreshing.delete(name); }
236
+ })();
237
+ this.#refreshing.set(name, running);
238
+ }
239
+ return running;
240
+ }
241
+ }
242
+
243
+ /* The page the owner's browser lands on: said plainly, nothing to copy, no script. */
244
+ export function backPage({ ok, title = '', message = '' }) {
245
+ 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>`;
250
+ }
package/server/mcpx.mjs CHANGED
@@ -56,7 +56,8 @@ export async function mcpAdd({ tethers, secrets }, body = {}) {
56
56
  const had = known(secrets, ref);
57
57
  /* Its key, in the vault, host-only: Tether gets its name. None given: the one it had, or none. */
58
58
  let secret = '';
59
- if (key) { secrets.set({ name: ref, value: key, hostOnly: true }); secret = ref; }
59
+ /* A key given where it was signed in with OAuth: the key replaces the tokens, which go. */
60
+ if (key) { secrets.set({ name: ref, value: key, hostOnly: true }); secret = ref; if (before?.secrets?.token === oauthName(id)) { try { secrets.remove(oauthName(id)); } catch { /* not there */ } } }
60
61
  else if (before?.secrets?.token) secret = String(before.secrets.token);
61
62
  const r = await tethers.act('mcp-add', { id, name, url, ...(secret ? { secret } : {}), ...(body.header ? { header: String(body.header) } : {}), ...(body.allowHttp === true ? { allowHttp: true } : {}) }, '');
62
63
  if (!r.ok) {
@@ -146,9 +147,12 @@ export async function mcpSeen({ tethers }, body = {}) {
146
147
  return { seen: Array.isArray(r.data?.seen) ? r.data.seen : [] };
147
148
  }
148
149
 
149
- /* A server taken away: its key goes with it (only the one kept for it here). */
150
+ /* The vault's name for a server's OAuth tokens (mcpoauth.mjs): as long as its key's name. */
151
+ export const oauthName = (id) => `${keyName(id).slice(0, -KEY_SUFFIX.length)}_TOK`;
152
+
153
+ /* A server taken away: its key goes with it, or its OAuth tokens (only those kept for it here). */
150
154
  export function forgetKey(secrets, target) {
151
155
  const ref = target?.kind === 'mcp' ? String(target.secrets?.token ?? '') : '';
152
- if (!ref || ref !== keyName(target.id)) return;
156
+ if (!ref || (ref !== keyName(target.id) && ref !== oauthName(target.id))) return;
153
157
  try { secrets?.remove(ref); } catch { /* not there */ }
154
158
  }
@@ -164,7 +164,22 @@ export const SETTINGS_WORDS_FR = {
164
164
  'set-na-k-mcp': 'Serveur MCP', 'set-cx-mcp': 'serveur MCP',
165
165
  'set-mcp-head': 'Ajouter un serveur MCP', 'set-mcp-hint': 'Ses outils pour vos IA ; la clé reste ici.',
166
166
  'set-mcp-name': 'Nom', 'set-mcp-url': 'Adresse', 'set-mcp-key': 'Clé', 'set-mcp-add': 'Ajouter',
167
- 'set-mshared-with': 'Partagée « {m} », avec {others}.', 'set-mshared-alone': 'Machine partagée « {m} », seule pour l\'instant.',
167
+ /* Où elle tourne, et l'assistant Copier ou déplacer (#221, 14-11). */
168
+ 'set-where': 'Où elle tourne', 'set-where-copy': 'Copier…', 'set-where-move': 'Déplacer…', 'set-where-own': 'Sa propre machine',
169
+ 'set-where-shared': 'Machine partagée « {m} », avec {others}', 'set-where-alone': 'Machine partagée « {m} », seule', 'set-where-stops': 'L’arrêter les arrête aussi',
170
+ 'set-cm-title': 'Copier ou déplacer {t}', 'set-cm-copy': 'Copier', 'set-cm-copy-what': 'Celle-ci reste telle quelle',
171
+ 'set-cm-move': 'Déplacer', 'set-cm-move-what': 'La même, sur une autre machine', 'set-cm-cancel': 'Annuler', 'set-cm-next': 'Suivant',
172
+ 'set-cm-not-yet': 'Pas encore', 'set-cm-with': 'Avec {who}', 'set-cm-shared': 'Machine partagée « {m} »', 'set-cm-new': 'Une nouvelle machine partagée',
173
+ 'set-cm-name-first': 'Nommez d\'abord la machine partagée', 'set-cm-name-bad': 'Minuscules, chiffres, tirets',
174
+ 'set-cm-name-taken': 'C\'est le nom d\'une conversation', 'set-cm-there': 'Elle y est déjà',
175
+ 'set-cm-disk': 'Travail sur son disque : gardez-le ici d\'abord',
176
+ 'set-cm-own-to': 'sa propre machine', 'set-cm-copy-to': 'Copier {t} vers {where}', 'set-cm-move-to': 'Déplacer {t} dans {where}',
177
+ 'set-cm-new-line': 'Nouvelle machine partagée · {size}', 'set-cm-copy-name': 'Nom de la copie',
178
+ 'set-cm-goes-work': 'Son dossier de travail', 'set-cm-goes-memory': 'La mémoire de son IA', 'set-cm-goes-access': 'Ses accès',
179
+ 'set-cm-not': 'Ni ses appareils, ni ses rappels', 'set-cm-untouched': 'Celle-ci intacte : lue, puis remise en l\'état',
180
+ 'set-cm-stay': 'Vous restez ici · « Ouvrir » une fois prête', 'set-cm-stops': 'Son outil s\'arrête environ une minute',
181
+ 'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
182
+ 'set-cm-ready': 'Copie prête', 'set-cm-open': 'Ouvrir', 'set-cm-failed': 'Pas copiée', 'set-cm-see-why': 'Voir pourquoi',
168
183
  'set-carry': 'La mémoire de son outil', 'set-carry-hint': 'Mémoire, sessions, réglages : à emporter.',
169
184
  'set-carry-export': 'Exporter', 'set-carry-import': 'Importer…', 'set-carry-go': 'Importer',
170
185
  'set-carry-ask': '« {file} » dans « {name} » ? Mémoire remplacée.', 'set-carry-done': 'Importé depuis « {from} ».',
@@ -176,6 +191,7 @@ export const SETTINGS_WORDS_FR = {
176
191
  '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',
177
192
  'set-mcp-none': 'Aucun outil listé pour l\'instant.', 'set-mcp-unreached': 'Injoignable : {why}', 'set-mcp-open': 'atteint l\'extérieur',
178
193
  'set-mcp-fresh': 'Nouveau : demandé jusqu\'à ce que vous l\'ayez vu',
194
+ 'set-mcp-oauth': 'Se connecter (OAuth)', 'set-mcp-client': 'Identifiant client', 'set-mcp-client-need': 'Collez son identifiant client.',
179
195
  'set-mcp-c-read': 'Lecture seule', 'set-mcp-c-write': 'Écrit', 'set-mcp-c-destructive': 'Supprime ou écrase',
180
196
  'set-mcp-custom': 'Droits personnalisés', 'set-mcp-yes': 'Oui', 'set-mcp-ask': 'Demander', 'set-mcp-no': 'Non',
181
197
  '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é',
@@ -113,6 +113,9 @@ export class Tethers {
113
113
  {kind, text, data}) } (dockets.mjs): what wakes an agent told of a notice. `make`: the keeper (tests). */
114
114
  /* `browsers`: the paired browsers (browsers.mjs), set by the constructor when it is given one; their connector is the keeper's `browser`. */
115
115
  browsers = null;
116
+ /* Set by the server (main.mjs): the OAuth sign-ins of external MCP servers (mcpoauth.mjs), whose tokens the
117
+ keeper reveals fresh. */
118
+ oauth = null;
116
119
  constructor({ dataDir, resources, conversations, secrets, connectors, browsers = null, dockets = null, now = () => Date.now(), make = keeper }) {
117
120
  if (browsers) { connectors = { ...(connectors ?? {}), browser: browsers.connector }; this.browsers = browsers; }
118
121
  this.#resources = resources; this.#conversations = conversations; this.#secrets = secrets; this.#dockets = dockets;
@@ -245,6 +248,9 @@ export class Tethers {
245
248
  /* A secret's value for a connector, by name, from this server's vault; never seen by the agent.
246
249
  An unknown or expired secret is a plain refusal the connector turns into "Refused". */
247
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);
253
+ if (fresh !== undefined) return fresh;
248
254
  const value = this.#secrets?.reveal?.(name);
249
255
  if (value === undefined || value === null) throw new Error(`no secret named "${name}" on this server`);
250
256
  return value;
package/web/app.js CHANGED
@@ -2002,6 +2002,8 @@
2002
2002
  was last opened (« ● 1 failed », red); nothing otherwise. Tapped: what runs, its step; then the day's ends,
2003
2003
  done or failed with why. A line opens its conversation. Read with the list, nothing asked of the machines. */
2004
2004
  let jobsNow = { running: [], done: [] };
2005
+ /* The copies made from here (the wizard, #cm), watched until their job ends: their names, new each time. */
2006
+ const copiesWatched = new Set();
2005
2007
  const JOBS_SEEN = 'clavarium.jobsSeen';
2006
2008
  const jobsSeen = () => { try { return localStorage.getItem(JOBS_SEEN) ?? ''; } catch { return ''; } };
2007
2009
  async function paintJobs() {
@@ -2020,6 +2022,7 @@
2020
2022
  }
2021
2023
  if (n || failed) $('back').dataset.jobs = n ? 'on' : 'bad'; else delete $('back').dataset.jobs;
2022
2024
  if (!$('jobs').hidden) paintJobsList();
2025
+ cmJobsSeen();
2023
2026
  }
2024
2027
  function paintJobsList() {
2025
2028
  const line = (j, mark, result) => {
@@ -2668,15 +2671,6 @@
2668
2671
  catch (error) { show(error.message, 'Back to the terminal', enter); }
2669
2672
  }, () => { notice.hidden = true; focusTerminal(); });
2670
2673
  };
2671
- /* In a shared machine (#221): its name and the others in it, said once -- stopping it stops them too. */
2672
- const sharedIn = here?.sharedMachine;
2673
- $('machine-shared').hidden = DEVICE || !sharedIn;
2674
- if (sharedIn) {
2675
- const others = conversations.filter((c) => c.sharedMachine === sharedIn && c.name !== current).map((c) => c.title ?? c.name);
2676
- $('machine-shared').textContent = others.length
2677
- ? uiSaid('set-mshared-with', 'Shared machine « {m} », with {others}. Stopping it stops them too.', { m: sharedIn, others: others.join(', ') })
2678
- : uiSaid('set-mshared-alone', 'Shared machine « {m} », alone in it for now.', { m: sharedIn });
2679
- }
2680
2674
  /* Its tool's memory, exported as one file, or put back from one (#351): the person's own act, from here. */
2681
2675
  $('carry-box').hidden = DEVICE || !here;
2682
2676
  /* Its machine must run to be read: stopped or asleep, said there, with the one button that starts it
@@ -3071,21 +3065,16 @@
3071
3065
  $('machine-size-title').textContent = sharedHere ? 'Memory' : 'Memory, cores and disk';
3072
3066
  if (sharedHere) { $('machine-size-hint').textContent = 'Its limit in the shared machine · from its next start'; $('machine-size-apply').textContent = 'Apply'; }
3073
3067
  $('shared-size').hidden = !sharedHere || here.phase !== 'ready';
3074
- /* Into a shared machine (#221): offered to one in a machine of its own; a shared machine there is offered first. */
3075
- $('into-shared').hidden = sharedHere || DEVICE || !here || here.phase !== 'ready';
3076
- if (!$('into-shared').hidden && document.activeElement !== $('into-shared-name')) {
3077
- const names = [...new Set(conversations.map((x) => x.sharedMachine).filter(Boolean))].sort();
3078
- $('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
3079
- if (!$('into-shared-name').value && names.length) $('into-shared-name').value = names[0];
3080
- paintIntoShared();
3081
- }
3082
- /* A copy of it (#221): offered to any that is ready. */
3083
- $('copy-it').hidden = DEVICE || !here || here.phase !== 'ready';
3084
- if (!$('copy-it').hidden && ![$('copy-title'), $('copy-machine')].includes(document.activeElement)) {
3085
- if ($('copy-it').dataset.of !== here.name) { $('copy-it').dataset.of = here.name; $('copy-title').value = `${here.title ?? here.name} (copy)`; $('copy-where').value = ''; $('copy-machine').value = ''; }
3086
- const names = [...new Set(conversations.map((x) => x.sharedMachine).filter(Boolean))].sort();
3087
- $('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
3088
- paintCopy();
3068
+ /* Where it runs (#221, 14-11): its own machine, or a shared one and who else is there; Copy... and Move...
3069
+ open the wizard, for one that is ready. */
3070
+ $('where-row').hidden = DEVICE || !here;
3071
+ if (here) {
3072
+ $('where-now').textContent = whereWords(here);
3073
+ /* Its machine shared with others: stopping or restarting it stops them too -- said where it runs. */
3074
+ const sharers = here.sharedMachine ? conversations.some((x) => x.sharedMachine === here.sharedMachine && x.name !== here.name) : false;
3075
+ $('where-now').title = sharers ? uiSaid('set-where-stops', 'Stopping it stops them too') : '';
3076
+ if (sharers) $('where-now').append(' · ', uiSaid('set-where-stops', 'Stopping it stops them too'));
3077
+ for (const id of ['where-copy', 'where-move']) $(id).disabled = here.phase !== 'ready';
3089
3078
  }
3090
3079
  if (sharedHere && document.activeElement !== $('shared-memory')) {
3091
3080
  const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine);
@@ -3203,68 +3192,178 @@
3203
3192
  }, resume);
3204
3193
  });
3205
3194
 
3206
- /* ITS SHARED MACHINE'S MEMORY (#221): asked first, naming every conversation it interrupts. */
3207
- /* A new shared machine: its memory chosen; one that is there keeps its own. Work on its own disk: kept here first. */
3208
- function paintIntoShared() {
3195
+ /* ---------- COPY OR MOVE (#221, 14-11): a wizard of two screens over the page ----------
3196
+ 1. Choose: Copy (this one stays as it is) or Move (the same conversation, another machine), and where it
3197
+ runs -- its own machine, a shared machine there (who lives in it, its memory), or a new one (named, its
3198
+ memory chosen). Moving out of a shared machine does not exist yet: said so, not offered.
3199
+ 2. Check: what goes and what does not; for a move, its own machine deleted, in red.
3200
+ Confirmed, a copy closes it at once: the person stays where they are, the copy is a job « under way », and
3201
+ its end is one line at the bottom (« Open it », or « See why » in Settings, Jobs). A move does as it did:
3202
+ the page waits for it and reconnects. Work on its own machine's disk cannot go: kept here first. */
3203
+ function whereWords(c) {
3204
+ if (!c.sharedMachine) return uiSaid('set-where-own', 'Its own machine');
3205
+ const others = conversations.filter((x) => x.sharedMachine === c.sharedMachine && x.name !== c.name).map((x) => x.title ?? x.name);
3206
+ return others.length
3207
+ ? uiSaid('set-where-shared', 'Shared machine « {m} », with {others}', { m: c.sharedMachine, others: others.join(', ') })
3208
+ : uiSaid('set-where-alone', 'Shared machine « {m} », alone in it', { m: c.sharedMachine });
3209
+ }
3210
+ /* The shared machines there: their names, who lives in each, its memory. */
3211
+ function sharedMachines() {
3212
+ const by = new Map();
3213
+ for (const c of conversations) {
3214
+ if (!c.sharedMachine) continue;
3215
+ const m = by.get(c.sharedMachine) ?? { name: c.sharedMachine, who: [], mb: c.machineMb };
3216
+ m.who.push(c.title ?? c.name); m.mb ??= c.machineMb;
3217
+ by.set(c.sharedMachine, m);
3218
+ }
3219
+ return [...by.values()].sort((a, b) => a.name.localeCompare(b.name));
3220
+ }
3221
+ /* What is chosen: of which conversation, copy or move, and where ('' its own machine, 'new', or a machine's name). */
3222
+ const cm = { of: '', kind: 'copy', place: '' };
3223
+ const cmHere = () => conversations.find((x) => x.name === cm.of);
3224
+ const cmCard = (place, title, small, { disabled = false } = {}) => {
3225
+ const b = document.createElement('button'); b.type = 'button'; b.className = 'cm-card'; b.setAttribute('role', 'radio');
3226
+ b.dataset.place = place; b.disabled = disabled;
3227
+ b.setAttribute('aria-checked', String(!disabled && cm.place === place));
3228
+ b.append(Object.assign(document.createElement('b'), { textContent: title }));
3229
+ if (small) b.append(Object.assign(document.createElement('small'), { textContent: small }));
3230
+ b.addEventListener('click', () => { cm.place = place; paintCm(); if (place === 'new') $('cm-new-name').focus(); });
3231
+ return b;
3232
+ };
3233
+ /* The places it may go, for a copy or a move of this one; the one chosen kept if it still is one. */
3234
+ function cmPlaces(here) {
3235
+ const machines = sharedMachines().filter((m) => !(cm.kind === 'move' && m.name === here.sharedMachine));
3236
+ if (cm.kind === 'move' && here.sharedMachine) return { cards: [cmCard('', uiSaid('set-where-own', 'Its own machine'), uiSaid('set-cm-not-yet', 'Not yet'), { disabled: true })], open: [] };
3237
+ const open = [...(cm.kind === 'copy' ? [''] : []), ...machines.map((m) => m.name), 'new'];
3238
+ if (!open.includes(cm.place)) cm.place = open[0];
3239
+ const cards = [];
3240
+ if (cm.kind === 'copy') cards.push(cmCard('', uiSaid('set-where-own', 'Its own machine')));
3241
+ for (const m of machines) {
3242
+ const small = [m.who.length ? uiSaid('set-cm-with', 'With {who}', { who: m.who.join(', ') }) : '', m.mb ? sizeWords(m.mb) : ''].filter(Boolean).join(' · ');
3243
+ cards.push(cmCard(m.name, uiSaid('set-cm-shared', 'Shared machine « {m} »', { m: m.name }), small));
3244
+ }
3245
+ cards.push(cmCard('new', uiSaid('set-cm-new', 'A new shared machine')));
3246
+ return { cards, open };
3247
+ }
3248
+ /* Where it goes, as asked of the server: { machine?, machineMb? }, its words, or why it cannot. */
3249
+ function cmTarget(here) {
3250
+ if (cm.place === '') return { body: {}, said: uiSaid('set-where-own', 'Its own machine') };
3251
+ const machine = cm.place === 'new' ? $('cm-new-name').value.trim() : cm.place;
3252
+ if (cm.place === 'new' && !machine) return { why: uiSaid('set-cm-name-first', 'Name the shared machine first') };
3253
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(machine)) return { why: uiSaid('set-cm-name-bad', 'Lower-case letters, digits, hyphens') };
3254
+ if (conversations.some((x) => x.name === machine)) return { why: uiSaid('set-cm-name-taken', 'That is a conversation\'s name') };
3255
+ /* A name typed that is a machine there already: that one, its memory its own. */
3256
+ const known = sharedMachines().some((m) => m.name === machine);
3257
+ if (cm.kind === 'move' && machine === here.sharedMachine) return { why: uiSaid('set-cm-there', 'It is there already') };
3258
+ const machineMb = known ? undefined : Number($('cm-new-mb').value);
3259
+ return { body: { machine, ...(machineMb ? { machineMb } : {}) }, machine, known, machineMb };
3260
+ }
3261
+ /* Screen 1, painted again as it is chosen. */
3262
+ function paintCm() {
3263
+ const here = cmHere();
3264
+ if (!here) { closeCm(); return; }
3265
+ const t = here.title ?? here.name;
3266
+ for (const b of document.querySelectorAll('#cm .cm-kinds .cm-card')) b.setAttribute('aria-checked', String(b.dataset.kind === cm.kind));
3267
+ $('cm-sheep').dataset.kind = cm.kind;
3268
+ if (!$('cm-choose').hidden) {
3269
+ $('cm-title').textContent = uiSaid('set-cm-title', 'Copy or move {t}', { t });
3270
+ const { cards, open } = cmPlaces(here);
3271
+ $('cm-places').replaceChildren(...cards);
3272
+ $('cm-new').hidden = cm.place !== 'new' || !open.includes('new');
3273
+ const typed = $('cm-new-name').value.trim();
3274
+ $('cm-new-mb').hidden = sharedMachines().some((m) => m.name === typed);
3275
+ const onDisk = here.work === 'disk';
3276
+ $('cm-why').textContent = onDisk ? uiSaid('set-cm-disk', 'Its work is on its disk: keep it here first') : '';
3277
+ $('cm-why').hidden = !onDisk;
3278
+ $('cm-next').disabled = onDisk || !open.length;
3279
+ }
3280
+ }
3281
+ function openCm(kind) {
3209
3282
  const here = conversations.find((x) => x.name === current);
3210
- const names = new Set(conversations.map((x) => x.sharedMachine).filter(Boolean));
3211
- const known = names.has($('into-shared-name').value.trim());
3212
- $('into-shared-mb').hidden = known; $('into-shared-mb-label').hidden = known;
3213
- const onDisk = here?.work === 'disk';
3214
- $('into-shared-hint').textContent = onDisk ? 'Keep its files here first (Where the tool works)' : 'Trial · work and tool state come along';
3215
- $('into-shared-apply').disabled = onDisk;
3216
- }
3217
- $('into-shared-name').addEventListener('input', () => paintIntoShared());
3218
- $('into-shared').addEventListener('submit', (event) => {
3219
- event.preventDefault();
3220
- const name = current;
3221
- const here = conversations.find((x) => x.name === name);
3222
- if (!here || here.sharedMachine) return;
3223
- const machine = $('into-shared-name').value.trim();
3224
- if (!machine) { $('panel-error').textContent = 'Name the shared machine first.'; $('panel-error').hidden = false; return; }
3225
- const known = conversations.some((x) => x.sharedMachine === machine);
3226
- const machineMb = known ? undefined : Number($('into-shared-mb').value);
3227
- leavePanel();
3228
- const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
3229
- show(`Move ${here.title ?? here.name} into the shared machine « ${machine} »${known ? '' : ` (new, ${sizeWords(machineMb)})`}? Its tool stops, its work and its state come along, then ITS OWN MACHINE IS DELETED.`,
3230
- 'Move it', async () => {
3231
- disconnect(); say('moving', 'connecting'); show('Moving...'); $('notice-spin').hidden = false;
3232
- try { await post(`${API}/conversations/${encodeURIComponent(name)}/into-machine`, { machine, ...(machineMb ? { machineMb } : {}) }); await refresh(); enter(); }
3233
- catch (error) { show(error.message, 'Back', enter); }
3234
- }, resume);
3283
+ if (DEVICE || !here || here.phase !== 'ready') return;
3284
+ if (cm.of !== here.name) { $('cm-new-name').value = ''; $('cm-copy-title').value = ''; }
3285
+ Object.assign(cm, { of: here.name, kind, place: kind === 'copy' ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
3286
+ $('machine-names').replaceChildren(...sharedMachines().map((m) => Object.assign(document.createElement('option'), { value: m.name })));
3287
+ $('cm-copy-title').value = `${here.title ?? here.name} (copy)`;
3288
+ /* Its sheep: two for a copy (the second slides out of the first), one walking for a move. */
3289
+ if (!$('cm-sheep').childElementCount) $('cm-sheep').innerHTML = `<div class="mascot cm-one">${MASCOTS[MASCOT]()}</div><div class="mascot cm-one">${MASCOTS[MASCOT]()}</div>`;
3290
+ $('cm-choose').hidden = false; $('cm-check').hidden = true;
3291
+ paintCm();
3292
+ if (!$('cm').open) $('cm').showModal();
3293
+ document.querySelector('#cm .cm-kinds .cm-card[aria-checked="true"]')?.focus();
3294
+ }
3295
+ function closeCm() { if ($('cm').open) $('cm').close(); }
3296
+ $('where-copy').addEventListener('click', () => openCm('copy'));
3297
+ $('where-move').addEventListener('click', () => openCm('move'));
3298
+ for (const b of document.querySelectorAll('#cm .cm-kinds .cm-card')) b.addEventListener('click', () => { cm.kind = b.dataset.kind; paintCm(); });
3299
+ $('cm-new-name').addEventListener('input', () => { $('cm-new-mb').hidden = sharedMachines().some((m) => m.name === $('cm-new-name').value.trim()); $('cm-why').hidden = true; });
3300
+ $('cm-cancel').addEventListener('click', closeCm);
3301
+ /* Escape closes the wizard, and only it: never the place under it too. */
3302
+ document.addEventListener('keydown', (event) => { if (event.key === 'Escape' && $('cm').open) { event.stopImmediatePropagation(); event.preventDefault(); closeCm(); } }, true);
3303
+ /* Screen 2: what it does, said for the copy or the move chosen. */
3304
+ $('cm-next').addEventListener('click', () => {
3305
+ const here = cmHere();
3306
+ if (!here) return;
3307
+ const goes = cmTarget(here);
3308
+ if (goes.why) { $('cm-why').textContent = goes.why; $('cm-why').hidden = false; return; }
3309
+ const t = here.title ?? here.name;
3310
+ const where = goes.machine ? `« ${goes.machine} »` : uiSaid('set-cm-own-to', 'its own machine');
3311
+ $('cm-title').textContent = cm.kind === 'copy' ? uiSaid('set-cm-copy-to', 'Copy {t} to {where}', { t, where }) : uiSaid('set-cm-move-to', 'Move {t} into {where}', { t, where });
3312
+ $('cm-new-line')?.remove();
3313
+ if (goes.machine && !goes.known) $('cm-check').prepend(Object.assign(document.createElement('p'), { id: 'cm-new-line', className: 'cm-not', textContent: uiSaid('set-cm-new-line', 'A new shared machine · {size}', { size: sizeWords(goes.machineMb) }) }));
3314
+ $('cm-copy-part').hidden = cm.kind !== 'copy'; $('cm-move-part').hidden = cm.kind !== 'move';
3315
+ $('cm-go').textContent = cm.kind === 'copy' ? uiSaid('set-cm-copy-go', 'Copy it') : uiSaid('set-cm-move-go', 'Move it');
3316
+ $('cm-go').className = 'primary';
3317
+ $('cm-choose').hidden = true; $('cm-check').hidden = false;
3318
+ (cm.kind === 'copy' ? $('cm-copy-title') : $('cm-go')).focus();
3235
3319
  });
3236
- /* A COPY: in its own machine, or a shared one (there already, or new: its memory chosen). Work on its own disk: kept here first. */
3237
- function paintCopy() {
3238
- const here = conversations.find((x) => x.name === current);
3239
- const shared = $('copy-where').value === 'shared';
3240
- const known = conversations.some((x) => x.sharedMachine && x.sharedMachine === $('copy-machine').value.trim());
3241
- $('copy-machine').hidden = !shared; $('copy-mb').hidden = !shared || known;
3242
- const onDisk = here?.work === 'disk';
3243
- $('copy-hint').textContent = onDisk ? 'Keep its files here first (Where the tool works)' : 'Work, AI memory and accesses · the original untouched';
3244
- $('copy-apply').disabled = onDisk;
3245
- }
3246
- $('copy-where').addEventListener('change', () => { if ($('copy-where').value === 'shared' && !$('copy-machine').value) $('copy-machine').value = [...new Set(conversations.map((x) => x.sharedMachine).filter(Boolean))].sort()[0] ?? ''; paintCopy(); });
3247
- $('copy-machine').addEventListener('input', () => paintCopy());
3248
- $('copy-it').addEventListener('submit', (event) => {
3249
- event.preventDefault();
3250
- const name = current;
3251
- const here = conversations.find((x) => x.name === name);
3320
+ $('cm-back').addEventListener('click', () => { $('cm-check').hidden = true; $('cm-choose').hidden = false; paintCm(); $('cm-next').focus(); });
3321
+ $('cm-go').addEventListener('click', async () => {
3322
+ const name = cm.of;
3323
+ const here = cmHere();
3252
3324
  if (!here) return;
3253
- const title = $('copy-title').value.trim() || `${here.title ?? here.name} (copy)`;
3254
- const shared = $('copy-where').value === 'shared';
3255
- const machine = shared ? $('copy-machine').value.trim() : '';
3256
- if (shared && !machine) { $('panel-error').textContent = 'Name the shared machine first.'; $('panel-error').hidden = false; return; }
3257
- const known = shared && conversations.some((x) => x.sharedMachine === machine);
3258
- const machineMb = shared && !known ? Number($('copy-mb').value) : undefined;
3259
- leavePanel();
3260
- const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
3261
- show(`Make « ${title} », a copy of ${here.title ?? here.name}${shared ? ` in the shared machine « ${machine} »${known ? '' : ` (new, ${sizeWords(machineMb)})`}` : ' in a machine of its own'}? Its work, its AI's memory and its accesses are copied; not its devices nor its reminders. The original is untouched.`,
3262
- 'Copy it', async () => {
3263
- show('Copying...'); $('notice-spin').hidden = false;
3264
- try { await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...(machine ? { machine } : {}), ...(machineMb ? { machineMb } : {}) }); await refresh(); resume(); }
3265
- catch (error) { show(error.message, 'Back', enter); }
3266
- }, resume);
3325
+ const goes = cmTarget(here);
3326
+ if (goes.why) return;
3327
+ closeCm();
3328
+ if (cm.kind === 'move') {
3329
+ /* As it was: the page waits for the move, then reconnects to it in its new machine. */
3330
+ leavePanel();
3331
+ disconnect(); say('moving', 'connecting'); show('Moving...'); $('notice-spin').hidden = false;
3332
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/into-machine`, goes.body); await refresh(); enter(); }
3333
+ catch (error) { show(error.message, 'Back', enter); }
3334
+ return;
3335
+ }
3336
+ const title = $('cm-copy-title').value.trim() || `${here.title ?? here.name} (copy)`;
3337
+ try {
3338
+ const made = await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...goes.body });
3339
+ if (made?.name) copiesWatched.add(made.name);
3340
+ await refresh();
3341
+ } catch (error) { cmToast(`✗ ${error.message}`, 'bad'); }
3267
3342
  });
3343
+ /* Its end, read with the jobs (paintJobs): done, « Open it »; failed or removed, « See why ». */
3344
+ function cmJobsSeen() {
3345
+ for (const name of copiesWatched) {
3346
+ const end = jobsNow.done.find((j) => j.conversation === name);
3347
+ if (!end) continue;
3348
+ copiesWatched.delete(name);
3349
+ if (end.result === 'done') cmToast(`✓ ${uiSaid('set-cm-ready', 'Copy ready')}`, 'ok', uiSaid('set-cm-open', 'Open it'), () => select(name, { step: true }));
3350
+ else cmToast(`✗ ${uiSaid('set-cm-failed', 'Not copied')}`, 'bad', uiSaid('set-cm-see-why', 'See why'), async () => { await openSettings(); openChapter('s-jobs')?.scrollIntoView({ block: 'start' }); });
3351
+ }
3352
+ }
3353
+ let cmToastTimer;
3354
+ function cmToast(text, tone, label, act) {
3355
+ const toast = $('cm-toast');
3356
+ $('cm-toast-text').textContent = text;
3357
+ toast.dataset.tone = tone;
3358
+ $('cm-toast-go').hidden = !label;
3359
+ $('cm-toast-go').textContent = label ?? '';
3360
+ $('cm-toast-go').onclick = () => { toast.hidden = true; void act?.(); };
3361
+ toast.hidden = false;
3362
+ clearTimeout(cmToastTimer); cmToastTimer = setTimeout(() => { toast.hidden = true; }, 60_000);
3363
+ }
3364
+ $('cm-toast-close').addEventListener('click', () => { $('cm-toast').hidden = true; });
3365
+
3366
+ /* ITS SHARED MACHINE'S MEMORY (#221): asked first, naming every conversation it interrupts. */
3268
3367
  $('shared-size').addEventListener('submit', (event) => {
3269
3368
  event.preventDefault();
3270
3369
  const name = current;
@@ -5566,6 +5665,23 @@
5566
5665
  catch (error) { sayAsErr(error); }
5567
5666
  await repaintAsset();
5568
5667
  });
5668
+ /* Signed in with OAuth where the service offers no key (mcpoauth.mjs): the consent in a new tab, back here by
5669
+ itself. A server that registers no client by itself asks for its client id once. */
5670
+ const oauth = el('button', '', uiSaid('set-mcp-oauth', 'Sign in with OAuth')); oauth.type = 'button'; oauth.dataset.act = 'mcp-oauth';
5671
+ const clientRow = el('div', 'set-row mcp-client'); clientRow.hidden = true;
5672
+ const clientId = el('input'); clientId.type = 'text'; clientId.autocomplete = 'off'; clientId.spellcheck = false;
5673
+ clientId.setAttribute('aria-label', uiSaid('set-mcp-client', 'Client id'));
5674
+ clientId.placeholder = uiSaid('set-mcp-client', 'Client id');
5675
+ clientRow.append(el('span', '', uiSaid('set-mcp-client-need', 'Paste its client id.')), clientId);
5676
+ oauth.addEventListener('click', async () => {
5677
+ oauth.disabled = true; $(asErrId()).hidden = true;
5678
+ try {
5679
+ const r = await post(`${API}/tether/mcp-oauth`, { target: t.id, ...(clientId.value.trim() ? { clientId: clientId.value.trim() } : {}) });
5680
+ if (r?.need === 'client') { clientRow.hidden = false; clientId.focus(); }
5681
+ else if (r?.url) window.open(r.url, '_blank', 'noopener');
5682
+ } catch (error) { sayAsErr(error); }
5683
+ oauth.disabled = false;
5684
+ });
5569
5685
  const fresh = tools.filter((x) => x.fresh === true);
5570
5686
  const seen = fresh.length ? el('button', '', uiSaid('set-mcp-seen', 'Mark as seen')) : null;
5571
5687
  if (seen) {
@@ -5590,7 +5706,8 @@
5590
5706
  const body = [];
5591
5707
  if (t.catalog?.error) body.push(el('p', 'error', uiSaid('set-mcp-unreached', 'Not reached: {why}', { why: t.catalog.error })));
5592
5708
  body.push(tools.length ? list : el('p', 'hint', uiSaid('set-mcp-none', 'No tools listed yet.')));
5593
- out.push({ title: uiSaid('set-mcp-tools', 'Tools'), extra: [seen, refresh], body, cls: 'as-mcp-tools' });
5709
+ body.push(clientRow);
5710
+ out.push({ title: uiSaid('set-mcp-tools', 'Tools'), extra: [seen, oauth, refresh], body, cls: 'as-mcp-tools' });
5594
5711
  /* Custom: each kind of tool Yes / Ask / No, for each conversation set to it. */
5595
5712
  const custom = Object.entries(t.grants ?? {}).filter(([id, g]) => id.startsWith('conversation:') && g?.level === 'frame');
5596
5713
  if (custom.length) {
package/web/index.html CHANGED
@@ -199,13 +199,14 @@
199
199
  <details class="chapter" id="chapter-machine" data-chapter="machine">
200
200
  <summary><span class="chapter-title" data-said="set-ch-machine">Machine</span><span class="chapter-about">Health, size, restart.</span></summary>
201
201
  <div class="chapter-body">
202
+ <!-- WHERE IT RUNS (#221, 14-11): its own machine, or a shared one and who else lives there -- its stop or
203
+ restart stops them too; Copy... and Move... open the wizard (#cm, below). -->
204
+ <div class="set-row" id="where-row" hidden><div class="set-what"><b data-said="set-where">Where it runs</b><small id="where-now"></small></div><div class="set-control"><button type="button" id="where-copy" data-said="set-where-copy">Copy…</button><button type="button" id="where-move" data-said="set-where-move">Move…</button></div></div>
202
205
  <!-- ITS CURVES: memory, CPU and disk over time (server/history.mjs). -->
203
206
  <div class="curves" id="machine-curves" data-of="" hidden>
204
207
  <div class="curves-head"><b>Over time</b><div class="levels curves-span" role="group" aria-label="Over"><button type="button" data-span="1h" aria-pressed="true">1 h</button><button type="button" data-span="24h" aria-pressed="false">24 h</button><button type="button" data-span="7d" aria-pressed="false">7 days</button></div></div>
205
208
  <div class="curves-row"></div>
206
209
  </div>
207
- <!-- IN A SHARED MACHINE (#221): which, and who else lives in it -- its stop or restart stops them too. -->
208
- <p id="machine-shared" class="hint machine-shared" hidden></p>
209
210
  <p id="machine-restarted" class="hint" role="status" hidden></p>
210
211
  <div id="resume-box" hidden>
211
212
  <div class="set-row"><div class="set-what"><b>When its tool starts</b><small id="resume-hint">After a wake or restart</small></div><div class="set-control"><div class="levels" id="resume-on" role="group" aria-label="When its tool starts"><button type="button" data-on="true">Resume its last session</button><button type="button" data-on="false">Start fresh</button></div></div></div>
@@ -235,26 +236,6 @@
235
236
  <p class="hint" id="shared-size-hint">Restarts every conversation in it</p>
236
237
  <div class="row"><button type="submit" id="shared-size-apply">Change...</button></div>
237
238
  </form>
238
- <!-- MOVED INTO A SHARED MACHINE (#221, 12-11): its work and its tool's state along, its own machine deleted. -->
239
- <form id="into-shared" autocomplete="off" hidden>
240
- <label for="into-shared-name">Into a shared machine</label>
241
- <input id="into-shared-name" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off">
242
- <label for="into-shared-mb" id="into-shared-mb-label">Its memory</label>
243
- <select id="into-shared-mb"><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select>
244
- <p class="hint" id="into-shared-hint">Trial · work and tool state come along</p>
245
- <div class="row"><button type="submit" id="into-shared-apply">Move...</button></div>
246
- </form>
247
- <!-- A COPY OF IT (#221): its work, its AI's memory, its accesses; the original untouched. -->
248
- <form id="copy-it" autocomplete="off" hidden>
249
- <label for="copy-title">A copy of it</label>
250
- <input id="copy-title" maxlength="60">
251
- <label for="copy-where">Its machine</label>
252
- <select id="copy-where"><option value="">Its own</option><option value="shared">A shared machine</option></select>
253
- <input id="copy-machine" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off" aria-label="Shared machine" hidden>
254
- <select id="copy-mb" aria-label="Its memory" hidden><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select>
255
- <p class="hint" id="copy-hint">Work, AI memory and accesses · the original untouched</p>
256
- <div class="row"><button type="submit" id="copy-apply">Copy...</button></div>
257
- </form>
258
239
  <div id="work-box">
259
240
  <div class="panel-top"><b>Where the tool works</b></div>
260
241
  <p id="work-now" class="hint"><span><span id="work-now-text"></span></span><span id="work-now-why" class="tip" hidden></span></p>
@@ -1509,6 +1490,42 @@
1509
1490
  <script src="/gitgraph.js"></script>
1510
1491
  <script src="/links.js"></script>
1511
1492
  <div id="jobs" class="jobs-pop" role="dialog" aria-label="Under way" hidden></div>
1493
+ <!-- COPY OR MOVE (#221, 14-11): a two-screen wizard over the page -- what and where, then what it does. Confirmed,
1494
+ it closes at once and the job goes on in « under way »; its end said by the toast below. -->
1495
+ <dialog id="cm" aria-labelledby="cm-title">
1496
+ <div class="cm-head"><div class="mascot cm-sheep" id="cm-sheep" aria-hidden="true"></div><h2 id="cm-title"></h2></div>
1497
+ <div id="cm-choose">
1498
+ <div class="cm-kinds" role="radiogroup" aria-label="Copy or move">
1499
+ <button type="button" class="cm-card" data-kind="copy" role="radio" aria-checked="true"><b data-said="set-cm-copy">Copy</b><small data-said="set-cm-copy-what">This one stays as it is</small></button>
1500
+ <button type="button" class="cm-card" data-kind="move" role="radio" aria-checked="false"><b data-said="set-cm-move">Move</b><small data-said="set-cm-move-what">The same conversation, another machine</small></button>
1501
+ </div>
1502
+ <p class="cm-label" data-said="set-where">Where it runs</p>
1503
+ <div id="cm-places" class="cm-places" role="radiogroup" aria-label="Where it runs"></div>
1504
+ <div id="cm-new" class="cm-new" hidden>
1505
+ <input id="cm-new-name" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off" aria-label="Its name">
1506
+ <select id="cm-new-mb" aria-label="Its memory"><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select>
1507
+ </div>
1508
+ <p class="cm-why" id="cm-why" role="alert" hidden></p>
1509
+ <div class="cm-acts"><button type="button" id="cm-cancel" data-said="set-cm-cancel">Cancel</button><button type="button" class="primary" id="cm-next" data-said="set-cm-next">Next</button></div>
1510
+ </div>
1511
+ <div id="cm-check" hidden>
1512
+ <div id="cm-copy-part">
1513
+ <label class="cm-label" for="cm-copy-title" data-said="set-cm-copy-name">Name of the copy</label>
1514
+ <input id="cm-copy-title" maxlength="60">
1515
+ <ul class="cm-goes"><li data-said="set-cm-goes-work">Its work folder</li><li data-said="set-cm-goes-memory">Its AI's memory</li><li data-said="set-cm-goes-access">Its accesses</li></ul>
1516
+ <p class="cm-not" data-said="set-cm-not">Not its devices, nor its reminders</p>
1517
+ <p class="cm-box" data-said="set-cm-untouched">This one: untouched (woken or started to read it, then put back as it was)</p>
1518
+ <p class="cm-box" data-said="set-cm-stay">You stay here · « Open it » when it is ready</p>
1519
+ </div>
1520
+ <div id="cm-move-part">
1521
+ <p class="cm-box" data-said="set-cm-stops">Its tool stops for about a minute</p>
1522
+ <p class="cm-box cm-danger" data-said="set-cm-deleted">Its own machine is deleted</p>
1523
+ </div>
1524
+ <div class="cm-acts"><button type="button" id="cm-back" data-said="set-cm-back">Back</button><button type="button" class="primary" id="cm-go"></button></div>
1525
+ </div>
1526
+ </dialog>
1527
+ <!-- A COPY'S END (14-11): one line under the top bar, « Open it » or « See why ». -->
1528
+ <div id="cm-toast" class="cm-toast" role="status" hidden><span id="cm-toast-text"></span><button type="button" id="cm-toast-go" class="primary"></button><button type="button" id="cm-toast-close" class="quiet" aria-label="Close">×</button></div>
1512
1529
  <script src="/features.js"></script>
1513
1530
  <script src="/kit.js"></script>
1514
1531
  <script src="/mail-view.js"></script>
package/web/style.css CHANGED
@@ -498,9 +498,9 @@ details.chapter.reached { outline: 2px solid var(--brass); outline-offset: 2px;
498
498
  .facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
499
499
  .facts dt { color: var(--ink2); }
500
500
  .facts dd { margin: 0; overflow-wrap: anywhere; }
501
- #machine-size, #shared-size, #into-shared, #copy-it { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
- #machine-size label, #shared-size label, #into-shared label, #copy-it label { font-size: .8125rem; color: var(--ink2); }
503
- #machine-size select, #shared-size select, #into-shared :is(select, input), #copy-it :is(select, input) { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
501
+ #machine-size, #shared-size { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
+ #machine-size label, #shared-size label { font-size: .8125rem; color: var(--ink2); }
503
+ #machine-size select, #shared-size select, #cm :is(select, input) { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
504
504
  .health-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
505
505
  .health-lines li { padding-left: 1.3em; position: relative; }
506
506
  .health-lines li::before { content: ""; position: absolute; left: .2em; top: .45em; width: .55em; height: .55em; border-radius: 50%; background: var(--ok); }
@@ -1939,13 +1939,12 @@ button.tip-btn:hover, button.tip-btn[aria-expanded="true"] { color: var(--brass-
1939
1939
  :is(#settings, #panel) .chapter-body .panel-top { border: 0; }
1940
1940
  :is(#settings, #panel) .chapter-body .panel-top > b { font-size: .6875rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); }
1941
1941
  /* The machine's size: each a row, its name on the left, its choice on the right. */
1942
- #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 16rem); gap: 10px 16px; align-items: center; max-width: none; }
1943
- #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1944
- #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) > :is(p, .row) { grid-column: 1 / -1; }
1945
- #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) > .row { justify-content: flex-end; }
1946
- #shared-size[hidden], #into-shared[hidden], #into-shared [hidden], #copy-it[hidden], #copy-it [hidden] { display: none; }
1947
- #panel #copy-it > :is(#copy-machine, #copy-mb) { grid-column: 2; }
1948
- @media (max-width: 560px) { #panel :is(#machine-size, #into-shared, #copy-it) > :is(#copy-machine, #copy-mb) { grid-column: 1; } #panel :is(#machine-size, #into-shared, #copy-it) { grid-template-columns: minmax(0, 1fr); } }
1942
+ #panel :is(#machine-size, #shared-size) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 16rem); gap: 10px 16px; align-items: center; max-width: none; }
1943
+ #panel :is(#machine-size, #shared-size) > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1944
+ #panel :is(#machine-size, #shared-size) > :is(p, .row) { grid-column: 1 / -1; }
1945
+ #panel :is(#machine-size, #shared-size) > .row { justify-content: flex-end; }
1946
+ #shared-size[hidden] { display: none; }
1947
+ @media (max-width: 560px) { #panel #machine-size { grid-template-columns: minmax(0, 1fr); } }
1949
1948
  /* A chapter whose body is one block (Updates, Network): its pieces are the rows, not the block. */
1950
1949
  :is(#settings, #panel) .chapter-body > :is(#updates, #wifi) { padding: 0; }
1951
1950
  :is(#updates, #wifi) > * { margin: 0; padding: 12px 16px; }
@@ -3098,3 +3097,57 @@ a.button[aria-disabled] { opacity: .5; pointer-events: none; }
3098
3097
  @keyframes m-q { 0% { opacity: 0; transform: translateY(6px) rotate(-8deg); } 30%, 70% { opacity: 1; transform: translateY(0) rotate(6deg); } 100% { opacity: 0; transform: translateY(-4px) rotate(-4deg); } }
3099
3098
  .fading-out { transition: opacity .15s ease-out; opacity: 0; }
3100
3099
  @media (prefers-reduced-motion: reduce) { .mascot.wondering .m-q { animation: none; opacity: 1; } }
3100
+
3101
+ /* COPY OR MOVE (#221, 14-11): a wizard over the page, a sheet of the whole screen on a phone. Its cards are
3102
+ choices (radios): the one chosen in brass. Its sheep: a clone sliding out of it, or walking along. */
3103
+ #where-row .set-control button { white-space: nowrap; }
3104
+ #cm { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 14px 14px 12px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgb(0 0 0 / .35); }
3105
+ #cm::backdrop { background: rgb(0 0 0 / .45); }
3106
+ #cm > div { display: flex; flex-direction: column; gap: 8px; }
3107
+ #cm #cm-copy-part, #cm #cm-move-part { display: flex; flex-direction: column; gap: 8px; }
3108
+ #cm [hidden] { display: none !important; }
3109
+ #cm .cm-head { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 4px; }
3110
+ #cm h2 { margin: 0; font-size: 1rem; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
3111
+ .cm-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
3112
+ .cm-places { display: grid; gap: 8px; }
3113
+ .cm-card { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 8px 11px; text-align: left; background: transparent; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); }
3114
+ .cm-card:hover:not(:disabled) { border-color: var(--ink2); }
3115
+ .cm-card[aria-checked="true"] { border-color: var(--brass); background: color-mix(in srgb, var(--brass) 10%, transparent); }
3116
+ .cm-card small { font-size: .75rem; font-weight: 400; color: var(--ink2); overflow-wrap: anywhere; }
3117
+ .cm-label { margin: 2px 0 0; font-size: .75rem; color: var(--ink2); }
3118
+ .cm-new { display: flex; gap: 8px; }
3119
+ #cm .cm-new input { flex: 1; width: auto; min-width: 0; }
3120
+ #cm .cm-new select { flex: none; width: auto; }
3121
+ .cm-why { margin: 0; font-size: .8125rem; color: var(--danger); }
3122
+ .cm-goes { list-style: none; margin: 2px 0 0; padding: 0; font-size: .875rem; color: var(--ok); }
3123
+ .cm-goes li::before { content: "\2713\00a0"; }
3124
+ .cm-not { margin: 0; font-size: .75rem; color: var(--ink2); }
3125
+ .cm-box { margin: 0; padding: 8px 11px; font-size: .875rem; border: 1px solid var(--line); border-radius: 8px; }
3126
+ .cm-box.cm-danger { color: var(--danger); border-color: var(--danger); font-weight: 600; }
3127
+ .cm-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
3128
+ @media (max-width: 480px) {
3129
+ #cm { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 16px; }
3130
+ #cm[open] { display: flex; flex-direction: column; }
3131
+ #cm > div:not(.cm-head) { flex: 1; }
3132
+ #cm .cm-acts { margin-top: auto; padding-top: 8px; }
3133
+ #cm .cm-acts button { flex: 1; padding: 10px; }
3134
+ }
3135
+ .cm-sheep { position: relative; flex: none; width: 76px; height: 34px; margin: 0; overflow: hidden; }
3136
+ .cm-sheep .cm-one { position: absolute; left: 0; top: 0; width: 45px; height: 34px; margin: 0; }
3137
+ .cm-sheep .m-fill { fill: var(--panel); }
3138
+ .cm-sheep .cm-one:first-child { z-index: 1; }
3139
+ .cm-sheep[data-kind="move"] .cm-one + .cm-one { display: none; }
3140
+ @media (prefers-reduced-motion: no-preference) {
3141
+ .cm-sheep[data-kind="copy"] .cm-one + .cm-one { animation: cm-clone 2.5s ease-in-out infinite; }
3142
+ .cm-sheep[data-kind="move"] .cm-one:first-child { animation: cm-walk 2.5s linear infinite; }
3143
+ .cm-sheep[data-kind="move"] .m-legs { animation: cm-step .3s ease-in-out infinite alternate; }
3144
+ }
3145
+ @keyframes cm-clone { 0%, 15% { transform: translateX(0); opacity: 0; } 25% { opacity: 1; } 60%, 85% { transform: translateX(30px); opacity: 1; } 100% { transform: translateX(30px); opacity: 0; } }
3146
+ @keyframes cm-walk { 0% { transform: translateX(-24px); opacity: 0; } 15%, 80% { opacity: 1; } 100% { transform: translateX(56px); opacity: 0; } }
3147
+ @keyframes cm-step { to { transform: translateY(-2px); } }
3148
+ /* A copy's end: one line under the top bar, clear of the keys at the bottom. */
3149
+ .cm-toast { position: fixed; z-index: 70; left: 50%; top: 60px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 6px 6px 6px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / .35); font-size: .875rem; }
3150
+ .cm-toast > span { min-width: 0; overflow-wrap: anywhere; }
3151
+ .cm-toast[data-tone="ok"] > span { color: var(--ok); }
3152
+ .cm-toast[data-tone="bad"] > span { color: var(--danger); }
3153
+ .cm-toast button { flex: none; }