clavarium 0.2.84-beta.1 → 0.2.85-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/config/tools.json CHANGED
@@ -64,6 +64,7 @@
64
64
  {
65
65
  "id": "opencode",
66
66
  "instructions": ".config/opencode/AGENTS.md",
67
+ "logs": [".local/share/opencode/log"],
67
68
  "label": "OpenCode",
68
69
  "command": [
69
70
  "opencode"
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.84-beta.1",
3
+ "version": "0.2.85-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.84-beta.1",
9
+ "version": "0.2.85-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
- "clavarium-binder": "0.1.36-next.1",
14
+ "clavarium-binder": "0.1.38-next.1",
15
15
  "clavarium-docket": "0.1.1",
16
16
  "clavarium-parley": "0.17.20-next.1",
17
- "clavarium-tether": "0.1.0-next.31",
17
+ "clavarium-tether": "0.1.0-next.32",
18
18
  "mermaid": "11.17.2",
19
19
  "node-pty": "^1.1.0",
20
20
  "pdfjs-dist": "6.4.299",
@@ -716,9 +716,9 @@
716
716
  }
717
717
  },
718
718
  "node_modules/clavarium-binder": {
719
- "version": "0.1.36-next.1",
720
- "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.36-next.1.tgz",
721
- "integrity": "sha512-4YvWkq3az1sP2N7Ot5fsYJONsoqN8Rwi8snS2rUoV1sTtcd9vvwRghfC01myZcoGHq3chFep3Jb6q4mibDvvRQ==",
719
+ "version": "0.1.38-next.1",
720
+ "resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.38-next.1.tgz",
721
+ "integrity": "sha512-9nhZM/vb1hsXr60vJ354XNWVCojyB9RrrAtl9BWFtaIPO55Dde9D5fgxOylmqTprjmMVq8r6Za2YqvWe+W05ig==",
722
722
  "license": "MIT",
723
723
  "bin": {
724
724
  "binder": "bin/binder.mjs",
@@ -755,9 +755,9 @@
755
755
  }
756
756
  },
