clavarium 0.2.504-next.1 → 0.2.506-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/launch/screen-watch.mjs +3 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/mailbox.mjs +8 -0
- package/server/main.mjs +3 -1
- package/server/settingswords.mjs +1 -0
- package/server/signin.mjs +25 -8
- package/server/signinhelp.mjs +14 -0
- package/web/app.js +12 -3
- package/web/index.html +1 -0
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { spawnSync } from 'node:child_process';
|
|
33
33
|
import { randomUUID } from 'node:crypto';
|
|
34
|
-
import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
34
|
+
import { existsSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
35
35
|
import { dirname, join } from 'node:path';
|
|
36
36
|
import { fileURLToPath } from 'node:url';
|
|
37
37
|
|
|
@@ -138,6 +138,8 @@ if (main) {
|
|
|
138
138
|
if (CODE.test(code)) {
|
|
139
139
|
spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, '-l', '--', code], { timeout: 5000 });
|
|
140
140
|
spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, 'Enter'], { timeout: 5000 });
|
|
141
|
+
/* Typed: the ask is over, so the next message that looks like a code is a secret again (#394). */
|
|
142
|
+
try { rmSync(`${chat}/signin-ask.json`, { force: true }); } catch { /* left: it runs out on the server's side */ }
|
|
141
143
|
awaiting = null; return;
|
|
142
144
|
}
|
|
143
145
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.506-next.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.506-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/mailbox.mjs
CHANGED
|
@@ -143,6 +143,14 @@ export class Mailboxes {
|
|
|
143
143
|
return { host: m.host, port: m.port ?? 993, user: m.user, password: this.#vault.open(m.sealed) };
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
/* WHAT A SIGN-IN MAILBOX READS when it is one of these (20-11, #395): server side only, never to the page;
|
|
147
|
+
a classic one or one signed in with Google or Microsoft alike. */
|
|
148
|
+
readSettings(name) {
|
|
149
|
+
const m = this.#store.get(name);
|
|
150
|
+
if (!m) throw new Refusal(404, 'No such mailbox.');
|
|
151
|
+
return { host: m.host, port: m.port ?? 993, user: m.user, ...(m.provider ? { provider: m.provider } : {}), password: this.#vault.open(m.sealed) };
|
|
152
|
+
}
|
|
153
|
+
|
|
146
154
|
/* Adds a mailbox after proving it can be read, as a folder of that name. */
|
|
147
155
|
async add(body) {
|
|
148
156
|
const name = String(body?.name ?? '');
|
package/server/main.mjs
CHANGED
|
@@ -425,7 +425,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
425
425
|
secrets.expired = (name, users) => { events.add({ kind: 'asset', text: `Secret ${name} expired: no longer given${users.length ? ` to ${users.join(', ')}` : ''}` }); };
|
|
426
426
|
secrets.check();
|
|
427
427
|
const expiryTimer = setInterval(() => secrets.check(), 10 * 60_000); expiryTimer.unref();
|
|
428
|
-
const signin = new SignInMailboxes({ store: new Store(`${dataDir}/signin.json`), vault, rules: (name) => all.signinRules(name) });
|
|
428
|
+
const signin = new SignInMailboxes({ store: new Store(`${dataDir}/signin.json`), vault, rules: (name) => all.signinRules(name), mailboxes: () => { try { return mailboxes; } catch { return null; } } });
|
|
429
429
|
/* Each opening: the runner and the attached secrets are put in the VM,
|
|
430
430
|
and the tool is started through the runner. */
|
|
431
431
|
const network = new Network({ host: asHost, offline: () => all.offline() });
|
|
@@ -592,6 +592,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
592
592
|
the chat shows as stars; the value reaches the machine as
|
|
593
593
|
/run/secrets/<name>, and is swept after a few minutes. */
|
|
594
594
|
screen: async (conversation, text) => {
|
|
595
|
+
/* A sign-in code its tool waits for (#394): left whole, screen-watch types it in. */
|
|
596
|
+
if (signinHelp?.awaitsCode(conversation, text)) return text;
|
|
595
597
|
const hits = scan(text);
|
|
596
598
|
if (!hits.length) return text;
|
|
597
599
|
let out = ''; let last = 0; let any = false;
|
package/server/settingswords.mjs
CHANGED
|
@@ -197,6 +197,7 @@ export const SETTINGS_WORDS_FR = {
|
|
|
197
197
|
'set-carry-replace': 'Son travail a des fichiers. Tout remplacer ?', 'set-carry-replace-go': 'Remplacer son travail',
|
|
198
198
|
'set-carry-tolink': 'À relier à la main :', 'set-carry-import': 'Importer…', 'set-carry-reminders': 'Importer aussi ses rappels et réveils', 'set-carry-go': 'Importer',
|
|
199
199
|
'set-carry-ask': '« {file} » dans « {name} » ? Mémoire remplacée.', 'set-carry-done': 'Importé depuis « {from} ».',
|
|
200
|
+
'signin-typed': 'Une autre, saisie ici',
|
|
200
201
|
'set-mcp-drop': 'Collez ici la configuration du service', 'set-mcp-drop-hint': 'le bloc { "mcpServers": … } de sa page d\'aide',
|
|
201
202
|
'set-mcp-hand': 'Remplir à la main', 'set-mcp-add-n': 'Ajouter les {n}', 'set-mcp-nokey': 'aucune',
|
|
202
203
|
'set-mcp-notjson': 'Pas du JSON : collez tout le bloc.',
|
package/server/signin.mjs
CHANGED
|
@@ -181,23 +181,40 @@ export async function recentSignIns(settings, rules, { connect = tlsConnect, now
|
|
|
181
181
|
const CACHE_MS = 5_000;
|
|
182
182
|
|
|
183
183
|
export class SignInMailboxes {
|
|
184
|
-
#store; #vault; #rules; #cache = new Map(); #reader;
|
|
184
|
+
#store; #vault; #rules; #cache = new Map(); #reader; #mailboxes;
|
|
185
185
|
|
|
186
|
-
/* `rules(conversation)` gives the tool's sign-in rules, or undefined.
|
|
187
|
-
|
|
186
|
+
/* `rules(conversation)` gives the tool's sign-in rules, or undefined. `mailboxes()`: the mailboxes of Assets
|
|
187
|
+
(mailbox.mjs), one of which may be chosen instead of a mailbox typed in here (20-11, #395). */
|
|
188
|
+
constructor({ store, vault, rules, reader = recentSignIns, mailboxes = () => null }) { this.#store = store; this.#vault = vault; this.#rules = rules; this.#reader = reader; this.#mailboxes = mailboxes; }
|
|
188
189
|
|
|
189
|
-
/*
|
|
190
|
+
/* Where it reads, whichever way it was set: an asset's own settings, or its own. */
|
|
191
|
+
#where(s) {
|
|
192
|
+
if (s?.mailbox) { const boxes = this.#mailboxes(); if (!boxes) throw new Refusal(404, 'No such mailbox.'); return boxes.readSettings(s.mailbox); }
|
|
193
|
+
return { host: s.host, port: s.port, user: s.user, password: this.#vault.open(s.sealed) };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/* What the page may know: that a mailbox is set, and where (an asset by its name). Never the password. */
|
|
190
197
|
settings(conversation) {
|
|
191
198
|
const s = this.#store.get(conversation);
|
|
192
|
-
|
|
199
|
+
let host = s?.host ?? null; let port = s?.port ?? null; let user = s?.user ?? null;
|
|
200
|
+
if (s?.mailbox) { const m = (this.#mailboxes()?.list() ?? []).find((x) => x.name === s.mailbox); host = m?.host ?? null; port = m?.port ?? null; user = m?.user ?? null; }
|
|
201
|
+
const offered = (this.#mailboxes()?.list() ?? []).map((m) => ({ name: m.name, user: m.user }));
|
|
202
|
+
return { available: this.#rules(conversation) !== undefined, configured: s !== undefined, mailbox: s?.mailbox ?? null, host, port, user, mailboxes: offered };
|
|
193
203
|
}
|
|
194
204
|
|
|
195
|
-
/* Saves a mailbox after proving it can be read; an empty host
|
|
205
|
+
/* Saves a mailbox after proving it can be read: one of Assets by its name, or one typed in; an empty host
|
|
206
|
+
(and no mailbox) removes it. */
|
|
196
207
|
async set(conversation, body) {
|
|
197
208
|
this.#cache.delete(conversation);
|
|
198
|
-
|
|
209
|
+
const chosen = String(body?.mailbox ?? '').trim();
|
|
210
|
+
if (!chosen && String(body?.host ?? '').trim() === '') { this.#store.remove(conversation); return this.settings(conversation); }
|
|
199
211
|
const rules = this.#rules(conversation);
|
|
200
212
|
if (!rules) throw new Refusal(400, 'The tool of this conversation has no sign-in by mail.');
|
|
213
|
+
if (chosen) {
|
|
214
|
+
await this.#reader(this.#where({ mailbox: chosen }), rules);
|
|
215
|
+
this.#store.put({ name: conversation, mailbox: chosen });
|
|
216
|
+
return this.settings(conversation);
|
|
217
|
+
}
|
|
201
218
|
const settings = readSettings(body);
|
|
202
219
|
await this.#reader(settings, rules);
|
|
203
220
|
this.#store.put({ name: conversation, host: settings.host, port: settings.port, user: settings.user, sealed: this.#vault.seal(settings.password) });
|
|
@@ -212,7 +229,7 @@ export class SignInMailboxes {
|
|
|
212
229
|
if (!s || !rules) return [];
|
|
213
230
|
const cached = this.#cache.get(conversation);
|
|
214
231
|
if (cached && Date.now() - cached.at < CACHE_MS) return cached.items;
|
|
215
|
-
const items = await this.#reader(
|
|
232
|
+
const items = await this.#reader(this.#where(s), rules);
|
|
216
233
|
this.#cache.set(conversation, { at: Date.now(), items });
|
|
217
234
|
return items;
|
|
218
235
|
}
|
package/server/signinhelp.mjs
CHANGED
|
@@ -40,6 +40,8 @@ export const ROUTE = 'signin-route.json';
|
|
|
40
40
|
export const CHAT = '.parley';
|
|
41
41
|
export const DOCKET = '.docket';
|
|
42
42
|
export const WAIT_MS = 10 * 60_000;
|
|
43
|
+
/* How long after its tool asked a code pasted by the person is taken as that code (and not as a secret). */
|
|
44
|
+
export const CODE_WAIT_MS = 30 * 60_000;
|
|
43
45
|
export const TICK_MS = 3000;
|
|
44
46
|
export const NONE = 'none';
|
|
45
47
|
const ASK_BYTES = 16_384;
|
|
@@ -143,6 +145,18 @@ export class SigninHelp {
|
|
|
143
145
|
if (!this.#own(dir)) return;
|
|
144
146
|
try { writeFileSync(join(dir, `.${ROUTE}.new`), JSON.stringify(route)); renameSync(join(dir, `.${ROUTE}.new`), join(dir, ROUTE)); } catch { /* its chat folder cannot be written: screen-watch tells the person itself */ }
|
|
145
147
|
}
|
|
148
|
+
/* A CODE AWAITED FROM THE PERSON (20-11, #394): its tool asked to sign in, the link was told to the person (not
|
|
149
|
+
handed to a companion), a short while ago. Then a message that is nothing but a code is that code: typed into
|
|
150
|
+
the tool by screen-watch, never lifted out as a secret (19-11: « code#state » kept as two secrets, the tool
|
|
151
|
+
never got it). */
|
|
152
|
+
awaitsCode(name, text) {
|
|
153
|
+
if (!CODE.test(String(text ?? '').trim())) return false;
|
|
154
|
+
const ask = this.#readAsk(name); if (!ask) return false;
|
|
155
|
+
const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS || at > this.#now() + 60_000) return false;
|
|
156
|
+
if (ask.told === true) return true;
|
|
157
|
+
const route = this.#readRoute(name);
|
|
158
|
+
return route?.id === ask.id && route.route === 'person';
|
|
159
|
+
}
|
|
146
160
|
#readRoute(name) { try { return JSON.parse(readFileSync(join(this.#chat(name), ROUTE), 'utf8')); } catch { return null; } }
|
|
147
161
|
#line(name, line) { try { this.#event(name, line); } catch { /* its chat may be off */ } }
|
|
148
162
|
#tool(name) { const id = this.#conversations().find((c) => c.name === name)?.tool; return this.#tools().find((t) => t.id === id); }
|
package/web/app.js
CHANGED
|
@@ -12816,14 +12816,23 @@
|
|
|
12816
12816
|
async function paintSignIn() {
|
|
12817
12817
|
const j = await (await fetch(`${API}/conversations/${encodeURIComponent(current)}/signin`)).json();
|
|
12818
12818
|
$('signin-setup').hidden = !j.available;
|
|
12819
|
-
$('signin-state').textContent = j.configured ? `Watching ${j.user} on ${j.host}.${j.failure ? ` Not readable just now: ${j.failure}` : ''}` : 'No mailbox is set for this conversation.';
|
|
12819
|
+
$('signin-state').textContent = j.configured ? `Watching ${j.mailbox ? `« ${j.mailbox} » (${j.user ?? '?'})` : `${j.user} on ${j.host}`}.${j.failure ? ` Not readable just now: ${j.failure}` : ''}` : 'No mailbox is set for this conversation.';
|
|
12820
12820
|
$('signin-remove').hidden = !j.configured;
|
|
12821
|
-
|
|
12821
|
+
/* One of Assets' mailboxes, or one typed in (20-11, #395). */
|
|
12822
|
+
const box = $('signin-box'); const offered = j.mailboxes ?? [];
|
|
12823
|
+
box.replaceChildren(...offered.map((m) => { const o = document.createElement('option'); o.value = m.name; o.textContent = `${m.name} · ${m.user}`; return o; }));
|
|
12824
|
+
const typed = document.createElement('option'); typed.value = ''; typed.textContent = uiSaid('signin-typed', 'Another, typed in'); box.append(typed);
|
|
12825
|
+
box.value = j.mailbox ?? (j.configured ? '' : (offered[0]?.name ?? ''));
|
|
12826
|
+
$('signin-box-row').hidden = !offered.length;
|
|
12827
|
+
signinTyped();
|
|
12828
|
+
}
|
|
12829
|
+
const signinTyped = () => { const typed = !$('signin-box').value; for (const id of ['signin-host', 'signin-user', 'signin-password']) $(id).hidden = !typed; };
|
|
12830
|
+
$('signin-box').addEventListener('change', signinTyped);
|
|
12822
12831
|
$('signin-form').addEventListener('submit', async (event) => {
|
|
12823
12832
|
event.preventDefault();
|
|
12824
12833
|
$('panel-error').hidden = true;
|
|
12825
12834
|
$('signin-state').textContent = 'Reading the mailbox once, to check...';
|
|
12826
|
-
try { await post(`${API}/conversations/${encodeURIComponent(current)}/signin`, { host: $('signin-host').value, user: $('signin-user').value, password: $('signin-password').value }); $('signin-password').value = ''; }
|
|
12835
|
+
try { const box = $('signin-box').value; await post(`${API}/conversations/${encodeURIComponent(current)}/signin`, box ? { mailbox: box } : { host: $('signin-host').value, user: $('signin-user').value, password: $('signin-password').value }); $('signin-password').value = ''; }
|
|
12827
12836
|
catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
|
|
12828
12837
|
await paintSignIn(); void watchSignIn();
|
|
12829
12838
|
});
|
package/web/index.html
CHANGED
|
@@ -276,6 +276,7 @@
|
|
|
276
276
|
<p class="hint">Its sign-in links, beside the terminal</p><p class="hint tip" hidden>A mailbox for this tool's account, read only; its password never enters the machine.</p>
|
|
277
277
|
<p id="signin-state" class="hint"></p>
|
|
278
278
|
<form id="signin-form" autocomplete="off">
|
|
279
|
+
<div class="row" id="signin-box-row"><select id="signin-box" aria-label="Which mailbox"></select></div>
|
|
279
280
|
<div class="row"><input id="signin-host" placeholder="imap.example.com" aria-label="Mail server" spellcheck="false" autocapitalize="none">
|
|
280
281
|
<input id="signin-user" placeholder="user" aria-label="Mailbox user" spellcheck="false" autocapitalize="none">
|
|
281
282
|
<input id="signin-password" type="password" placeholder="password" aria-label="Mailbox password" autocomplete="new-password">
|