clavarium 0.2.221-beta.1 → 0.2.222-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.
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/api.mjs +4 -0
- package/server/demandes.mjs +2 -0
- package/server/main.mjs +3 -0
- package/server/settingswords.mjs +20 -0
- package/server/sshconsole.mjs +99 -0
- package/server/tethers.mjs +9 -0
- package/web/app.js +306 -4
- package/web/style.css +73 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.222-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.222-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.
|
|
17
|
+
"clavarium-tether": "0.1.0-next.72",
|
|
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.
|
|
804
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
805
|
-
"integrity": "sha512-
|
|
803
|
+
"version": "0.1.0-next.72",
|
|
804
|
+
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.72.tgz",
|
|
805
|
+
"integrity": "sha512-v8dr19nsZ+hY8GTZd0aLy6G5FP430yruhOZKVhjcQhJtT9X2iTnCzT8LNseEdSkHZ4pHPrfy00VxfvlPp13rAQ==",
|
|
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.
|
|
3
|
+
"version": "0.2.222-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.
|
|
51
|
+
"clavarium-tether": "0.1.0-next.72",
|
|
52
52
|
"mammoth": "1.13.0",
|
|
53
53
|
"mermaid": "11.17.2",
|
|
54
54
|
"node-pty": "^1.1.0",
|
package/server/api.mjs
CHANGED
|
@@ -175,6 +175,8 @@
|
|
|
175
175
|
* POST /api/tether/agenda {target, from?, to?}: a calendar's events of a window, read now (agenda.mjs)
|
|
176
176
|
* POST /api/tether/mail-list|mail-read {target, folder?, text?} | {target, id, folder?}: a mailbox's latest messages, one as text (mailview.mjs)
|
|
177
177
|
* POST /api/tether/contacts|contact {target, text?} | {target, id}: an address book's contacts, one (contactview.mjs)
|
|
178
|
+
* POST /api/tether/console-journal {target}: a machine's shared console, its short journal (sshconsole.mjs);
|
|
179
|
+
* the console itself is a WebSocket, /api/tether/console?target=ID
|
|
178
180
|
* POST /api/files/import?c=...&r=...&p=<folder>&name=<file name>[&dir=<subfolders>&exists=keep|replace|skip&batch=<id>] the body IS the file
|
|
179
181
|
* GET /api/files/thumb|text POST /api/files/save|make|rename|move|remove|taken ?c=...&r=...&p=... (see files.mjs)
|
|
180
182
|
*
|
|
@@ -192,6 +194,7 @@ import { VmUnknown } from './vm.mjs';
|
|
|
192
194
|
import { list, download, importFile, page, PAGE_HEADERS, changeRoute, IMAGE_HEADERS, mailFile, mailPage } from './files.mjs';
|
|
193
195
|
import { mailRoute } from './mailref.mjs';
|
|
194
196
|
import { readAgenda } from './agenda.mjs';
|
|
197
|
+
import { consoleJournal } from './sshconsole.mjs';
|
|
195
198
|
import { readMailList, readMail } from './mailview.mjs';
|
|
196
199
|
import { readContacts, readContact } from './contactview.mjs';
|
|
197
200
|
import { WORK_TAB } from './resources.mjs';
|
|
@@ -735,6 +738,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
735
738
|
/* A mailbox's latest messages and one as text, an address book's contacts and one, read the same way (16-11:
|
|
736
739
|
mailview.mjs, contactview.mjs): never marked read, nothing changed. */
|
|
737
740
|
const peek = { '/api/tether/mail-list': readMailList, '/api/tether/mail-read': readMail, '/api/tether/contacts': readContacts, '/api/tether/contact': readContact }[pathname];
|
|
741
|
+
if (pathname === '/api/tether/console-journal' && tethers) return send(200, await consoleJournal(tethers, body ?? {})), true;
|
|
738
742
|
if (peek && tethers) return send(200, await peek(tethers, body ?? {}, { who: { id: `person:${identity || 'owner'}`, name: identity || 'Owner' } })), true;
|
|
739
743
|
/* A mailbox's signature (Markdown), added under what the agent sends from it. */
|
|
740
744
|
if (pathname === '/api/tether/signature' && tethers) {
|
package/server/demandes.mjs
CHANGED
|
@@ -220,6 +220,8 @@ export function demandeView(q) {
|
|
|
220
220
|
if (c.command || c.text) { v.code = String(c.command ?? c.text); sub.push(v.code.split('\n')[0].slice(0, 60)); }
|
|
221
221
|
v.yes = c.action === 'run' ? 'run' : c.action === 'type' ? 'type' : 'open';
|
|
222
222
|
if (c.action === 'run') v.irreversible = true;
|
|
223
|
+
/* A destructive line (Tether: rm -r, mkfs, reboot...): marked, never in Accept all, said as final. */
|
|
224
|
+
if (c.destructive) { v.irreversible = true; if (!v.risk.includes(w('req-risk-final'))) v.risk.push(w('req-risk-final')); }
|
|
223
225
|
} else if (c.kind === 'files') {
|
|
224
226
|
v.title = c.action === 'write' ? w('req-files-write', { path: String(c.path) }) : c.action === 'delete' ? w('req-files-delete', { path: String(c.path) }) : c.action === 'move' ? w('req-files-move', { from: String(c.from), to: String(c.to) }) : `${c.action ?? 'files'} ${c.path ?? ''}`.trim();
|
|
225
227
|
if (where) sub.push(where);
|
package/server/main.mjs
CHANGED
|
@@ -96,6 +96,7 @@ import { Desks, handleDesktop } from './desktop.mjs';
|
|
|
96
96
|
import { ApiKeys, handleExternal, handleApiKeys, statusOf } from './apikeys.mjs';
|
|
97
97
|
import { RelayJoin, handleRelayJoin, RELAY_JOIN_PATH } from './relayjoin.mjs';
|
|
98
98
|
import { WebSocketServer } from 'ws';
|
|
99
|
+
import { attachConsole } from './sshconsole.mjs';
|
|
99
100
|
import { copyWorkFolder } from './copywork.mjs';
|
|
100
101
|
import { accessesOf, relinkAccesses } from './carry.mjs';
|
|
101
102
|
import { Jobs, withUpdates } from './jobs.mjs';
|
|
@@ -921,6 +922,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
921
922
|
let closing = false;
|
|
922
923
|
boxes.attach(server, WebSocketServer);
|
|
923
924
|
browsers.attach(server, WebSocketServer); server.on('close', () => browsers.shutdown());
|
|
925
|
+
/* A machine's shared SSH console, live in its asset panel (sshconsole.mjs): the same checks as the terminal. */
|
|
926
|
+
attachConsole(server, { tethers, gate, originOk });
|
|
924
927
|
/* The wake word's weekly threshold tuning (Sunday from 03:00, each box's own time): looked at every 10 minutes. */
|
|
925
928
|
const wakeWeekly = setInterval(() => { try { boxes.wakeWeekly(); } catch (error) { console.error(`wake tuning: ${error.message}`); } }, 10 * 60_000); wakeWeekly.unref?.(); server.on('close', () => clearInterval(wakeWeekly));
|
|
926
929
|
/* A collect session's clock: the stations asked, its end, the speaker told to stop (boxcollect.mjs). */
|
package/server/settingswords.mjs
CHANGED
|
@@ -336,6 +336,26 @@ export const SETTINGS_WORDS_FR = {
|
|
|
336
336
|
'desk-add-rooms': 'Salons', 'desk-add-assets': 'Assets', 'desk-add-more': 'Dossiers', 'desk-add-all': 'Tout est déjà sur le bureau',
|
|
337
337
|
'desk-added': 'Ajouté au bureau', 'desk-editing': 'Mode modification', 'desk-drop-folder': 'Lâcher : faire un dossier',
|
|
338
338
|
'desk-drop-into': 'Lâcher : mettre dans le dossier', 'desk-create': 'Créer', 'desk-new-conv': 'Nouvelle conversation', 'desk-new-room': 'Nouveau salon',
|
|
339
|
+
/* A machine's shared console (16-11, app.js consoleParts). */
|
|
340
|
+
'set-sc-title': 'Console', 'set-sc-console': 'Console', 'set-sc-keys': 'Touches', 'set-sc-take': 'Reprendre la main', 'set-sc-hide-ai': 'Cacher à l’IA',
|
|
341
|
+
'set-sc-show-ai': 'Montrer à l’IA', 'set-sc-secret': 'Saisie cachée', 'set-sc-ctrlc': 'Interrompt ce qui tourne', 'set-sc-full': 'Plein écran',
|
|
342
|
+
'set-sc-leave-full': 'Quitter le plein écran', 'set-sc-reopen': 'Rouvrir', 'set-sc-chat': 'Chat', 'set-sc-chat-of': 'Chat de',
|
|
343
|
+
'set-sc-chat-off': 'Le chat de cette conversation est coupé.', 'set-sc-no-holder': 'Aucune conversation n’a cette machine.',
|
|
344
|
+
'set-sc-you': 'Vous', 'set-sc-you-av': 'V', 'set-sc-you-hidden': 'tapez (caché)', 'set-sc-you-watch': 'regardez', 'set-sc-you-control': 'aux commandes',
|
|
345
|
+
'set-sc-ai-av': 'IA', 'set-sc-ai-blind': 'ne voit plus', 'set-sc-ai-typing': 'tape', 'set-sc-ai-proposes': 'propose', 'set-sc-ai-watching': 'regarde',
|
|
346
|
+
'set-sc-no-ai': 'Aucun assistant dessus', 'set-sc-live': 'en direct', 'set-sc-connecting': 'connexion…', 'set-sc-off': 'fermée',
|
|
347
|
+
'set-sc-failed': 'La console n’a pas pu s’ouvrir.', 'set-sc-closed': 'La console est fermée.', 'set-sc-connecting-long': 'Connexion à la machine…',
|
|
348
|
+
'set-sc-hidden-prompt': 'Mot de passe demandé : saisie cachée à l’IA.', 'set-sc-hidden': 'Saisie cachée : l’IA ne voit rien.',
|
|
349
|
+
'set-sc-typing': '{name} tape. Une touche reprend la main.', 'set-sc-hidden-ai': 'Caché à l’IA jusqu’à « Montrer ».', 'set-sc-control': 'Vous avez la main.',
|
|
350
|
+
'set-sc-in-full': 'La console est en plein écran.', 'set-sc-ai-title': 'Assistant', 'set-sc-journal': 'Journal',
|
|
351
|
+
'set-sc-j-empty': 'Chaque saisie de l’IA est gardée ici.', 'set-sc-typed': 'Ses dernières saisies', 'set-sc-ai-none': 'Rien de proposé. Il suit la console.',
|
|
352
|
+
'set-sc-j-took': 'a repris la main', 'set-sc-j-prompt': 'mot de passe : saisie cachée', 'set-sc-j-hidden': 'saisie cachée', 'set-sc-j-hide-ai': 'caché à l’IA',
|
|
353
|
+
'set-sc-j-show-ai': 'montré à l’IA', 'set-sc-j-refused': 'refusée', 'set-sc-j-dropped': 'pas envoyée', 'set-sc-j-failed': 'pas faite', 'set-sc-j-edited': 'modifiée par vous',
|
|
354
|
+
'set-sc-destructive': 'Destructif', 'set-sc-to-approve': 'À valider', 'set-sc-run-apart': 'Lancée à part, montrée dans la console.',
|
|
355
|
+
'set-sc-risk-erase': 'Efface des fichiers. Sans retour.', 'set-sc-risk-disk': 'Écrase un disque. Sans retour.', 'set-sc-risk-power': 'Arrête ou redémarre la machine.',
|
|
356
|
+
'set-sc-risk-rights': 'Change les droits de tout le système.', 'set-sc-risk-other': 'Peut casser la machine.',
|
|
357
|
+
'set-sc-send': 'Envoyer', 'set-sc-send-anyway': 'Envoyer quand même', 'set-sc-sure': 'Sûr ? Envoyer', 'set-sc-edit': 'Modifier', 'set-sc-refuse': 'Refuser',
|
|
358
|
+
'set-sc-edit-line': 'La ligne à envoyer', 'set-sc-send-edited': 'Envoyer modifiée',
|
|
339
359
|
'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',
|
|
340
360
|
};
|
|
341
361
|
export const settingsWords = (lang) => (String(lang ?? '').toLowerCase().split('-')[0] === 'fr' ? { ...SETTINGS_WORDS_FR } : {});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* A MACHINE'S SHARED CONSOLE, SEEN BY ITS PERSON (16-11): the live SSH console of a machine asset (a Tether target
|
|
2
|
+
* of kind ssh), shown in its asset panel. ONE shell per machine, kept by Tether's keeper in this server: the person
|
|
3
|
+
* streams it from the page, the conversations given the machine reach the same shell through terminal.open / read /
|
|
4
|
+
* type (Tether's console.mjs says who sees and types what: the person's key always wins, password prompts hide the
|
|
5
|
+
* input from the AI, « hide from the AI », destructive lines always asked).
|
|
6
|
+
*
|
|
7
|
+
* WebSocket /api/tether/console?target=ID[&cols=N&rows=N]
|
|
8
|
+
* browser -> server binary frame keystrokes (the person's own: never read here, never kept)
|
|
9
|
+
* text frame {"type":"resize","cols":n,"rows":n} | {"type":"hidden","on":bool}
|
|
10
|
+
* | {"type":"hide-ai","on":bool} | {"type":"take-back"} | {"type":"interrupt"}
|
|
11
|
+
* server -> browser binary frame what the machine prints (first: the screen so far, for a page that comes back)
|
|
12
|
+
* text frame {"type":"ready","state":{...}} | {"type":"state","state":{...}}
|
|
13
|
+
* | {"type":"error","text":...} then close 1011
|
|
14
|
+
* close 1000 the shell ended (the page offers to open it again)
|
|
15
|
+
*
|
|
16
|
+
* POST /api/tether/console-journal {target} -> { lines: [...] }: the console's short journal -- the agents' inputs
|
|
17
|
+
* (sent, refused, edited, destructive), control taken back, input hidden; never
|
|
18
|
+
* what the person typed (Tether never journals it).
|
|
19
|
+
*
|
|
20
|
+
* THE SAME CHECKS AS THE TERMINAL BRIDGE (bridge.mjs): this site's own pages only (the Origin, compared by hand: a
|
|
21
|
+
* WebSocket is not covered by the same-origin policy), past the gate (a signed-in operator, as every asset route);
|
|
22
|
+
* a machine that exists. A device's page (/c/) has no way here: its console is not given to devices. What the
|
|
23
|
+
* machine prints is carried, never parsed nor kept here; the page draws it with xterm only (never as HTML). */
|
|
24
|
+
import { WebSocketServer } from 'ws';
|
|
25
|
+
import { Refusal } from './conversations.mjs';
|
|
26
|
+
import { IDENTITY_HEADER } from './gate.mjs';
|
|
27
|
+
|
|
28
|
+
export const CONSOLE_PATH = '/api/tether/console';
|
|
29
|
+
export const KEYS_MAX = 64 * 1024;
|
|
30
|
+
export const JOURNAL_MAX = 30;
|
|
31
|
+
const CLOSE_ENDED = 1000;
|
|
32
|
+
const CLOSE_FAILED = 1011;
|
|
33
|
+
|
|
34
|
+
const whoOf = (headers) => {
|
|
35
|
+
const identity = String(headers?.[IDENTITY_HEADER] ?? '').trim().toLowerCase();
|
|
36
|
+
return { id: `person:${identity || 'owner'}`, name: identity || 'Owner' };
|
|
37
|
+
};
|
|
38
|
+
const machineOf = (tethers, id) => {
|
|
39
|
+
const t = tethers?.store().target(String(id ?? ''));
|
|
40
|
+
return t && t.kind === 'ssh' ? t : null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function attachConsole(server, { tethers, gate = () => 'local', originOk }) {
|
|
44
|
+
const sockets = new WebSocketServer({ noServer: true, maxPayload: KEYS_MAX });
|
|
45
|
+
server.on('upgrade', (request, socket, head) => {
|
|
46
|
+
const url = new URL(request.url ?? '/', 'http://local');
|
|
47
|
+
if (url.pathname !== CONSOLE_PATH) return;
|
|
48
|
+
const target = machineOf(tethers, url.searchParams.get('target'));
|
|
49
|
+
if (!originOk(request.headers) || gate(request.headers) === undefined || !target) { socket.destroy(); return; }
|
|
50
|
+
const cols = Number(url.searchParams.get('cols')); const rows = Number(url.searchParams.get('rows'));
|
|
51
|
+
sockets.handleUpgrade(request, socket, head, (ws) => { void seat(ws, target, whoOf(request.headers), { cols, rows }); });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
async function seat(ws, target, who, { cols, rows }) {
|
|
55
|
+
const send = (data, binary = false) => { if (ws.readyState === 1) ws.send(data, { binary }); };
|
|
56
|
+
let handle = null; let gone = false; const early = [];
|
|
57
|
+
const onEvent = (e) => {
|
|
58
|
+
if (!handle) { early.push(e); return; }
|
|
59
|
+
if (e.type === 'data') send(Buffer.from(e.data, 'utf8'), true);
|
|
60
|
+
else if (e.type === 'state') send(JSON.stringify({ type: 'state', state: e.state }));
|
|
61
|
+
else if (e.type === 'closed') { try { ws.close(CLOSE_ENDED, 'ended'); } catch { /* gone */ } }
|
|
62
|
+
};
|
|
63
|
+
ws.on('close', () => { gone = true; handle?.detach(); });
|
|
64
|
+
try { handle = await tethers.console(target.id, who, onEvent); } catch (error) {
|
|
65
|
+
send(JSON.stringify({ type: 'error', text: String(error?.message ?? error) }));
|
|
66
|
+
try { ws.close(CLOSE_FAILED, 'failed'); } catch { /* gone */ }
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (gone) { handle.detach(); return; }
|
|
70
|
+
handle.resize(cols, rows);
|
|
71
|
+
send(JSON.stringify({ type: 'ready', state: handle.state() }));
|
|
72
|
+
if (handle.replay) send(Buffer.from(handle.replay, 'utf8'), true);
|
|
73
|
+
/* What came meanwhile is in the replay already: only the latest state is said again. */
|
|
74
|
+
if (early.some((e) => e.type === 'closed')) { try { ws.close(CLOSE_ENDED, 'ended'); } catch { /* gone */ } return; }
|
|
75
|
+
ws.on('message', (data, binary) => {
|
|
76
|
+
if (binary) { handle.write(Buffer.from(data).toString('utf8')); return; }
|
|
77
|
+
let m; try { m = JSON.parse(String(data)); } catch { return; }
|
|
78
|
+
if (m?.type === 'resize') handle.resize(Number(m.cols), Number(m.rows));
|
|
79
|
+
else if (m?.type === 'hidden') handle.hidden(m.on === true);
|
|
80
|
+
else if (m?.type === 'hide-ai') handle.hideFromAi(m.on === true);
|
|
81
|
+
else if (m?.type === 'take-back') handle.takeBack();
|
|
82
|
+
else if (m?.type === 'interrupt') handle.interrupt();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return sockets;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* The console's short journal: the newest first, its agents' inputs and its events. */
|
|
89
|
+
export async function consoleJournal(tethers, body = {}) {
|
|
90
|
+
const target = machineOf(tethers, body.target);
|
|
91
|
+
if (!target) throw new Refusal(404, 'No such machine.');
|
|
92
|
+
const r = await tethers.act('journal', { target: target.id, limit: 200 }, '');
|
|
93
|
+
if (!r.ok) throw new Refusal(502, r.text);
|
|
94
|
+
const lines = (Array.isArray(r.data) ? r.data : []).filter((l) => l.op === 'console' || String(l.verb ?? '').startsWith('terminal.') && l.verb !== 'terminal.read' && l.verb !== 'terminal.open')
|
|
95
|
+
.slice(0, JOURNAL_MAX)
|
|
96
|
+
.map((l) => ({ at: l.at, ...(l.op ? { op: l.op } : {}), ...(l.verb ? { verb: l.verb } : {}), detail: String(l.detail ?? ''), ...(l.agent?.name ? { agent: l.agent.name } : {}), ...(l.by?.name ? { by: l.by.name } : {}),
|
|
97
|
+
...(l.decision ? { decision: l.decision } : {}), ...(l.ok !== undefined ? { ok: l.ok } : {}), ...(l.risk ? { risk: l.risk } : {}), ...(l.edited ? { edited: true } : {}), ...(l.error ? { error: String(l.error) } : {}) }));
|
|
98
|
+
return { lines };
|
|
99
|
+
}
|
package/server/tethers.mjs
CHANGED
|
@@ -304,6 +304,15 @@ export class Tethers {
|
|
|
304
304
|
return this.#keeper.read(String(verb ?? ''), args && typeof args === 'object' ? args : {}, by);
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/* A MACHINE'S SHARED CONSOLE, for the person's page (sshconsole.mjs): one shell per machine, the conversations given
|
|
308
|
+
it on the same one. `who`: { id, name }, the person the caller has already checked; `onEvent` gets what the machine
|
|
309
|
+
prints and the console's state. -> Tether's handle (write, resize, hidden, hideFromAi, takeBack, interrupt, detach). */
|
|
310
|
+
console(target, who, onEvent) {
|
|
311
|
+
const by = { id: String(who?.id ?? 'person:owner'), name: String(who?.name ?? 'Owner') };
|
|
312
|
+
if (typeof this.#keeper.console !== 'function') throw new Error('this Tether has no shared console');
|
|
313
|
+
return this.#keeper.console(String(target ?? ''), by, onEvent);
|
|
314
|
+
}
|
|
315
|
+
|
|
307
316
|
/* The store behind it, for the Assets page to create/give/remove targets. */
|
|
308
317
|
store() { return this.#keeper.store; }
|
|
309
318
|
|
package/web/app.js
CHANGED
|
@@ -483,13 +483,15 @@
|
|
|
483
483
|
document.addEventListener('keydown', (event) => {
|
|
484
484
|
if (event.key !== 'Escape' || event.defaultPrevented || event.isComposing) return;
|
|
485
485
|
const target = event.target instanceof Element ? event.target : null;
|
|
486
|
-
if (target?.closest('#terminal')) return;
|
|
486
|
+
if (target?.closest('#terminal, .sc-screen')) return;
|
|
487
487
|
if (target?.matches('input:not([type=checkbox]):not([type=radio]):not([type=button]), textarea, select, [contenteditable]:not([contenteditable=false])')) { target.blur(); return; }
|
|
488
488
|
if (nav.back()) event.preventDefault();
|
|
489
489
|
});
|
|
490
490
|
|
|
491
491
|
/* ---------- the terminal ---------- */
|
|
492
|
-
|
|
492
|
+
/* ONE TERMINAL, everywhere a terminal is drawn (a conversation's, a machine's shared console): the same xterm,
|
|
493
|
+
the same font and theme, the same links. What it is given to draw is only ever drawn by it, never as HTML. */
|
|
494
|
+
const terminalOptions = () => ({
|
|
493
495
|
cursorBlink: true, scrollback: 5000,
|
|
494
496
|
fontSize: innerWidth < 500 ? 11 : 14,
|
|
495
497
|
fontFamily: 'ui-monospace, Menlo, Consolas, monospace',
|
|
@@ -498,6 +500,7 @@
|
|
|
498
500
|
tab, with no way back to this page; anything else is not followed. */
|
|
499
501
|
linkHandler: { activate: (_event, uri) => openWeb(uri), allowNonHttpProtocols: false },
|
|
500
502
|
});
|
|
503
|
+
const terminal = new Terminal(terminalOptions());
|
|
501
504
|
/* A web address on screen opens in a new tab, on its own: nothing of this
|
|
502
505
|
page is handed to it. Only http and https. */
|
|
503
506
|
function openWeb(uri) {
|
|
@@ -981,7 +984,13 @@
|
|
|
981
984
|
A click from the keyboard (Enter or Space on the focused button)
|
|
982
985
|
sends once. */
|
|
983
986
|
const stopRepeats = new Set();
|
|
984
|
-
|
|
987
|
+
/* THE KEYS BAR, one behaviour wherever it is (a conversation's #keys, a machine's console): each button's
|
|
988
|
+
data-keys, sent to `sendKeys`, the focus given back by `focusBack`. */
|
|
989
|
+
function wireKeys(buttons, sendKeys, focusBack) {
|
|
990
|
+
for (const button of buttons) wireKey(button, sendKeys, focusBack);
|
|
991
|
+
}
|
|
992
|
+
wireKeys(document.querySelectorAll('#keys button[data-keys]'), (keys) => send(keys), () => focusTerminal());
|
|
993
|
+
function wireKey(button, send, focusTerminal) {
|
|
985
994
|
const key = button.dataset.keys;
|
|
986
995
|
let delay = null; let every = null;
|
|
987
996
|
const stop = () => { clearTimeout(delay); clearInterval(every); delay = null; every = null; };
|
|
@@ -6127,6 +6136,8 @@
|
|
|
6127
6136
|
/* A CALENDAR'S AGENDA (16-11): its events, under who has it -- read through Tether as the owner's own read
|
|
6128
6137
|
(agenda.mjs), so the calendar need not stay open elsewhere. The owner's page only: a device reads no calendar. */
|
|
6129
6138
|
if (t?.kind === 'calendar' && !DEVICE) parts.push(agendaPart(t));
|
|
6139
|
+
/* A MACHINE'S SHARED CONSOLE (16-11): live, under who has it (sshconsole.mjs). The owner's page only: not given to devices. */
|
|
6140
|
+
if (t?.kind === 'ssh' && !DEVICE) parts.push(...consoleParts(t, tether, from));
|
|
6130
6141
|
/* A MAILBOX'S MAIL, AN ADDRESS BOOK'S CONTACTS (16-11): read the same way (mailview.mjs, contactview.mjs). */
|
|
6131
6142
|
if (t?.kind === 'mail' && !DEVICE) parts.push(mailPart(t));
|
|
6132
6143
|
if (t?.kind === 'contacts' && !DEVICE) parts.push(contactsPart(t));
|
|
@@ -6194,7 +6205,8 @@
|
|
|
6194
6205
|
/* An MCP server's rights say themselves (Off / Read / All with approval / All / Custom): no levels' words under them. */
|
|
6195
6206
|
if (t.kind !== 'mcp') parts.push(el('p', 'hint', 'A level is: watch (read only), propose (asks before each action), frame (acts within its rules, asks for the rest), free (acts, kept in the journal).'));
|
|
6196
6207
|
/* Calls waiting for a person (propose/frame). Accept or refuse each. */
|
|
6197
|
-
|
|
6208
|
+
/* A machine's terminal inputs are proposed beside its console (consoleAsk), not here again. */
|
|
6209
|
+
const waiting = (Array.isArray(tether.approvals) ? tether.approvals : []).filter((q) => (q.target?.id ?? q.target) === t.id && !(t.kind === 'ssh' && !DEVICE && String(q.verb ?? '').startsWith('terminal.')));
|
|
6198
6210
|
if (waiting.length) {
|
|
6199
6211
|
const box = el('div', 'as-users');
|
|
6200
6212
|
for (const q of waiting) {
|
|
@@ -6363,6 +6375,296 @@
|
|
|
6363
6375
|
}
|
|
6364
6376
|
agendaDays(holder, answer);
|
|
6365
6377
|
}
|
|
6378
|
+
/* A MACHINE'S SHARED CONSOLE (16-11): the live SSH console of a machine asset, under who has it -- ONE shell that
|
|
6379
|
+
the person and the conversations given the machine share (Tether's console.mjs, through sshconsole.mjs). Drawn by
|
|
6380
|
+
the same terminal as a conversation's (terminalOptions, xterm: what the machine prints is never HTML here), with
|
|
6381
|
+
the same keys bar (wireKeys). Big: most of the panel's height. Under it, the AI's proposals (Send / Edit / Refuse,
|
|
6382
|
+
destructive marked, sent in two steps) and its inputs, then a short journal. Full screen: the console large and,
|
|
6383
|
+
beside it (under it on a phone), the chat of the conversation that holds the machine (Parley's own view). The
|
|
6384
|
+
person's key always wins; « Take back control », « Hidden input », « Hide from the AI », Ctrl C.
|
|
6385
|
+
KEPT ACROSS PAINTS: the panel is drawn again with every Tether change, the console is not -- its element (and its
|
|
6386
|
+
terminal, its socket) is the same one, moved into the new panel, its focus given back. */
|
|
6387
|
+
const consoleViews = new Map(); /* target id -> view */
|
|
6388
|
+
const SC_KEYS = [['esc', 'Esc'], ['tab', 'Tab'], ['left', '←'], ['down', '↓'], ['up', '↑'], ['right', '→'], ['enter', 'Enter'], ['stop', 'Ctrl+C']];
|
|
6389
|
+
const SC_RISK = {
|
|
6390
|
+
erase: ['set-sc-risk-erase', 'Erases files. No way back.'], disk: ['set-sc-risk-disk', 'Writes over a disk. No way back.'],
|
|
6391
|
+
power: ['set-sc-risk-power', 'Stops or restarts the machine.'], rights: ['set-sc-risk-rights', 'Changes rights on the whole system.'],
|
|
6392
|
+
other: ['set-sc-risk-other', 'Can break the machine.'],
|
|
6393
|
+
};
|
|
6394
|
+
const SC_EVENTS = {
|
|
6395
|
+
'control taken back from the AI': ['set-sc-j-took', 'took back control'], 'input hidden: a password prompt': ['set-sc-j-prompt', 'password prompt: input hidden'],
|
|
6396
|
+
'input hidden by the person': ['set-sc-j-hidden', 'hidden input'], 'hidden from the AI': ['set-sc-j-hide-ai', 'hidden from the AI'], 'shown to the AI again': ['set-sc-j-show-ai', 'shown to the AI again'],
|
|
6397
|
+
};
|
|
6398
|
+
const scButton = (cls, text) => { const b = el('button', cls, text); b.type = 'button'; return b; };
|
|
6399
|
+
const hhmm = (at) => { const d = new Date(at); return Number.isNaN(d.getTime()) ? '' : d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); };
|
|
6400
|
+
function consoleView(target) {
|
|
6401
|
+
let v = consoleViews.get(target.id);
|
|
6402
|
+
if (v) { v.target = target; return v; }
|
|
6403
|
+
v = { id: target.id, target, state: null, socket: null, phase: 'connecting', focused: false, full: false, chat: null, chatOf: '', chatPick: '', waiting: [], opened: false, retry: 0, away: 0, from: '' };
|
|
6404
|
+
consoleViews.set(target.id, v);
|
|
6405
|
+
const root = el('div', 'sc'); root.dataset.target = target.id;
|
|
6406
|
+
const presence = el('div', 'sc-presence'); presence.setAttribute('aria-live', 'polite');
|
|
6407
|
+
const screen = el('div', 'sc-screen'); screen.setAttribute('role', 'log'); screen.setAttribute('aria-label', uiSaid('set-sc-console', 'Console'));
|
|
6408
|
+
const banner = el('div', 'sc-state'); banner.setAttribute('aria-live', 'assertive');
|
|
6409
|
+
const keys = el('div', 'sc-keys'); keys.setAttribute('role', 'group'); keys.setAttribute('aria-label', uiSaid('set-sc-keys', 'Keys'));
|
|
6410
|
+
for (const [k, label] of SC_KEYS) { const b = scButton(k === 'stop' ? 'careful' : '', label); b.dataset.keys = k; keys.append(b); }
|
|
6411
|
+
const take = scButton('danger sc-take', uiSaid('set-sc-take', 'Take back control')); take.hidden = true;
|
|
6412
|
+
const hideAi = scButton('sc-hide-ai', uiSaid('set-sc-hide-ai', 'Hide from the AI')); hideAi.setAttribute('aria-pressed', 'false');
|
|
6413
|
+
const secret = scButton('sc-secret', uiSaid('set-sc-secret', 'Hidden input')); secret.setAttribute('aria-pressed', 'false');
|
|
6414
|
+
const ctrlc = scButton('quiet sc-ctrlc', 'Ctrl C'); ctrlc.title = uiSaid('set-sc-ctrlc', 'Interrupts what is running');
|
|
6415
|
+
const full = scButton('quiet sc-full-btn', uiSaid('set-sc-full', 'Full screen')); full.setAttribute('aria-pressed', 'false');
|
|
6416
|
+
const reopen = scButton('primary sc-reopen', uiSaid('set-sc-reopen', 'Open it again')); reopen.hidden = true;
|
|
6417
|
+
const tools = el('div', 'sc-tools'); tools.append(take, hideAi, secret, el('span', 'sc-space'), ctrlc, full);
|
|
6418
|
+
const main = el('div', 'sc-main'); main.append(presence, screen, banner, keys, tools);
|
|
6419
|
+
/* Full screen: the chat of a conversation that holds the machine, beside the console. */
|
|
6420
|
+
const chatHead = el('div', 'sc-chat-head');
|
|
6421
|
+
const chatBox = el('div', 'sc-chat-thread');
|
|
6422
|
+
const side = el('aside', 'sc-chat'); side.setAttribute('aria-label', uiSaid('set-sc-chat', 'Chat')); side.hidden = true; side.append(chatHead, chatBox);
|
|
6423
|
+
root.append(main, side);
|
|
6424
|
+
Object.assign(v, { root, presence, screen, banner, take, hideAi, secret, fullBtn: full, reopen, chatHead, chatBox, side });
|
|
6425
|
+
const term = new Terminal({ ...terminalOptions(), scrollback: 3000 });
|
|
6426
|
+
const fitter = new FitAddon.FitAddon(); term.loadAddon(fitter);
|
|
6427
|
+
v.term = term; v.fit = () => { if (v.opened && screen.isConnected && screen.offsetWidth > 0) { try { fitter.fit(); } catch { /* not drawn yet */ } } };
|
|
6428
|
+
new ResizeObserver(() => v.fit()).observe(screen);
|
|
6429
|
+
const sendJson = (m) => { if (v.socket?.readyState === 1) v.socket.send(JSON.stringify(m)); };
|
|
6430
|
+
const sendKeys = (data) => { if (v.socket?.readyState === 1) v.socket.send(new TextEncoder().encode(data)); };
|
|
6431
|
+
v.sendJson = sendJson;
|
|
6432
|
+
term.onData(sendKeys);
|
|
6433
|
+
term.onResize(({ cols, rows }) => sendJson({ type: 'resize', cols, rows }));
|
|
6434
|
+
keys.addEventListener('pointerdown', (event) => { if (event.target.closest('button')) event.preventDefault(); });
|
|
6435
|
+
wireKeys(keys.querySelectorAll('button[data-keys]'), sendKeys, () => term.focus());
|
|
6436
|
+
take.addEventListener('click', () => { sendJson({ type: 'take-back' }); term.focus(); });
|
|
6437
|
+
ctrlc.addEventListener('click', () => { sendJson({ type: 'interrupt' }); term.focus(); });
|
|
6438
|
+
hideAi.addEventListener('click', () => { sendJson({ type: 'hide-ai', on: !(v.state?.hideAi) }); });
|
|
6439
|
+
secret.addEventListener('click', () => { sendJson({ type: 'hidden', on: !(v.state?.hidden) }); term.focus(); });
|
|
6440
|
+
full.addEventListener('click', () => consoleFull(v, !v.full));
|
|
6441
|
+
reopen.addEventListener('click', () => { reopen.hidden = true; consoleConnect(v); });
|
|
6442
|
+
/* Where the focus is, kept across paints: given back once the console is in the new panel. */
|
|
6443
|
+
root.addEventListener('focusin', () => { v.focused = true; });
|
|
6444
|
+
document.addEventListener('pointerdown', (event) => { if (!root.contains(event.target)) v.focused = false; }, true);
|
|
6445
|
+
return v;
|
|
6446
|
+
}
|
|
6447
|
+
function consoleConnect(v) {
|
|
6448
|
+
if (v.socket && v.socket.readyState <= 1) return;
|
|
6449
|
+
v.phase = 'connecting'; consolePaint(v);
|
|
6450
|
+
const scheme = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
6451
|
+
const ws = new WebSocket(`${scheme}://${location.host}${API}/tether/console?${new URLSearchParams({ target: v.id, cols: String(v.term.cols), rows: String(v.term.rows) })}`);
|
|
6452
|
+
ws.binaryType = 'arraybuffer';
|
|
6453
|
+
v.socket = ws;
|
|
6454
|
+
ws.addEventListener('message', (event) => {
|
|
6455
|
+
if (typeof event.data !== 'string') { v.term.write(new Uint8Array(event.data)); return; }
|
|
6456
|
+
let m; try { m = JSON.parse(event.data); } catch { return; }
|
|
6457
|
+
/* Ready: the screen so far comes next, drawn on a clean terminal (a page that came back draws it once). */
|
|
6458
|
+
if (m.type === 'ready') { v.term.reset(); v.phase = 'live'; v.retry = 0; v.state = m.state; consolePaint(v); v.fit(); }
|
|
6459
|
+
else if (m.type === 'state') { const was = v.state; v.state = m.state; consolePaint(v); if (was && !was.typing !== !m.state.typing) consoleSoon(v); }
|
|
6460
|
+
else if (m.type === 'error') { v.phase = 'failed'; v.error = String(m.text ?? ''); consolePaint(v); }
|
|
6461
|
+
});
|
|
6462
|
+
ws.addEventListener('close', (event) => {
|
|
6463
|
+
if (v.socket !== ws) return;
|
|
6464
|
+
v.socket = null;
|
|
6465
|
+
if (v.phase === 'failed') { v.reopen.hidden = false; return; }
|
|
6466
|
+
if (event.code === 1000) { v.phase = 'closed'; consolePaint(v); return; }
|
|
6467
|
+
/* Dropped: again in a moment while it is shown, said meanwhile; never its keys replayed. */
|
|
6468
|
+
v.phase = 'connecting'; consolePaint(v);
|
|
6469
|
+
if (v.root.isConnected && v.retry < 6) { v.retry++; setTimeout(() => { if (v.root.isConnected) consoleConnect(v); }, 1500 * v.retry); }
|
|
6470
|
+
else { v.phase = 'closed'; consolePaint(v); }
|
|
6471
|
+
});
|
|
6472
|
+
}
|
|
6473
|
+
/* After the AI typed: the journal and the proposals read again (a paint of the panel; the console stays). */
|
|
6474
|
+
function consoleSoon(v) { clearTimeout(v.soon); v.soon = setTimeout(() => { if (v.root.isConnected) void repaintAsset(); }, 600); }
|
|
6475
|
+
function consolePaint(v) {
|
|
6476
|
+
const st = v.state ?? {};
|
|
6477
|
+
const typing = st.typing ?? null;
|
|
6478
|
+
v.root.classList.toggle('ai-typing', Boolean(typing));
|
|
6479
|
+
v.root.classList.toggle('hidden-input', Boolean(st.hidden));
|
|
6480
|
+
v.root.classList.toggle('hidden-ai', Boolean(st.hideAi));
|
|
6481
|
+
/* Who has it: you, and each assistant on it -- what it does, in words, never by colour alone. */
|
|
6482
|
+
const chips = [];
|
|
6483
|
+
const me = el('span', `sc-chip me${typing ? '' : ' active'}`); me.append(el('span', 'sc-av', uiSaid('set-sc-you-av', 'Y')), el('span', '', uiSaid('set-sc-you', 'You')), el('small', '', st.hidden ? uiSaid('set-sc-you-hidden', 'typing (hidden)') : typing ? uiSaid('set-sc-you-watch', 'watching') : uiSaid('set-sc-you-control', 'in control')));
|
|
6484
|
+
chips.push(me);
|
|
6485
|
+
for (const a of st.agents ?? []) {
|
|
6486
|
+
const doing = st.hideAi ? uiSaid('set-sc-ai-blind', 'sees nothing') : typing?.agent === a.id ? uiSaid('set-sc-ai-typing', 'typing') : v.waiting.some((q) => q.agent?.id === a.id) ? uiSaid('set-sc-ai-proposes', 'proposes') : uiSaid('set-sc-ai-watching', 'watching');
|
|
6487
|
+
const c = el('span', `sc-chip ai${typing?.agent === a.id ? ' active' : ''}`); c.append(el('span', 'sc-av', uiSaid('set-sc-ai-av', 'AI')), el('span', '', a.name), el('small', '', doing));
|
|
6488
|
+
chips.push(c);
|
|
6489
|
+
}
|
|
6490
|
+
if (!(st.agents ?? []).length) chips.push(el('small', 'hint', uiSaid('set-sc-no-ai', 'No assistant on it now')));
|
|
6491
|
+
const live = el('span', `sc-live${v.phase === 'live' ? ' on' : ''}`, v.phase === 'live' ? uiSaid('set-sc-live', 'live') : v.phase === 'connecting' ? uiSaid('set-sc-connecting', 'connecting…') : uiSaid('set-sc-off', 'closed'));
|
|
6492
|
+
v.presence.replaceChildren(...chips, el('span', 'sc-space'), live);
|
|
6493
|
+
/* The one line that says the state (aria-live). */
|
|
6494
|
+
let text; let tone = '';
|
|
6495
|
+
if (v.phase === 'failed') { text = v.error || uiSaid('set-sc-failed', 'The console could not be opened.'); tone = 'bad'; }
|
|
6496
|
+
else if (v.phase === 'closed') { text = uiSaid('set-sc-closed', 'The console is closed.'); tone = 'pause'; }
|
|
6497
|
+
else if (v.phase === 'connecting') text = uiSaid('set-sc-connecting-long', 'Connecting to the machine…');
|
|
6498
|
+
else if (st.hidden) { text = st.hidden === 'prompt' ? uiSaid('set-sc-hidden-prompt', 'Password asked: hidden input, the AI sees nothing.') : uiSaid('set-sc-hidden', 'Hidden input: the AI sees nothing.'); tone = 'secret'; }
|
|
6499
|
+
else if (typing) { text = uiSaid('set-sc-typing', '{name} is typing. A key takes back control.', { name: typing.name }); tone = 'ai'; }
|
|
6500
|
+
else if (st.hideAi) { text = uiSaid('set-sc-hidden-ai', 'Hidden from the AI until you show it.'); tone = 'pause'; }
|
|
6501
|
+
else text = uiSaid('set-sc-control', 'You are in control.');
|
|
6502
|
+
v.banner.dataset.tone = tone;
|
|
6503
|
+
v.banner.replaceChildren(el('span', '', text), ...(v.phase === 'closed' || v.phase === 'failed' ? [v.reopen] : []));
|
|
6504
|
+
if (v.phase === 'closed' || v.phase === 'failed') v.reopen.hidden = false;
|
|
6505
|
+
v.take.hidden = !typing;
|
|
6506
|
+
v.hideAi.setAttribute('aria-pressed', String(Boolean(st.hideAi)));
|
|
6507
|
+
v.hideAi.textContent = st.hideAi ? uiSaid('set-sc-show-ai', 'Show to the AI') : uiSaid('set-sc-hide-ai', 'Hide from the AI');
|
|
6508
|
+
v.secret.setAttribute('aria-pressed', String(Boolean(st.hidden)));
|
|
6509
|
+
}
|
|
6510
|
+
/* FULL SCREEN: the console large, the chat of its conversation beside it (under it on a phone). Esc (outside the
|
|
6511
|
+
terminal, which keeps its Escape for the machine) or Back leaves. */
|
|
6512
|
+
function consoleFull(v, on) {
|
|
6513
|
+
if (v.full === on) return;
|
|
6514
|
+
v.full = on;
|
|
6515
|
+
v.root.classList.toggle('sc-full', on);
|
|
6516
|
+
v.side.hidden = !on;
|
|
6517
|
+
const b = v.fullBtn;
|
|
6518
|
+
b.setAttribute('aria-pressed', String(on));
|
|
6519
|
+
b.textContent = on ? uiSaid('set-sc-leave-full', 'Leave full screen') : uiSaid('set-sc-full', 'Full screen');
|
|
6520
|
+
document.documentElement.toggleAttribute('data-sc-full', on);
|
|
6521
|
+
/* Over the whole page, out of the panel (drawn again meanwhile, it holds a line in its place); back in it after. */
|
|
6522
|
+
if (on) document.body.append(v.root);
|
|
6523
|
+
else if (v.root.parentElement === document.body) { v.root.remove(); void repaintAsset(); }
|
|
6524
|
+
if (on) {
|
|
6525
|
+
v.fullStep = nav.over('console-full', () => consoleFull(v, false));
|
|
6526
|
+
void consoleChat(v);
|
|
6527
|
+
} else {
|
|
6528
|
+
if (v.fullStep) { const step = v.fullStep; v.fullStep = null; nav.drop(step); }
|
|
6529
|
+
v.chat?.destroy(); v.chat = null; v.chatOf = '';
|
|
6530
|
+
}
|
|
6531
|
+
requestAnimationFrame(() => { v.fit(); v.term.focus(); });
|
|
6532
|
+
}
|
|
6533
|
+
/* The conversations that hold the machine; the one whose chat is shown: picked, else the one on the console now,
|
|
6534
|
+
else the conversation this panel is seen from, else the first. */
|
|
6535
|
+
function consoleHolders(v) {
|
|
6536
|
+
return Object.keys(v.target.grants ?? {}).filter((id) => id.startsWith('conversation:')).map((id) => id.slice('conversation:'.length)).filter((n) => conversations.some((c) => c.name === n));
|
|
6537
|
+
}
|
|
6538
|
+
function consoleChatOf(v) {
|
|
6539
|
+
const holders = consoleHolders(v);
|
|
6540
|
+
if (v.chatPick && holders.includes(v.chatPick)) return v.chatPick;
|
|
6541
|
+
const on = (v.state?.agents ?? []).map((a) => String(a.id).replace(/^conversation:/, '')).find((n) => holders.includes(n));
|
|
6542
|
+
return on ?? (holders.includes(v.from) ? v.from : holders[0] ?? '');
|
|
6543
|
+
}
|
|
6544
|
+
async function consoleChat(v) {
|
|
6545
|
+
const holders = consoleHolders(v);
|
|
6546
|
+
const name = consoleChatOf(v);
|
|
6547
|
+
const label = (n) => conversations.find((c) => c.name === n)?.title || n;
|
|
6548
|
+
if (holders.length > 1) {
|
|
6549
|
+
const pick = el('select', 'sc-chat-pick'); pick.setAttribute('aria-label', uiSaid('set-sc-chat-of', 'Chat of'));
|
|
6550
|
+
for (const n of holders) { const o = el('option', '', label(n)); o.value = n; o.selected = n === name; pick.append(o); }
|
|
6551
|
+
pick.addEventListener('change', () => { v.chatPick = pick.value; void consoleChat(v); });
|
|
6552
|
+
v.chatHead.replaceChildren(el('b', '', uiSaid('set-sc-chat-of', 'Chat of')), pick);
|
|
6553
|
+
} else v.chatHead.replaceChildren(el('b', '', name ? label(name) : uiSaid('set-sc-chat', 'Chat')));
|
|
6554
|
+
if (!name) { v.chat?.destroy(); v.chat = null; v.chatOf = ''; v.chatBox.replaceChildren(el('p', 'hint', uiSaid('set-sc-no-holder', 'No conversation has this machine.'))); return; }
|
|
6555
|
+
if (v.chat && v.chatOf === name) return;
|
|
6556
|
+
v.chat?.destroy(); v.chat = null; v.chatOf = name;
|
|
6557
|
+
v.chatBox.replaceChildren();
|
|
6558
|
+
if (!conversations.find((c) => c.name === name)?.talk) { v.chatBox.append(el('p', 'hint', uiSaid('set-sc-chat-off', 'The chat of this conversation is off.'))); return; }
|
|
6559
|
+
const [{ mount }, words] = await Promise.all([parleyUi(), readWords()]);
|
|
6560
|
+
if (!v.full || v.chatOf !== name) return;
|
|
6561
|
+
v.chatBox.dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
6562
|
+
/* Parley's own chat view, as in the conversation: its thread read and written the same way. */
|
|
6563
|
+
v.chat = mount(v.chatBox, {
|
|
6564
|
+
words, view: chatView, window: windowFor(chatWindow),
|
|
6565
|
+
load: (asked = {}) => fetch(talkPath(name, '', asked)).then((r) => r.json()).then(machineLines),
|
|
6566
|
+
search: (q) => fetch(talkPath(name, '/search', { q })).then((r) => (r.ok ? r.json() : { matches: [], count: 0 })),
|
|
6567
|
+
send: (text, answers, files) => post(talkPath(name), { text, answers, quick: true, ...(files ? { files: files.map((f) => (f.note ? { path: f.path, note: f.note } : f.path)) } : {}) }),
|
|
6568
|
+
schemes: { mail: { icon: 'mail', open: (ref, label2) => { void openMailRef(ref, { label: label2, of: name }); } } },
|
|
6569
|
+
});
|
|
6570
|
+
}
|
|
6571
|
+
/* A console no longer shown for a while lets its shell go (the person's side): opened again when shown. */
|
|
6572
|
+
setInterval(() => {
|
|
6573
|
+
for (const v of consoleViews.values()) {
|
|
6574
|
+
if (v.root.isConnected) { v.away = 0; continue; }
|
|
6575
|
+
v.away += 1;
|
|
6576
|
+
if (v.away >= 3 && v.socket) { const ws = v.socket; v.socket = null; v.phase = 'closed'; try { ws.close(); } catch { /* gone */ } }
|
|
6577
|
+
}
|
|
6578
|
+
}, 10_000);
|
|
6579
|
+
/* The parts: the console (kept), then what the AI proposes and has typed, then the journal (drawn each paint). */
|
|
6580
|
+
function consoleParts(target, tether, from) {
|
|
6581
|
+
const v = consoleView(target);
|
|
6582
|
+
v.from = from || '';
|
|
6583
|
+
v.waiting = (Array.isArray(tether.approvals) ? tether.approvals : []).filter((q) => (q.target?.id ?? q.target) === target.id && String(q.verb ?? '').startsWith('terminal.'));
|
|
6584
|
+
const hadFocus = v.focused;
|
|
6585
|
+
let tries = 0;
|
|
6586
|
+
queueMicrotask(function place() {
|
|
6587
|
+
/* Put in the panel at the end of its paint; a paint overtaken by another never puts it: given up after a while. */
|
|
6588
|
+
if (!v.root.isConnected) { if (++tries < 120) requestAnimationFrame(place); return; }
|
|
6589
|
+
if (!v.opened) { v.term.open(v.screen); v.opened = true; }
|
|
6590
|
+
v.fit();
|
|
6591
|
+
if (!v.socket) consoleConnect(v);
|
|
6592
|
+
if (hadFocus) v.term.focus();
|
|
6593
|
+
});
|
|
6594
|
+
consolePaint(v);
|
|
6595
|
+
const ai = el('div', 'sc-ai'); ai.setAttribute('aria-live', 'polite');
|
|
6596
|
+
for (const q of v.waiting) ai.append(consoleAsk(q));
|
|
6597
|
+
const typed = el('div', 'sc-typed');
|
|
6598
|
+
ai.append(typed);
|
|
6599
|
+
const journal = el('div', 'sc-journal');
|
|
6600
|
+
journal.append(el('p', 'hint', uiSaid('set-sc-j-empty', 'Each AI input is kept here.')));
|
|
6601
|
+
void post(`${API}/tether/console-journal`, { target: target.id }).then((r) => {
|
|
6602
|
+
const lines = Array.isArray(r?.lines) ? r.lines : [];
|
|
6603
|
+
const inputs = lines.filter((l) => l.verb && l.ok === true).slice(0, 3);
|
|
6604
|
+
if (inputs.length) {
|
|
6605
|
+
typed.replaceChildren(el('h4', '', uiSaid('set-sc-typed', 'Its last inputs')));
|
|
6606
|
+
for (const l of inputs) { const row = el('div', 'sc-typed-row'); row.append(el('small', '', hhmm(l.at)), el('code', '', l.detail)); typed.append(row); }
|
|
6607
|
+
} else if (!v.waiting.length) typed.replaceChildren(el('p', 'hint', uiSaid('set-sc-ai-none', 'Nothing proposed. It follows the console.')));
|
|
6608
|
+
if (!lines.length) return;
|
|
6609
|
+
journal.replaceChildren(...lines.map((l) => {
|
|
6610
|
+
const row = el('div', 'sc-j-row');
|
|
6611
|
+
row.append(el('small', 'sc-j-at', hhmm(l.at)));
|
|
6612
|
+
if (l.op === 'console') {
|
|
6613
|
+
const [k, t] = SC_EVENTS[l.detail] ?? ['', l.detail];
|
|
6614
|
+
row.append(el('b', '', l.by ? uiSaid('set-sc-you', 'You') : uiSaid('set-sc-console', 'Console')), el('span', '', k ? uiSaid(k, t) : t));
|
|
6615
|
+
} else {
|
|
6616
|
+
row.append(el('b', '', l.agent ?? uiSaid('set-sc-ai-av', 'AI')), el('code', '', l.detail));
|
|
6617
|
+
const mark = l.decision === 'no' ? uiSaid('set-sc-j-refused', 'refused') : l.decision === 'stopped' || l.decision === 'timeout' || l.decision === 'withdrawn' ? uiSaid('set-sc-j-dropped', 'not sent')
|
|
6618
|
+
: l.ok === false ? uiSaid('set-sc-j-failed', 'not done') : l.edited ? uiSaid('set-sc-j-edited', 'edited by you') : '';
|
|
6619
|
+
if (mark) row.append(el('span', 'sc-j-mark', mark));
|
|
6620
|
+
if (l.risk) row.append(el('span', 'sc-risk', uiSaid('set-sc-destructive', 'Destructive')));
|
|
6621
|
+
}
|
|
6622
|
+
return row;
|
|
6623
|
+
}));
|
|
6624
|
+
}).catch(() => {});
|
|
6625
|
+
return [
|
|
6626
|
+
{ title: uiSaid('set-sc-title', 'Console'), body: [v.full ? el('p', 'hint', uiSaid('set-sc-in-full', 'The console is in full screen.')) : v.root], cls: 'as-console-part' },
|
|
6627
|
+
{ title: uiSaid('set-sc-ai-title', 'Assistant'), body: [ai], cls: 'as-console-ai' },
|
|
6628
|
+
{ title: uiSaid('set-sc-journal', 'Journal'), body: [journal], cls: 'as-console-journal' },
|
|
6629
|
+
];
|
|
6630
|
+
}
|
|
6631
|
+
/* A PROPOSAL: why, the line whole, Send / Edit / Refuse -- the same decision as any waiting call (decideTether);
|
|
6632
|
+
a destructive one marked, said in plain words, and sent in two steps. */
|
|
6633
|
+
function consoleAsk(q) {
|
|
6634
|
+
const risk = q.destructive ?? q.card?.destructive ?? '';
|
|
6635
|
+
const card = el('div', `sc-ask${risk ? ' risky' : ''}`); card.dataset.request = q.id;
|
|
6636
|
+
const head = el('div', 'sc-ask-head');
|
|
6637
|
+
head.append(el('span', 'sc-ai-tag', uiSaid('set-sc-ai-av', 'AI')), el('b', '', uiSaid('set-sc-to-approve', 'To approve')), el('small', 'hint', q.agent?.name ?? ''), el('span', 'sc-space'));
|
|
6638
|
+
if (risk) head.append(el('span', 'sc-risk', uiSaid('set-sc-destructive', 'Destructive')));
|
|
6639
|
+
card.append(head);
|
|
6640
|
+
if (q.why) card.append(el('p', 'sc-why', q.why));
|
|
6641
|
+
const key = (Array.isArray(q.editable) && q.editable[0]) || (q.verb === 'terminal.run' ? 'command' : 'text');
|
|
6642
|
+
const line = String(q.card?.[key] ?? q.detail ?? '');
|
|
6643
|
+
card.append(el('code', 'sc-cmd', line));
|
|
6644
|
+
if (q.verb === 'terminal.run') card.append(el('p', 'hint', uiSaid('set-sc-run-apart', 'Run apart, shown in the console.')));
|
|
6645
|
+
if (risk) { const [k, t] = SC_RISK[risk] ?? SC_RISK.other; card.append(el('p', 'sc-risk-say', uiSaid(k, t))); }
|
|
6646
|
+
const send = scButton(risk ? 'danger' : 'primary', risk ? uiSaid('set-sc-send-anyway', 'Send anyway') : uiSaid('set-sc-send', 'Send'));
|
|
6647
|
+
const edit = scButton('', uiSaid('set-sc-edit', 'Edit'));
|
|
6648
|
+
const refuse = scButton('quiet', uiSaid('set-sc-refuse', 'Refuse'));
|
|
6649
|
+
const acts = el('div', 'sc-ask-acts'); acts.append(send, edit, refuse);
|
|
6650
|
+
let armed = 0;
|
|
6651
|
+
send.addEventListener('click', () => {
|
|
6652
|
+
if (risk && Date.now() - armed > 5000) { armed = Date.now(); send.textContent = uiSaid('set-sc-sure', 'Sure? Send'); return; }
|
|
6653
|
+
send.disabled = true; void decideTether(q.id, 'yes', repaintAsset);
|
|
6654
|
+
});
|
|
6655
|
+
refuse.addEventListener('click', () => { refuse.disabled = true; void decideTether(q.id, 'no', repaintAsset); });
|
|
6656
|
+
card.append(acts);
|
|
6657
|
+
if (Array.isArray(q.editable) && q.editable.length) {
|
|
6658
|
+
const form = el('div', 'sc-edit'); form.hidden = true;
|
|
6659
|
+
const area = el('textarea'); area.rows = 2; area.value = line; area.spellcheck = false; area.setAttribute('aria-label', uiSaid('set-sc-edit-line', 'The line to send'));
|
|
6660
|
+
const go = scButton('primary', uiSaid('set-sc-send-edited', 'Send as edited'));
|
|
6661
|
+
go.addEventListener('click', () => { if (!area.value.trim()) return; go.disabled = true; void decideTether(q.id, 'yes', repaintAsset, { [key]: area.value }); });
|
|
6662
|
+
form.append(area, go);
|
|
6663
|
+
edit.addEventListener('click', () => { form.hidden = !form.hidden; send.hidden = !form.hidden; if (!form.hidden) area.focus(); });
|
|
6664
|
+
card.append(form);
|
|
6665
|
+
} else edit.hidden = true;
|
|
6666
|
+
return card;
|
|
6667
|
+
}
|
|
6366
6668
|
function agendaPart(target) {
|
|
6367
6669
|
const holder = el('div', 'as-agenda');
|
|
6368
6670
|
const move = (days) => {
|
package/web/style.css
CHANGED
|
@@ -3338,3 +3338,76 @@ span.tile-spark { display: block; height: 22px; }
|
|
|
3338
3338
|
.desk-pick-row > span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3339
3339
|
.desk-pick-row small { margin-left: auto; color: var(--ink2); }
|
|
3340
3340
|
.desk-plus { width: 30px; text-align: center; color: var(--brass-ink); font-size: 1.25rem; }
|
|
3341
|
+
|
|
3342
|
+
/* A MACHINE'S SHARED CONSOLE (16-11, app.js consoleParts): big -- most of the panel's height --, the same terminal as a
|
|
3343
|
+
conversation's; who has it above, the state in words under it, its keys bar on a touch screen, its tools; under it the
|
|
3344
|
+
AI's proposals, its inputs, the journal. Full screen: the console large, the conversation's chat beside it (under it on
|
|
3345
|
+
a phone). Colours never alone: each state is said in words too. */
|
|
3346
|
+
.as-console-part .sc { display: flex; flex-direction: column; }
|
|
3347
|
+
.sc-main { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0f141a; transition: box-shadow .2s, border-color .2s; }
|
|
3348
|
+
.sc.ai-typing .sc-main { border-color: var(--wait); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wait) 35%, transparent); }
|
|
3349
|
+
.sc.hidden-input .sc-main { border-color: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 30%, transparent); }
|
|
3350
|
+
.sc-presence { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 7px 10px; background: var(--bar); border-bottom: 1px solid var(--line); }
|
|
3351
|
+
.sc-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .8125rem; padding: 2px 10px 2px 3px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
|
|
3352
|
+
.sc-chip small { color: var(--ink2); }
|
|
3353
|
+
.sc-chip .sc-av { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .6875rem; font-weight: 700; }
|
|
3354
|
+
.sc-chip.me .sc-av { background: var(--brass); color: var(--on-brass); }
|
|
3355
|
+
.sc-chip.ai .sc-av { background: var(--wait); color: #fff; }
|
|
3356
|
+
.sc-chip.me.active { border-color: var(--brass); }
|
|
3357
|
+
.sc-chip.ai.active { border-color: var(--wait); box-shadow: 0 0 0 2px color-mix(in srgb, var(--wait) 25%, transparent); }
|
|
3358
|
+
.sc-space { flex: 1; }
|
|
3359
|
+
.sc-live { font-size: .75rem; color: var(--ink2); white-space: nowrap; }
|
|
3360
|
+
.sc-live::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--warn); }
|
|
3361
|
+
.sc-live.on { color: var(--ok); }
|
|
3362
|
+
.sc-live.on::before { background: var(--ok); }
|
|
3363
|
+
.sc-screen { height: max(340px, calc(100dvh - 330px)); padding: 6px 8px; background: #0f141a; min-width: 0; }
|
|
3364
|
+
.sc-screen .xterm { height: 100%; }
|
|
3365
|
+
.sc-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 7px 10px; font-size: .8125rem; background: var(--bar); color: var(--ink); border-top: 1px solid var(--line); }
|
|
3366
|
+
.sc-state[data-tone="ai"] { background: color-mix(in srgb, var(--wait) 16%, var(--panel)); border-top-color: var(--wait); }
|
|
3367
|
+
.sc-state[data-tone="secret"] { background: color-mix(in srgb, var(--ok) 14%, var(--panel)); border-top-color: var(--ok); }
|
|
3368
|
+
.sc-state[data-tone="pause"] { background: color-mix(in srgb, var(--warn) 14%, var(--panel)); border-top-color: var(--warn); }
|
|
3369
|
+
.sc-state[data-tone="bad"] { color: var(--danger); }
|
|
3370
|
+
.sc-keys { display: none; gap: 4px; padding: 5px; background: var(--bar); border-top: 1px solid var(--line); overflow-x: auto; }
|
|
3371
|
+
.sc-keys button { min-height: 38px; min-width: 44px; padding: 2px 8px; font: 600 .8125rem var(--mono, ui-monospace, Menlo, Consolas, monospace); flex: 0 0 auto; }
|
|
3372
|
+
.sc-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 7px 10px; background: var(--panel); border-top: 1px solid var(--line); }
|
|
3373
|
+
.sc-tools button[aria-pressed="true"] { border-color: var(--brass); color: var(--brass-ink); background: color-mix(in srgb, var(--brass) 12%, transparent); }
|
|
3374
|
+
.sc-tools .sc-take { font-size: .875rem; }
|
|
3375
|
+
/* Under the console: what the AI proposes, what it typed, the journal. */
|
|
3376
|
+
.sc-ai { display: flex; flex-direction: column; gap: 10px; }
|
|
3377
|
+
.sc-ask { border: 1px solid var(--wait); border-radius: 10px; padding: 10px 12px; background: var(--panel); box-shadow: 0 0 0 2px color-mix(in srgb, var(--wait) 20%, transparent); display: flex; flex-direction: column; gap: 6px; }
|
|
3378
|
+
.sc-ask.risky { border-color: var(--danger); box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 22%, transparent); }
|
|
3379
|
+
.sc-ask-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8125rem; }
|
|
3380
|
+
.sc-ai-tag { font-size: .6875rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--wait); color: var(--wait); }
|
|
3381
|
+
.sc-risk { font-size: .6875rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--danger); color: var(--danger); white-space: nowrap; }
|
|
3382
|
+
.sc-why { margin: 0; font-size: .875rem; }
|
|
3383
|
+
.sc-cmd { display: block; font: .8125rem/1.45 ui-monospace, Menlo, Consolas, monospace; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; white-space: pre-wrap; word-break: break-all; }
|
|
3384
|
+
.sc-risk-say { margin: 0; font-size: .8125rem; color: var(--danger); }
|
|
3385
|
+
.sc-ask-acts { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
3386
|
+
.sc-edit { display: flex; flex-direction: column; gap: 6px; }
|
|
3387
|
+
.sc-edit textarea { font: .8125rem ui-monospace, Menlo, Consolas, monospace; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; resize: vertical; }
|
|
3388
|
+
.sc-typed h4 { margin: 0 0 4px; font-size: .75rem; color: var(--ink2); letter-spacing: .05em; text-transform: uppercase; }
|
|
3389
|
+
.sc-typed-row, .sc-j-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: .8125rem; padding: 2px 0; }
|
|
3390
|
+
.sc-typed-row small, .sc-j-at { color: var(--ink2); font-variant-numeric: tabular-nums; }
|
|
3391
|
+
.sc-typed-row code, .sc-j-row code { font: .8125rem ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }
|
|
3392
|
+
.sc-j-mark { font-size: .75rem; color: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
|
|
3393
|
+
.sc-journal { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; }
|
|
3394
|
+
/* Full screen: over the page, the console large, the chat beside it. */
|
|
3395
|
+
.sc.sc-full { position: fixed; inset: 0; z-index: 60; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 30%); gap: 10px; padding: 10px; background: var(--bg); }
|
|
3396
|
+
.sc.sc-full .sc-main { min-height: 0; }
|
|
3397
|
+
.sc.sc-full .sc-screen { height: auto; flex: 1; min-height: 0; }
|
|
3398
|
+
.sc-chat { display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); overflow: hidden; }
|
|
3399
|
+
.sc-chat-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--bar); font-size: .875rem; }
|
|
3400
|
+
.sc-chat-pick { flex: 1; min-width: 0; font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
|
|
3401
|
+
.sc-chat-thread { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
|
|
3402
|
+
.sc-chat-thread > .hint { padding: 12px; }
|
|
3403
|
+
:root[data-sc-full] body { overflow: hidden; }
|
|
3404
|
+
@media (max-width: 760px), (pointer: coarse) {
|
|
3405
|
+
.sc-keys { display: flex; }
|
|
3406
|
+
}
|
|
3407
|
+
@media (max-width: 760px) {
|
|
3408
|
+
.sc-screen { height: max(280px, calc(100dvh - 300px)); padding: 4px; }
|
|
3409
|
+
.sc-tools .sc-ctrlc { display: none; }
|
|
3410
|
+
.sc-tools .sc-take { flex: 1 1 100%; min-height: 42px; }
|
|
3411
|
+
.sc.sc-full { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 58fr) minmax(0, 42fr); padding: 6px; gap: 6px; }
|
|
3412
|
+
}
|
|
3413
|
+
@media (prefers-reduced-motion: reduce) { .sc-main { transition: none; } }
|