757
757
  "node_modules/clavarium-tether": {
758
- "version": "0.1.0-next.31",
759
- "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.31.tgz",
760
- "integrity": "sha512-ZhNJgkQAusiAFptGGp1f4XVvmunRSfoZC0vSDlfE1WcikvicwaXWamsCOyQFcQJTOg8mnw875IAVvEFqTWvX4w==",
758
+ "version": "0.1.0-next.32",
759
+ "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.32.tgz",
760
+ "integrity": "sha512-Lkw2EqT79rqDi1q8+nhV1Ll30maopyNvwwHZkXYKp7IPoAUOde9R+Gtf7tCO8X/ArqEoADM7gouWnW+w+h1cXA==",
761
761
  "license": "MIT",
762
762
  "bin": {
763
763
  "tether": "bin/cli.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.84-beta.1",
3
+ "version": "0.2.85-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.",
@@ -44,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@xterm/addon-fit": "^0.11.0",
46
46
  "@xterm/xterm": "^6.0.0",
47
- "clavarium-binder": "0.1.36-next.1",
47
+ "clavarium-binder": "0.1.38-next.1",
48
48
  "clavarium-docket": "0.1.1",
49
49
  "clavarium-parley": "0.17.20-next.1",
50
- "clavarium-tether": "0.1.0-next.31",
50
+ "clavarium-tether": "0.1.0-next.32",
51
51
  "mermaid": "11.17.2",
52
52
  "node-pty": "^1.1.0",
53
53
  "pdfjs-dist": "6.4.299",
@@ -16,6 +16,11 @@
16
16
  * own open-source desktop client, verified for all three: Google over IMAP +
17
17
  * CalDAV/CardDAV, Microsoft over Microsoft Graph (mail, calendar and contacts).
18
18
  *
19
+ * A CLASSIC ACCOUNT (OVH, Infomaniak, Nextcloud... any IMAP/SMTP + CalDAV/CardDAV host)
20
+ * has no token: it signs in with its password. The password is kept the same way, a
21
+ * host-only secret the keeper reveals to the connector alone; each kind is tried live
22
+ * before anything is kept, so a wrong server or password is said at once.
23
+ *
19
24
  * A CREATED TARGET IS GIVEN TO NO ONE. The person grants it per conversation, at
20
25
  * its own level, from the page (Assets > Access) -- like git: one mailbox, many
21
26
  * conversations, each its own rights.
@@ -45,6 +50,14 @@ const KIND = {
45
50
  /* What each provider's built-in (Thunderbird) client grants a refresh token for. */
46
51
  const SUPPORTED = { google: ['mail', 'calendar', 'contacts'], microsoft: ['mail', 'calendar', 'contacts'] };
47
52
 
53
+ /* Servers of common classic hosts, by the address's domain (what ISPDB lacks: the
54
+ calendar and contacts addresses). */
55
+ const CLASSIC = {
56
+ 'ovh.net': { imap: 'ssl0.ovh.net', smtp: 'ssl0.ovh.net' },
57
+ 'infomaniak.com': { imap: 'mail.infomaniak.com', smtp: 'mail.infomaniak.com', caldav: 'https://sync.infomaniak.com', carddav: 'https://sync.infomaniak.com' },
58
+ 'ik.me': { imap: 'mail.infomaniak.com', smtp: 'mail.infomaniak.com', caldav: 'https://sync.infomaniak.com', carddav: 'https://sync.infomaniak.com' },
59
+ 'fastmail.com': { imap: 'imap.fastmail.com', smtp: 'smtp.fastmail.com', caldav: 'https://caldav.fastmail.com', carddav: 'https://carddav.fastmail.com' },
60
+ };
48
61
  const emailOk = (s) => /^[^\s@]{1,64}@[^\s@]{1,190}\.[^\s@]{2,}$/.test(s);
49
62
  /* A deterministic, valid secret name for an account's token: a short slug of the
50
63
  address plus a hash of it, so reconnecting the same account reuses the name
@@ -62,10 +75,73 @@ export class Accounts {
62
75
 
63
76
  /* `secrets`: the vault (set host-only, by name). `targets`: { put(spec) } onto
64
77
  the Tether store. `fetch`: injected for tests. */
65
- constructor({ secrets, targets, fetch = globalThis.fetch }) {
78
+ #probe;
79
+ constructor({ secrets, targets, fetch = globalThis.fetch, probe = null }) {
66
80
  if (!secrets?.set) throw new Error('accounts needs the secret store');
67
81
  if (!targets?.put) throw new Error('accounts needs the Tether target store');
68
- this.#secrets = secrets; this.#targets = targets; this.#fetch = fetch;
82
+ this.#secrets = secrets; this.#targets = targets; this.#fetch = fetch; this.#probe = probe;
83
+ }
84
+
85
+ /* The servers of a classic address, as far as they can be known: a few common
86
+ hosts, else the public Thunderbird database of mail providers (ISPDB). What
87
+ is not known stays empty for the person to fill. */
88
+ async lookup({ user } = {}) {
89
+ const address = String(user ?? '').trim();
90
+ if (!emailOk(address)) throw new Refusal(400, 'The account needs its email address.');
91
+ const domain = address.split('@')[1].toLowerCase();
92
+ const known = Object.entries(CLASSIC).find(([d]) => domain === d || domain.endsWith(`.${d}`))?.[1];
93
+ const out = { imap: '', smtp: '', caldav: '', carddav: '', ...(known ?? {}) };
94
+ if (!out.imap || !out.smtp) {
95
+ try {
96
+ const r = await this.#fetch(`https://autoconfig.thunderbird.net/v1.1/${encodeURIComponent(domain)}`);
97
+ if (r.ok) {
98
+ const xml = await r.text();
99
+ const servers = (kind) => [...xml.matchAll(new RegExp(`<(incomingServer|outgoingServer) type="${kind}">([\\s\\S]*?)</\\1>`, 'g'))].map((m) => ({ host: /<hostname>([^<]+)</.exec(m[2])?.[1] ?? '', port: /<port>(\\d+)</.exec(m[2])?.[1] ?? '', socket: /<socketType>([^<]+)</.exec(m[2])?.[1] ?? '' }));
100
+ const imap = servers('imap').find((x) => x.socket === 'SSL') ?? null;
101
+ const smtp = servers('smtp').find((x) => x.socket === 'STARTTLS') ?? null;
102
+ if (!out.imap && imap?.host) out.imap = `${imap.host}${imap.port && imap.port !== '993' ? `:${imap.port}` : ''}`;
103
+ if (!out.smtp && smtp?.host) out.smtp = `${smtp.host}${smtp.port && smtp.port !== '587' ? `:${smtp.port}` : ''}`;
104
+ }
105
+ } catch { /* not known there: the person fills it */ }
106
+ }
107
+ return out;
108
+ }
109
+
110
+ /* Connect a classic account: its password kept host-only, a target per kind,
111
+ each tried live first (nothing is kept if one fails). */
112
+ async classic({ user, password, imap, smtp, caldav, carddav, kinds } = {}) {
113
+ const address = String(user ?? '').trim();
114
+ if (!emailOk(address)) throw new Refusal(400, 'The account needs its email address.');
115
+ const secret = String(password ?? '');
116
+ if (!secret) throw new Refusal(400, 'The account needs its password.');
117
+ const wanted = (Array.isArray(kinds) && kinds.length ? kinds : ['mail']).map(String).filter((k) => KIND[k]);
118
+ if (!wanted.length) throw new Refusal(400, 'Choose at least mail, calendar or contacts.');
119
+ const hostPort = (v, what, port) => {
120
+ const m = /^([a-z0-9.-]+\.[a-z]{2,})(?::(\d{1,5}))?$/i.exec(String(v ?? '').trim());
121
+ if (!m) throw new Refusal(400, `The ${what} server is a name like mail.example.com.`);
122
+ return { host: m[1].toLowerCase(), port: Number(m[2] ?? port) };
123
+ };
124
+ const davUrl = (v, what) => {
125
+ let u; try { u = new URL(/^https?:\/\//i.test(String(v ?? '').trim()) ? String(v).trim() : `https://${String(v ?? '').trim()}`); } catch { u = null; }
126
+ if (!u || u.protocol !== 'https:' || !u.hostname.includes('.')) throw new Refusal(400, `The ${what} address is an https address, like https://dav.example.com.`);
127
+ return u.href;
128
+ };
129
+ const name = secretName('classic', address);
130
+ const specs = [];
131
+ for (const k of wanted) {
132
+ const config = { user: address };
133
+ if (k === 'mail') { const i = hostPort(imap, 'mail (IMAP)', 993); const o = hostPort(smtp, 'sending (SMTP)', 587); Object.assign(config, { host: i.host, port: i.port, smtpHost: o.host, smtpPort: o.port }); }
134
+ if (k === 'calendar') config.caldav = davUrl(caldav, 'calendar (CalDAV)');
135
+ if (k === 'contacts') config.carddav = davUrl(carddav, 'contacts (CardDAV)');
136
+ specs.push({ id: targetId(k, 'classic', address), title: `${KIND[k].title} — ${address}`, kind: KIND[k].kind, connector: KIND[k].connector, config, secrets: { password: name } });
137
+ }
138
+ if (this.#probe) for (const t of specs) {
139
+ try { await this.#probe(t, secret); }
140
+ catch (e) { throw new Refusal(400, `${KIND[t.connector === 'mail' ? 'mail' : t.connector].title}: ${String(e?.message ?? e).replace(/^.*?: /, '')}`); }
141
+ }
142
+ this.#secrets.set({ name, value: secret, hostOnly: true });
143
+ const made = specs.map((t) => { const saved = this.#targets.put(t); return { id: saved?.id ?? t.id, title: saved?.title ?? t.title, kind: t.kind }; });
144
+ return { provider: 'classic', user: address, targets: made, authorized: wanted, denied: [] };
69
145
  }
70
146
 
71
147
  /* Which kinds may be connected, per provider, for the page to offer. */
package/server/api.mjs CHANGED
@@ -12,6 +12,7 @@
12
12
  * GET /api/conversations/<name>/health what was last seen of its machine
13
13
  * POST /api/conversations/<name>/health look now (never wakes a machine)
14
14
  * POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
15
+ * POST /api/conversations/<name>/exit-report why its tool ended: { now (read in its machine, if it runs), last (kept at its end) }
15
16
  * POST /api/conversations/<name>/archive
16
17
  * POST /api/conversations/<name>/ask-first {on}: its tool asks before acting (true), or acts without asking in its machine (false, the default), from its next start
17
18
  * POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
@@ -434,6 +435,8 @@ export async function handleApi(request, response, conversations, headers, resou
434
435
  kept host-only, a Tether target made): see accounts.mjs. */
435
436
  if (pathname === '/api/accounts/consent' && accounts) return send(200, accounts.consent(body)), true;
436
437
  if (pathname === '/api/accounts/connect' && accounts) { const made = await accounts.connect(body); return send(201, made), true; }
438
+ if (pathname === '/api/accounts/lookup' && accounts) return send(200, await accounts.lookup(body)), true;
439
+ if (pathname === '/api/accounts/classic' && accounts) { const made = await accounts.classic(body); return send(201, made), true; }
437
440
  if (pathname === '/api/accounts/verify' && accounts) { const r = await accounts.verify(body); return send(200, r), true; }
438
441
  /* Assets > Access: the owner sets a conversation's level and rules on a
439
442
  target, decides a call that waited, or removes a target. Each is an op the
@@ -617,6 +620,15 @@ export async function handleApi(request, response, conversations, headers, resou
617
620
  }
618
621
  const moved = /^\/api\/conversations\/([^/]+)\/work$/.exec(pathname);
619
622
  if (moved) return send(202, await conversations.moveWork(decodeURIComponent(moved[1]), body.to)), true;
623
+ /* Why its tool ended: read now in its machine when it runs, else the last kept at its end. */
624
+ const exitOf = /^\/api\/conversations\/([^/]+)\/exit-report$/.exec(pathname);
625
+ if (exitOf) {
626
+ const conversation = decodeURIComponent(exitOf[1]);
627
+ const c = conversations.list().find((x) => x.name === conversation);
628
+ if (!c) throw new Refusal(404, 'No such conversation.');
629
+ const now = await conversations.exitReport(conversation).catch(() => null);
630
+ return send(200, { now, last: c.lastExit ?? null }), true;
631
+ }
620
632
  /* "Seen": what its machine says now no longer calls its owner (health.mjs). */
621
633
  const seenOf = /^\/api\/conversations\/([^/]+)\/health\/seen$/.exec(pathname);
622
634
  if (seenOf && health) {
@@ -1036,6 +1036,11 @@ export class Conversations {
1036
1036
  const alive = await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'has-session', '-t', `=${SESSION}`]);
1037
1037
  /* true: the tool is still there, only the channel to it dropped. */
1038
1038
  if (alive.code === 0) return true;
1039
+ /* Before its machine stops (and its kernel's memory of the night with it): why the tool
1040
+ ended, kept on the conversation and said -- a person without access to the server
1041
+ sees it in Machine, and is told at once when it was cut for lack of memory. */
1042
+ const report = await this.exitReport(name).catch(() => null);
1043
+ if (report) { this.#store.patch(name, { lastExit: report }); try { this.onToolExit?.(name, report); } catch { /* telling is best effort */ } }
1039
1044
  this.#cancelStop(name);
1040
1045
  const timer = setTimeout(() => {
1041
1046
  this.#timers.delete(name);
@@ -1046,6 +1051,28 @@ export class Conversations {
1046
1051
  return false;
1047
1052
  }
1048
1053
 
1054
+ /* WHY ITS TOOL ENDED, read inside the machine while it still runs: the kernel's kills for
1055
+ lack of memory since it started (with the program's name), its memory, and the last
1056
+ lines of the tool's own log (`logs` in config/tools.json). Read as the machine's
1057
+ ordinary user; dmesg through sudo when it may. Nothing is changed. */
1058
+ async exitReport(name) {
1059
+ const c = this.#store.get(name);
1060
+ if (!c) throw new Refusal(404, 'No such conversation.');
1061
+ if (await this.#vms.state(name) !== 'Running') throw new Refusal(409, 'Its machine is not running.');
1062
+ const tool = this.#tools.find((t) => t.id === c.tool);
1063
+ const logs = Array.isArray(tool?.logs) ? tool.logs.filter((d) => /^[A-Za-z0-9._/-]+$/.test(d)) : [];
1064
+ const script = [
1065
+ '( sudo -n dmesg -T 2>/dev/null || dmesg -T 2>/dev/null ) | grep -E "Killed process|Out of memory|Memory cgroup out of memory" | tail -n 4 | sed "s/^/oom /"',
1066
+ 'awk \'/^MemTotal:/{print "memory", int($2/1024)}\' /proc/meminfo',
1067
+ 'for d in "$@"; do f=$(ls -t "$HOME/$d"/*.log 2>/dev/null | head -1); [ -n "$f" ] && { echo "logfile $f"; tail -n 25 "$f" | cut -c1-300 | sed "s/^/log /"; }; done; true',
1068
+ ].join('\n');
1069
+ const r = await this.#vms.exec(name, ['bash', '-c', script, 'report', ...logs], { timeoutMs: 20_000 });
1070
+ const lines = String(r.stdout ?? '').split('\n');
1071
+ const pick = (p) => lines.filter((l) => l.startsWith(`${p} `)).map((l) => l.slice(p.length + 1));
1072
+ const memoryMb = Number(pick('memory')[0]) || null;
1073
+ return { at: new Date().toISOString(), oom: pick('oom'), memoryMb, logFile: pick('logfile')[0] ?? null, log: pick('log') };
1074
+ }
1075
+
1049
1076
  /* ONE FILE OF THE MACHINE'S OWN DISK, read for the person who asked to
1050
1077
  see it (a path on their screen, clicked). Only under /work, only a
1051
1078
  plain path, only a regular file of a modest size; read as the
package/server/main.mjs CHANGED
@@ -411,7 +411,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
411
411
  /* Connecting a mailbox, calendar or address book by token: the consent happens
412
412
  in the owner's browser, the refresh token is kept host-only (never in a
413
413
  machine) and a Tether target is made for it: see accounts.mjs. */
414
- const accounts = new Accounts({ secrets, targets: { put: (spec) => tethers.store().putTarget(spec), all: () => tethers.store().targets() } });
414
+ const accounts = new Accounts({ secrets, targets: { put: (spec) => tethers.store().putTarget(spec), all: () => tethers.store().targets() }, probe: (target, password) => tethers.probe(target, password) });
415
415
  /* A calendar target made before it needed the account address (Google CalDAV
416
416
  puts it in the URL) carries none. The same account's mailbox or address book
417
417
  has it -- they share the one refresh token -- so fill it in from a sibling,
@@ -530,6 +530,15 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
530
530
  reclaim: (name) => { events.add({ kind: 'machine', text: `Machine of ${name}: memory reclaimed (it was asleep but still held RAM)`, conversation: name }); return vms.reclaim(name).then((r) => (r.stdout || '').trim()); },
531
531
  say: (name, text) => { try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ } } });
532
532
  all.room = (ask) => capacity.check(ask);
533
+ /* A tool that ended cut for lack of memory: said in the events, to the owner, and in its chat. */
534
+ all.onToolExit = (name, report) => {
535
+ if (!report?.oom?.length) return;
536
+ const size = report.memoryMb ? ` (${Math.round(report.memoryMb / 1024 * 10) / 10} GB)` : '';
537
+ const text = `Its tool was stopped: the machine ran out of memory${size}. Give it more in Settings → Machine → Memory, or start it fresh.`;
538
+ events.add({ kind: 'machine', text: `Machine of ${name}: its tool was stopped for lack of memory${size}`, conversation: name });
539
+ void alerts.tell({ title: `${name}: its tool ran out of memory`, body: text, url: `/?c=${encodeURIComponent(name)}&open=settings` });
540
+ try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ }
541
+ };
533
542
  const stopWatch = capacity.start();
534
543
  /* The curves of the resources (history.mjs): one look a minute, from what the server knows already. */
535
544
  const history = new History({ file: `${dataDir}/history.json` });
@@ -110,6 +110,15 @@ export class Tethers {
110
110
  /* The store behind it, for the Assets page to create/give/remove targets. */
111
111
  store() { return this.#keeper.store; }
112
112
 
113
+ /* A first read of a target not saved yet, its password given here: does the account
114
+ answer? Used when a classic account is connected, before anything is kept. */
115
+ async probe(target, password) {
116
+ const verb = { mail: 'mail.list', calendar: 'calendar.list', contacts: 'contacts.list' }[target.connector];
117
+ const conn = this.#keeper.connectors?.[target.connector];
118
+ if (!verb || !conn) throw new Error(`no ${target.connector} connector`);
119
+ await conn.run(verb, target, {}, { agent: 'person:owner', secret: async () => password });
120
+ }
121
+
113
122
  /* What each conversation was given: { name: count } -- the targets it may use. */
114
123
  given() {
115
124
  const out = {};
package/server/tools.mjs CHANGED
@@ -98,13 +98,15 @@ export function readTools(text) {
98
98
  machine's user (".claude/CLAUDE.md"): a marked block in it points
99
99
  the tool to its guide (see guide.mjs). A plain relative path. */
100
100
  if (t.instructions !== undefined && !INSTRUCTIONS.test(t.instructions)) throw new Error(`${t.id}: instructions is a relative path in the home, without ".."`);
101
+ /* Where the tool keeps its own log, read when it ends (why it stopped): folders relative to the home. */
102
+ if (t.logs !== undefined && (!Array.isArray(t.logs) || t.logs.some((d) => typeof d !== 'string' || !/^[A-Za-z0-9._/-]+$/.test(d) || d.startsWith('/') || d.split('/').includes('..')))) throw new Error(`${t.id}: logs is a list of folders relative to the home, without ".."`);
101
103
  /* Optional: ITS LAUNCHER, a script of config/launch shown at /tools/launch: run at each start,
102
104
  given the rights chosen (full, ask) then the command; it sets what the tool needs,
103
105
  then runs it. Clavarium knows nothing more of the tool. */
104
106
  if (t.launch !== undefined && !/^[a-z][a-z0-9-]{0,40}\.sh$/.test(t.launch)) throw new Error(`${t.id}: launch is the name of a script of config/launch, such as "${t.id}.sh"`);
105
107
  /* Repairs an existing machine is given once (see FIXES in conversations.mjs). */
106
108
  const fixups = t.install.includes('npm-writable') ? NPM_WRITABLE : [];
107
- return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), command: Object.freeze([...t.command]), ...(t.launch ? { launch: t.launch } : {}), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
109
+ return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), ...(t.logs ? { logs: Object.freeze([...t.logs]) } : {}), command: Object.freeze([...t.command]), ...(t.launch ? { launch: t.launch } : {}), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
108
110
  });
109
111
  }
110
112
 
package/web/app.js CHANGED
@@ -2222,6 +2222,36 @@
2222
2222
  try { await post(`${API}/conversations/${encodeURIComponent(current)}/health-react`, { on: $('react-on').checked, message: $('react-message').value, command: $('react-command').value }); $('react-said').textContent = 'Saved.'; }
2223
2223
  catch (error) { $('react-said').textContent = error.message; }
2224
2224
  });
2225
+ /* WHY ITS TOOL STOPPED, said plainly: cut for lack of memory (and what to do), else its log's
2226
+ last lines. `last` was kept when it ended; `now` is read in the machine when it runs. */
2227
+ function paintToolExit(r) {
2228
+ const body = $('tool-exit-body'); body.replaceChildren();
2229
+ const rep = r?.last ?? null; const now = r?.now ?? null;
2230
+ if (!rep && !now) { body.hidden = !r; if (r) body.append(el('p', 'hint', 'Nothing kept yet: its tool has not ended since this was added, and its machine is not running.')); return; }
2231
+ body.hidden = false;
2232
+ const show = (title, x) => {
2233
+ if (!x) return;
2234
+ const box = el('div', 'tool-exit-one');
2235
+ box.append(el('p', '', [title, x.at ? new Date(x.at).toLocaleString() : ''].filter(Boolean).join(' · ')));
2236
+ if (x.oom?.length) {
2237
+ box.append(el('p', 'error', `Stopped for lack of memory: the machine${x.memoryMb ? ` (${sizeWords(x.memoryMb)})` : ''} ran out. Give it more memory below, or start its tool fresh.`));
2238
+ const pre = el('pre', 'tool-exit-lines'); pre.textContent = x.oom.join('\n'); box.append(pre);
2239
+ } else box.append(el('p', 'hint', 'No program was stopped for lack of memory.'));
2240
+ if (x.log?.length) {
2241
+ const d = document.createElement('details'); const sm = document.createElement('summary'); sm.textContent = `Last lines of its own log${x.logFile ? ` (${x.logFile.split('/').pop()})` : ''}`;
2242
+ const pre = el('pre', 'tool-exit-lines'); pre.textContent = x.log.join('\n'); d.append(sm, pre); box.append(d);
2243
+ }
2244
+ body.append(box);
2245
+ };
2246
+ show('Now, in its machine', now);
2247
+ show('When its tool last ended', rep);
2248
+ }
2249
+ $('tool-exit-look').addEventListener('click', async () => {
2250
+ const b = $('tool-exit-look'); b.disabled = true; b.textContent = 'Looking…';
2251
+ try { paintToolExit(await post(`${API}/conversations/${encodeURIComponent(current)}/exit-report`, {})); }
2252
+ catch (error) { $('tool-exit-body').replaceChildren(el('p', 'error', error.message)); $('tool-exit-body').hidden = false; }
2253
+ b.disabled = false; b.textContent = 'Why did its tool stop?';
2254
+ });
2225
2255
  function paintMachine(here) {
2226
2256
  void paintReact(here);
2227
2257
  /* Its curves: asked again when it changes, or once in a while (paintCurves). */
@@ -2239,6 +2269,7 @@
2239
2269
  fact('Works in', here.work === 'kept' ? 'a folder kept here (/work)' : 'the disk of its machine (/work)');
2240
2270
  }
2241
2271
  healthLines($('machine-health'), here?.health ?? null);
2272
+ if ($('tool-exit').dataset.of !== (here?.name ?? '')) { $('tool-exit').dataset.of = here?.name ?? ''; paintToolExit(here?.lastExit ? { last: here.lastExit } : null); }
2242
2273
  $('machine-restarted').textContent = here?.restarted ?? ''; $('machine-restarted').hidden = !here?.restarted;
2243
2274
  /* The choices are not painted over while somebody is choosing. */
2244
2275
  const memory = $('machine-memory'); const disk = $('machine-disk'); const cores = $('machine-cpus');
@@ -4338,7 +4369,7 @@
4338
4369
  }
4339
4370
  if (chosen.siblings?.length) {
4340
4371
  const a = el('p', 'as-assoc hint');
4341
- a.append(el('b', '', 'Linked'), document.createTextNode(` to the same account: ${chosen.siblings.join(', ')}. They share the account's token (kept on the server); rights are given separately.`));
4372
+ a.append(el('b', '', 'Linked'), document.createTextNode(` to the same account: ${chosen.siblings.join(', ')}. They share the account's sign-in (kept on the server); rights are given separately.`));
4342
4373
  detail.append(a);
4343
4374
  }
4344
4375
  }
@@ -5842,6 +5873,8 @@
5842
5873
  const foot = el('div', 'curve-foot'); foot.append(el('span', '', curveTime(r.from, r.span)), el('span', '', 'now'));
5843
5874
  box.append(head, plot, foot);
5844
5875
  if (Number.isFinite(level)) box.append(el('small', 'hint curve-legend', '..... the reserve: what must stay free'));
5876
+ /* Said, not only on hover (a tablet has none): what a red dot is, and how many. */
5877
+ if (r.marks?.length) box.append(el('small', 'hint curve-legend curve-legend-oom', `● ${r.marks.length === 1 ? 'a program was' : `${r.marks.length} times a program was`} stopped for lack of memory`));
5845
5878
  return box;
5846
5879
  }
5847
5880
  const curvesAt = new WeakMap();
@@ -6407,9 +6440,9 @@
6407
6440
  /* New mailbox is now the classic IMAP file-copy alone. Gmail and Microsoft are
6408
6441
  a live Connexion (dynamic connector, token kept on the server): this jumps
6409
6442
  straight to adding one. */
6410
- const MAILBOX_PROVIDER = { google: 'Google', microsoft: 'Microsoft' };
6443
+ const MAILBOX_PROVIDER = { google: 'Google', microsoft: 'Microsoft', classic: 'your host' };
6411
6444
  /* Which kinds each provider can be connected for (from the server). */
6412
- let accountSupported = { google: ['mail', 'calendar', 'contacts'], microsoft: ['mail'] };
6445
+ let accountSupported = { google: ['mail', 'calendar', 'contacts'], microsoft: ['mail'], classic: ['mail', 'calendar', 'contacts'] };
6413
6446
  $('mailbox-to-connexion').addEventListener('click', () => { assetsAdding = 'connexion'; void paintAssets(); });
6414
6447
  /* CONNECT AN ACCOUNT (Connexions): a live link through Tether. The person signs
6415
6448
  in in their own browser; the token is kept on the server, never in a machine.
@@ -6419,7 +6452,12 @@
6419
6452
  const form = $('connexion-new');
6420
6453
  form.dataset.provider = provider;
6421
6454
  for (const b of $('connexion-provider').querySelectorAll('button')) b.setAttribute('aria-pressed', String(b.dataset.provider === provider));
6422
- const kinds = accountSupported[provider] ?? ['mail'];
6455
+ const classic = provider === 'classic';
6456
+ $('connexion-classic').hidden = !classic;
6457
+ $('connexion-open-row').hidden = classic;
6458
+ $('connexion-notice').hidden = classic;
6459
+ if (classic) showClassicFields();
6460
+ const kinds = classic ? ['mail', 'calendar', 'contacts'] : accountSupported[provider] ?? ['mail'];
6423
6461
  for (const [id, k] of [['connexion-calendar', 'calendar'], ['connexion-contacts', 'contacts']]) { const c = $(id); const ok = kinds.includes(k); if (!ok) c.checked = false; c.disabled = !ok; $(`${id}-label`).classList.toggle('off', !ok); }
6424
6462
  $('connexion-paste').hidden = true;
6425
6463
  $('connexion-error').hidden = true;
@@ -6432,6 +6470,39 @@
6432
6470
  $('connexion-open').textContent = `Open the ${who} sign-in page`;
6433
6471
  };
6434
6472
  for (const b of $('connexion-provider').querySelectorAll('button')) b.addEventListener('click', () => setConnexionProvider(b.dataset.provider));
6473
+ /* A CLASSIC ACCOUNT (OVH, Infomaniak, Nextcloud...): a password and its servers,
6474
+ filled from the address when known. Only the servers of the kinds ticked show. */
6475
+ function showClassicFields() {
6476
+ const on = (k) => $(`connexion-${k}`).checked;
6477
+ for (const [f, k] of [['imap', 'mail'], ['smtp', 'mail'], ['caldav', 'calendar'], ['carddav', 'contacts']]) { $(`connexion-${f}`).hidden = !on(k); $(`connexion-${f}-label`).hidden = !on(k); }
6478
+ }
6479
+ for (const id of ['connexion-mail', 'connexion-calendar', 'connexion-contacts']) $(id).addEventListener('change', () => { if ($('connexion-new').dataset.provider === 'classic') showClassicFields(); });
6480
+ let lookedUp = '';
6481
+ $('connexion-email').addEventListener('change', async () => {
6482
+ const user = $('connexion-email').value.trim();
6483
+ if ($('connexion-new').dataset.provider !== 'classic' || !user.includes('@') || user === lookedUp) return;
6484
+ lookedUp = user;
6485
+ try {
6486
+ const found = await post(`${API}/accounts/lookup`, { user });
6487
+ for (const f of ['imap', 'smtp', 'caldav', 'carddav']) if (found?.[f] && !$(`connexion-${f}`).value.trim()) $(`connexion-${f}`).value = found[f];
6488
+ } catch { /* filled by hand */ }
6489
+ });
6490
+ $('connexion-classic-connect').addEventListener('click', async () => {
6491
+ $('connexion-error').hidden = true;
6492
+ const kinds = connexionKinds();
6493
+ if (!kinds.length) { $('connexion-error').textContent = 'Choose at least mail, calendar or contacts.'; $('connexion-error').hidden = false; return; }
6494
+ const btn = $('connexion-classic-connect'); const was = btn.textContent; btn.disabled = true; btn.textContent = 'Trying the account…';
6495
+ try {
6496
+ const made = await post(`${API}/accounts/classic`, { user: $('connexion-email').value.trim(), password: $('connexion-password').value, kinds,
6497
+ imap: $('connexion-imap').value.trim(), smtp: $('connexion-smtp').value.trim(), caldav: $('connexion-caldav').value.trim(), carddav: $('connexion-carddav').value.trim() });
6498
+ if (made?.targets?.[0]) assetOpen = `connexion:${made.targets[0].id}`;
6499
+ assetsAdding = ''; lookedUp = '';
6500
+ $('connexion-new').reset(); setConnexionProvider('google');
6501
+ } catch (error) { $('connexion-error').textContent = error.message; $('connexion-error').hidden = false; }
6502
+ $('connexion-password').value = '';
6503
+ btn.disabled = false; btn.textContent = was;
6504
+ await paintAssets();
6505
+ });
6435
6506
  const connexionKinds = () => [['connexion-mail', 'mail'], ['connexion-calendar', 'calendar'], ['connexion-contacts', 'contacts']].filter(([id]) => $(id).checked && !$(id).disabled).map(([, k]) => k);
6436
6507
  $('connexion-open').addEventListener('click', async () => {
6437
6508
  $('connexion-error').hidden = true;
@@ -6471,7 +6542,7 @@
6471
6542
  await paintAssets();
6472
6543
  });
6473
6544
  setConnexionProvider('google');
6474
- getJson('/accounts', null).then((d) => { if (d?.supported) { accountSupported = d.supported; setConnexionProvider($('connexion-new').dataset.provider || 'google'); } });
6545
+ getJson('/accounts', null).then((d) => { if (d?.supported) { accountSupported = { ...d.supported, classic: ['mail', 'calendar', 'contacts'] }; setConnexionProvider($('connexion-new').dataset.provider || 'google'); } });
6475
6546
  $('list-new').addEventListener('submit', async (event) => {
6476
6547
  event.preventDefault();
6477
6548
  $('assets-error').hidden = true;
package/web/index.html CHANGED
@@ -165,6 +165,11 @@
165
165
  <div class="chapter-body">
166
166
  <div class="panel-top"><b>Health</b><button type="button" id="health-check">Look now</button></div>
167
167
  <ul id="machine-health" class="health-lines" aria-live="polite"></ul>
168
+ <!-- WHY ITS TOOL STOPPED: kept when the tool ends, read again on demand (no server access needed). -->
169
+ <div id="tool-exit" class="tool-exit">
170
+ <div class="row"><button type="button" id="tool-exit-look">Why did its tool stop?</button></div>
171
+ <div id="tool-exit-body" hidden></div>
172
+ </div>
168
173
  <!-- ITS CURVES: memory, CPU and disk over time (server/history.mjs). -->
169
174
  <div class="curves" id="machine-curves" data-of="" hidden>
170
175
  <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>
@@ -537,6 +542,7 @@
537
542
  <div id="connexion-provider" class="choices" role="group" aria-label="Kind of account">
538
543
  <button type="button" data-provider="google" aria-pressed="true">Google</button>
539
544
  <button type="button" data-provider="microsoft">Microsoft</button>
545
+ <button type="button" data-provider="classic">Other (OVH, Infomaniak…)</button>
540
546
  </div>
541
547
  <label for="connexion-email">Email address</label>
542
548
  <input id="connexion-email" type="email" spellcheck="false" autocapitalize="off" autocomplete="off" placeholder="your email address">
@@ -545,8 +551,22 @@
545
551
  <label class="check" id="connexion-calendar-label"><input type="checkbox" id="connexion-calendar"> Calendar</label>
546
552
  <label class="check" id="connexion-contacts-label"><input type="checkbox" id="connexion-contacts"> Contacts</label>
547
553
  </div>
554
+ <div id="connexion-classic" hidden>
555
+ <label for="connexion-password">Password</label>
556
+ <input id="connexion-password" type="password" autocomplete="new-password" placeholder="the account's password">
557
+ <label for="connexion-imap" id="connexion-imap-label">Mail server (IMAP)</label>
558
+ <input id="connexion-imap" spellcheck="false" autocapitalize="off" placeholder="mail.example.com">
559
+ <label for="connexion-smtp" id="connexion-smtp-label">Sending server (SMTP)</label>
560
+ <input id="connexion-smtp" spellcheck="false" autocapitalize="off" placeholder="smtp.example.com">
561
+ <label for="connexion-caldav" id="connexion-caldav-label">Calendar address (CalDAV)</label>
562
+ <input id="connexion-caldav" spellcheck="false" autocapitalize="off" placeholder="https://dav.example.com">
563
+ <label for="connexion-carddav" id="connexion-carddav-label">Contacts address (CardDAV)</label>
564
+ <input id="connexion-carddav" spellcheck="false" autocapitalize="off" placeholder="https://dav.example.com">
565
+ <p class="hint">Filled from the email address when known; your host's help pages give them otherwise. The password stays on the server and never enters a machine.</p>
566
+ <div class="row"><button type="button" id="connexion-classic-connect" class="primary">Connect</button></div>
567
+ </div>
548
568
  <p class="hint" id="connexion-notice"></p>
549
- <div class="row"><button type="button" id="connexion-open" class="primary">Open the sign-in page</button></div>
569
+ <div class="row" id="connexion-open-row"><button type="button" id="connexion-open" class="primary">Open the sign-in page</button></div>
550
570
  <div id="connexion-paste" hidden>
551
571
  <label for="connexion-code">After you allow, the page will not load — copy its full address and paste it here</label>
552
572
  <div class="row"><input id="connexion-code" spellcheck="false" autocapitalize="off" placeholder="Paste the whole address from the bar"><button type="button" id="connexion-connect" class="primary">Connect</button></div>
package/web/style.css CHANGED
@@ -1222,7 +1222,7 @@ header .ic, #folders .ic { width: 18px; height: 18px; fill: none; stroke: curren
1222
1222
  .as-foot { margin-top: 10px; }
1223
1223
  .as-form { display: flex; flex-direction: column; gap: 8px; }
1224
1224
  .as-form h3 { margin: 0; font-size: 1.125rem; }
1225
- .as-form form { display: flex; flex-direction: column; gap: 6px; }
1225
+ .as-form form, #connexion-classic:not([hidden]) { display: flex; flex-direction: column; gap: 6px; }
1226
1226
  #gitview-remote-box > summary { display: none; }
1227
1227
  #gitview-remote { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
1228
1228
  .as-none { margin: auto; text-align: center; }
@@ -1903,3 +1903,10 @@ details.commit > pre { margin: 6px 0 0 1.6em; white-space: pre-wrap; overflow-wr
1903
1903
  #preview-body:has(> img:only-child) { display: flex; align-items: center; justify-content: center; }
1904
1904
  #preview-body > img:only-child { max-height: 100%; width: auto; object-fit: contain; margin: 0; }
1905
1905
  #viewer #preview-download.ico svg { width: 20px; height: 20px; }
1906
+
1907
+ /* Why its tool stopped (Machine). */
1908
+ .tool-exit { margin: .4rem 0 .8rem; }
1909
+ .tool-exit-one { margin-top: .5rem; }
1910
+ .tool-exit-one p { margin: .2rem 0; }
1911
+ .tool-exit-lines { max-height: 14rem; overflow: auto; font-size: .78rem; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2, rgba(127,127,127,.08)); padding: .5rem .6rem; border-radius: 8px; margin: .3rem 0; }
1912
+ .curve-legend-oom { color: var(--danger); }