clavarium 0.2.22 → 0.2.23-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/README.md +4 -1
- package/deploy/clavarium-host +2 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/capacity.mjs +11 -2
- package/server/gitkeeper.mjs +29 -3
- package/server/main.mjs +1 -1
- package/server/shelf.mjs +2 -0
- package/server/talk.mjs +17 -5
- package/web/app.js +223 -13
- package/web/style.css +35 -0
package/README.md
CHANGED
|
@@ -104,7 +104,10 @@ Built slice by slice; the plan is in `blueprint/architecture.html`, tab
|
|
|
104
104
|
under /work/.parley/files/, the tool given its path). What is wrong with its
|
|
105
105
|
machine, and its restarts, are grey lines in the thread, with what can be
|
|
106
106
|
done; after a restart the tool is told once to read the whole thread again
|
|
107
|
-
(`parley read --all`).
|
|
107
|
+
(`parley read --all`). The server keeps its own copy of the thread, out of
|
|
108
|
+
the machine: a line the tool rewrites or deletes in /work/.parley, the
|
|
109
|
+
owner's too, is shown as it was, and the thread says "History changed
|
|
110
|
+
here". Off by default, per conversation; what the tool
|
|
108
111
|
prints in its terminal is never read.
|
|
109
112
|
|
|
110
113
|
- **13 - the machine**: each conversation's machine is looked at after a
|
package/deploy/clavarium-host
CHANGED
|
@@ -87,6 +87,8 @@ SHELF_CACHE="$SHELF_STORE/cache"
|
|
|
87
87
|
# (No drop-in is the usual case: under pipefail a missing file must not stop this program.)
|
|
88
88
|
MOVED_TO="$( { sed -n 's/^Environment=MULTIPASS_STORAGE=\(\/[A-Za-z0-9/._-]*\)$/\1/p' /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf 2>/dev/null || true; } | head -1)"
|
|
89
89
|
if [ -n "$MOVED_TO" ] && [ -d "$MOVED_TO/data" ]; then SHELF_STORE="$MOVED_TO"; SHELF_INSTANCES="$MOVED_TO/data/vault/instances"; SHELF_CACHE="$MOVED_TO/cache"; fi
|
|
90
|
+
# Also the floor under a grown disk (grow_room): the server keeps the same
|
|
91
|
+
# (MIN_FREE_MB in server/shelf.mjs, used by server/capacity.mjs).
|
|
90
92
|
SHELF_MIN_FREE_MB="6144"
|
|
91
93
|
CONF="/etc/clavarium/host.conf"
|
|
92
94
|
# THE GIT READER (verb "git read"): an empty root-owned directory used as the
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23-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.23-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-docket": "0.1.0",
|
|
15
|
-
"clavarium-parley": "0.
|
|
15
|
+
"clavarium-parley": "0.14.0-next.1",
|
|
16
16
|
"mermaid": "11.17.2",
|
|
17
17
|
"node-pty": "^1.1.0",
|
|
18
18
|
"pdfjs-dist": "6.4.299",
|
|
@@ -700,9 +700,9 @@
|
|
|
700
700
|
}
|
|
701
701
|
},
|
|
702
702
|
"node_modules/clavarium-parley": {
|
|
703
|
-
"version": "0.
|
|
704
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.
|
|
705
|
-
"integrity": "sha512-
|
|
703
|
+
"version": "0.14.0-next.1",
|
|
704
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.14.0-next.1.tgz",
|
|
705
|
+
"integrity": "sha512-hPscRjPaoh9Jjucjt0C48DSiOOEwVj2ZUBBs0iGL7rIZlqC/GuxwFq6KvlSqWVyVFuyOwRsO7OdpGcuYVsWjZQ==",
|
|
706
706
|
"license": "MIT",
|
|
707
707
|
"bin": {
|
|
708
708
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23-next.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.",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@xterm/addon-fit": "^0.11.0",
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-docket": "0.1.0",
|
|
48
|
-
"clavarium-parley": "0.
|
|
48
|
+
"clavarium-parley": "0.14.0-next.1",
|
|
49
49
|
"mermaid": "11.17.2",
|
|
50
50
|
"node-pty": "^1.1.0",
|
|
51
51
|
"pdfjs-dist": "6.4.299",
|
package/server/capacity.mjs
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* nothing is refused: the reserve is a guard, not a gate that jams.
|
|
37
37
|
*/
|
|
38
38
|
import { Refusal, DISK_GB } from './conversations.mjs';
|
|
39
|
+
import { MIN_FREE_MB } from './shelf.mjs';
|
|
39
40
|
|
|
40
41
|
export const RESERVE_DISK_MB = 5 * 1024;
|
|
41
42
|
export const RESERVE_MEMORY_MB = 1024;
|
|
@@ -244,8 +245,16 @@ export class Capacity {
|
|
|
244
245
|
throw new Refusal(409, `${verb}: this server cannot spare ${asks}. It has ${gb(f.memory.freeMb)} of memory free and keeps ${gb(r.memoryMb)} in reserve. ${what}, or lower the reserve in Settings, This server.`);
|
|
245
246
|
}
|
|
246
247
|
const takes = kind === 'create' ? (this.#shelf?.about?.().current?.sizeMb ?? NEW_MACHINE_MB) : diskMb;
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
/* A disk grown: the host program refuses it under its own floor
|
|
249
|
+
(grow_room in deploy/clavarium-host: what it grows by, plus
|
|
250
|
+
SHELF_MIN_FREE_MB), whatever reserve is set here. The same rule
|
|
251
|
+
here, so that it is refused before anything is stopped. */
|
|
252
|
+
if (f.disk && kind === 'grow' && takes > 0) {
|
|
253
|
+
const needMb = takes + Math.max(r.diskMb, MIN_FREE_MB);
|
|
254
|
+
if (f.disk.freeMb < needMb) throw new Refusal(409, `${verb}: ${gb(f.disk.freeMb)} of disk free, ${gb(needMb)} needed.`);
|
|
255
|
+
}
|
|
256
|
+
if (f.disk && kind === 'create' && takes > 0 && f.disk.freeMb - takes < r.diskMb) {
|
|
257
|
+
const asks = `the ${gb(takes)} of disk a new machine takes`;
|
|
249
258
|
throw new Refusal(409, `${verb}: this server cannot spare ${asks}. It has ${gb(f.disk.freeMb)} of disk free and keeps ${gb(r.diskMb)} in reserve. Archive conversations you no longer need, or lower the reserve in Settings, This server.`);
|
|
250
259
|
}
|
|
251
260
|
}
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -207,8 +207,13 @@ const upTo = (id) => (short(id) ? ` (up to ${short(id)})` : '');
|
|
|
207
207
|
/* "See the N commits": from the tip before to the tip now, as the review shows them; none for a new branch. */
|
|
208
208
|
const seeCommits = (name, head, base, n) => (short(head) && short(base) && Number.isInteger(n) && n > 0 ? [`commits:${name}.${head.slice(0, 12)}.${base.slice(0, 12)}.${Math.min(n, 9999)}`] : []);
|
|
209
209
|
|
|
210
|
+
/* How long one request waits for a check before it hears it still runs (a proxy cuts longer ones), and how
|
|
211
|
+
long a finished run is kept for the request that asks again just after. */
|
|
212
|
+
export const CHECK_WAIT_MS = 20_000;
|
|
213
|
+
export const CHECK_KEEP_MS = 60_000;
|
|
214
|
+
|
|
210
215
|
export class GitKeeper {
|
|
211
|
-
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map();
|
|
216
|
+
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map();
|
|
212
217
|
|
|
213
218
|
/* `review`: GitReview (reads, the reference, Send). `checks`: GitChecks.
|
|
214
219
|
`alerts`: what tells the owner's phone. `tellAgent(repository, line,
|
|
@@ -480,7 +485,28 @@ export class GitKeeper {
|
|
|
480
485
|
const target = body?.target || undefined;
|
|
481
486
|
const seen = typeof body?.head === 'string' ? this.#review.reviewOf(r.name, body.head, target) : undefined;
|
|
482
487
|
if (!seen) throw new Refusal(409, 'The repository changed since you looked: look again at what would be sent.');
|
|
483
|
-
return this.#
|
|
488
|
+
return this.#joined(r.name, seen, body?.wait, body?.join === true);
|
|
489
|
+
}
|
|
490
|
+
/* A CHECK OUTLIVES THE REQUEST THAT ASKED FOR IT. It may take minutes (dependencies installed, then the
|
|
491
|
+
tests), longer than a proxy on the way lets one request wait: the page was cut off and said "could not
|
|
492
|
+
run" while the checks ran on. So the run is kept here by repository, commit and target; a request
|
|
493
|
+
waits for it at most CHECK_WAIT_MS, then hears { status: 'running' } and asks again, joining the same run. */
|
|
494
|
+
/* A run still going is always joined; one just ended only by `join` (the page asking again after
|
|
495
|
+
"running"): any other ask is a new run, as before. */
|
|
496
|
+
async #joined(name, seen, wait, join = false) {
|
|
497
|
+
const key = `${name}\n${seen.head}\n${seen.target ?? ''}`;
|
|
498
|
+
let entry = this.#inFlight.get(key);
|
|
499
|
+
if (!entry || (entry.done && !join)) {
|
|
500
|
+
const made = { done: false };
|
|
501
|
+
made.run = this.#check(name, seen).finally(() => { made.done = true; setTimeout(() => { if (this.#inFlight.get(key) === made) this.#inFlight.delete(key); }, CHECK_KEEP_MS).unref?.(); });
|
|
502
|
+
this.#inFlight.set(key, made);
|
|
503
|
+
entry = made;
|
|
504
|
+
}
|
|
505
|
+
const run = entry.run;
|
|
506
|
+
const ms = Number.isFinite(wait) ? Math.max(0, Math.min(wait, CHECK_WAIT_MS)) : CHECK_WAIT_MS;
|
|
507
|
+
let timer;
|
|
508
|
+
const pending = new Promise((ok) => { timer = setTimeout(() => ok({ status: 'running', head: seen.head, branch: seen.branch, target: seen.target }), ms); });
|
|
509
|
+
try { return await Promise.race([run, pending]); } finally { clearTimeout(timer); }
|
|
484
510
|
}
|
|
485
511
|
/* `machine`: the conversation whose machine runs them (automatic sending). */
|
|
486
512
|
async #check(name, seen, machine) {
|
|
@@ -520,7 +546,7 @@ export class GitKeeper {
|
|
|
520
546
|
const branch = typeof body?.branch === 'string' && body.branch ? body.branch : undefined;
|
|
521
547
|
const out = await this.#review.outgoing(r.name, { target, branch });
|
|
522
548
|
if (!out?.head || !out.target) throw new Refusal(409, out?.message || 'There is no commit to check on this branch.');
|
|
523
|
-
return this.#
|
|
549
|
+
return this.#joined(r.name, { head: out.head, branch: out.branch, target: out.target, remoteTip: out.remoteTip ?? null }, body?.wait);
|
|
524
550
|
}
|
|
525
551
|
|
|
526
552
|
/* Send, from the page: as GitReview.push, and refused when the owner
|
package/server/main.mjs
CHANGED
|
@@ -388,7 +388,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
388
388
|
checks: new GitChecks({ vms, conversations: all, resources: folders }) });
|
|
389
389
|
const gitTimer = gitKeeper.start(gitEveryMs);
|
|
390
390
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
391
|
-
const talk = new Talk({ store: talkStore, words: new Store(`${dataDir}/talk-words.json`), vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
391
|
+
const talk = new Talk({ store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
392
392
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
393
393
|
/* A line typed down the terminal already open when there is one, and
|
|
394
394
|
what is already known of a machine used instead of asking (talk.mjs). */
|
package/server/shelf.mjs
CHANGED
|
@@ -35,6 +35,8 @@ export const REFRESH_MS = 30 * DAY;
|
|
|
35
35
|
/* A little more than a month: a monthly rebuild that failed for a few days
|
|
36
36
|
does not send every new conversation the long way at once. */
|
|
37
37
|
export const MAX_AGE_MS = 40 * DAY;
|
|
38
|
+
/* SHELF_MIN_FREE_MB of deploy/clavarium-host, which refuses under it too:
|
|
39
|
+
a rebuild, and a disk grown (on top of what it grows by: capacity.mjs). */
|
|
38
40
|
export const MIN_FREE_MB = 6 * 1024;
|
|
39
41
|
/* After a failed or refused rebuild, the next automatic try waits this long. */
|
|
40
42
|
export const RETRY_MS = DAY;
|
package/server/talk.mjs
CHANGED
|
@@ -40,6 +40,13 @@
|
|
|
40
40
|
* AFTER A RESTART the tool starts again with no memory of the
|
|
41
41
|
* chat: once it had time to start, REREAD is typed
|
|
42
42
|
* in its terminal, once (it reads the whole thread).
|
|
43
|
+
* THE THREAD, KEPT HERE Parley's own copy (its `keep`): every line read
|
|
44
|
+
* or written is kept in this server's data, one
|
|
45
|
+
* folder per conversation, out of the machine's
|
|
46
|
+
* reach. That copy is what the page shows; a line
|
|
47
|
+
* the tool rewrote or deleted in /work/.parley --
|
|
48
|
+
* the person's too -- is said in the thread
|
|
49
|
+
* ("History changed here"), never taken.
|
|
43
50
|
* FILES OF THE PERSON attached to a message, put under
|
|
44
51
|
* /work/.parley/files/<id>/<name>, and the message
|
|
45
52
|
* gives the tool their paths.
|
|
@@ -51,7 +58,7 @@
|
|
|
51
58
|
*/
|
|
52
59
|
import { posix, join } from 'node:path';
|
|
53
60
|
import { randomUUID } from 'node:crypto';
|
|
54
|
-
import { mkdirSync, lstatSync } from 'node:fs';
|
|
61
|
+
import { mkdirSync, lstatSync, rmSync } from 'node:fs';
|
|
55
62
|
import { install, Parley, WAKE, REREAD, texts, fill, LANGUAGES, SHOWN_MAX, FILES_MAX } from 'clavarium-parley/host';
|
|
56
63
|
import { importFile } from './files.mjs';
|
|
57
64
|
import { KEYS } from 'clavarium-parley/ui';
|
|
@@ -152,15 +159,18 @@ const WORDS = Object.freeze([...KEYS, 'alert-asks', 'alert-waits']);
|
|
|
152
159
|
export class Talk {
|
|
153
160
|
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #listening = new Map(); #every; #now;
|
|
154
161
|
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
155
|
-
#terminal; #health; #ranAt = new Map();
|
|
162
|
+
#terminal; #health; #ranAt = new Map(); #kept;
|
|
156
163
|
|
|
157
164
|
/* `alert({ title, body, url })`: told when the tool asks, or waits.
|
|
158
165
|
`words`: a store for the owner's choice of words (one record). */
|
|
159
166
|
/* `terminal`: the terminals the bridge keeps open (bridge.mjs): `open(name)`,
|
|
160
167
|
`type(name, line, enterAfterMs)`, `droppedAt(name)`. `health`: what was
|
|
161
168
|
last seen of each machine (health.mjs), `of(name)`. Both optional. */
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
/* `keptDir`: where each conversation's thread is kept (its own folder),
|
|
170
|
+
in this server's data -- never in the work folder, which its machine
|
|
171
|
+
writes. Without it, the bridge folder is all there is. */
|
|
172
|
+
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null }) {
|
|
173
|
+
this.#terminal = terminal; this.#health = health; this.#kept = keptDir;
|
|
164
174
|
this.#store = store; this.#words = words; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#toolbox = toolbox; this.#warm = warm; this.#alert = alert; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
165
175
|
for (const s of store.all()) if (s.on === true) this.#listen(s.name);
|
|
166
176
|
this.#timer = setInterval(() => { void this.#tick(); }, Math.min(listenEveryMs, 1000));
|
|
@@ -173,6 +183,7 @@ export class Talk {
|
|
|
173
183
|
return c;
|
|
174
184
|
}
|
|
175
185
|
#dir(name) { return `${this.#resources.workFolder(name)}/${FOLDER}`; }
|
|
186
|
+
#keep(name) { return this.#kept && isConversationName(name) ? join(this.#kept, name) : undefined; }
|
|
176
187
|
|
|
177
188
|
/* ---- the words a person reads ---- */
|
|
178
189
|
settings() {
|
|
@@ -241,6 +252,7 @@ export class Talk {
|
|
|
241
252
|
|
|
242
253
|
#parley(name, reacted = () => {}) {
|
|
243
254
|
return new Parley(this.#dir(name), {
|
|
255
|
+
keep: this.#keep(name),
|
|
244
256
|
reach: (path) => this.#reach(name, path),
|
|
245
257
|
on: (event) => {
|
|
246
258
|
if (event.type === 'person-reacted') { reacted(event); return; }
|
|
@@ -572,6 +584,6 @@ export class Talk {
|
|
|
572
584
|
}
|
|
573
585
|
}
|
|
574
586
|
|
|
575
|
-
forget(name) { this.#deaf(name); this.#store.remove(name); this.#typedAt.delete(name); this.#ranAt.delete(name); this.#nextTry.delete(name); this.#nextTry.delete(`reread:${name}`); }
|
|
587
|
+
forget(name) { this.#deaf(name); if (this.#keep(name)) rmSync(this.#keep(name), { recursive: true, force: true }); this.#store.remove(name); this.#typedAt.delete(name); this.#ranAt.delete(name); this.#nextTry.delete(name); this.#nextTry.delete(`reread:${name}`); }
|
|
576
588
|
stop() { clearInterval(this.#timer); for (const name of [...this.#listening.keys()]) this.#deaf(name); }
|
|
577
589
|
}
|
package/web/app.js
CHANGED
|
@@ -354,6 +354,7 @@
|
|
|
354
354
|
document.documentElement.dataset.theme = light ? 'light' : 'dark';
|
|
355
355
|
/* The chat's colours of meaning (notes, warnings, code) follow the page's theme, not the device's. */
|
|
356
356
|
$('simple-thread').dataset.theme = light ? 'light' : 'dark';
|
|
357
|
+
for (const view of document.querySelectorAll('.md-view')) view.dataset.theme = light ? 'light' : 'dark';
|
|
357
358
|
terminal.options.theme = light ? LIGHT : DARK;
|
|
358
359
|
document.querySelector('meta[name=theme-color]')?.setAttribute('content', light ? LIGHT.background : DARK.background);
|
|
359
360
|
$('theme').textContent = light ? 'Dark' : 'Light';
|
|
@@ -2959,6 +2960,7 @@
|
|
|
2959
2960
|
ticked, on a click; then Send. */
|
|
2960
2961
|
async function sendDetail(holder, names) {
|
|
2961
2962
|
const progress = el('p', 'status-line ts-progress'); progress.setAttribute('role', 'status');
|
|
2963
|
+
const meter = el('div', 'ts-meter'); const meterFill = el('i'); meter.append(meterFill); meter.setAttribute('aria-hidden', 'true');
|
|
2962
2964
|
const filters = el('div', 'levels ts-filters'); filters.setAttribute('role', 'group'); filters.setAttribute('aria-label', 'Show');
|
|
2963
2965
|
const list = el('div', 'ts-rows');
|
|
2964
2966
|
const bar = el('div', 'as-acts ts-bar');
|
|
@@ -2968,12 +2970,12 @@
|
|
|
2968
2970
|
bar.append(together, go, why);
|
|
2969
2971
|
const said = el('p', 'ts-said'); said.hidden = true; said.setAttribute('role', 'status');
|
|
2970
2972
|
const review = el('div', 'ts-review'); review.hidden = true;
|
|
2971
|
-
holder.append(progress, filters, list, bar, said, review);
|
|
2973
|
+
holder.append(progress, meter, filters, list, bar, said, review);
|
|
2972
2974
|
const rows = [];
|
|
2973
2975
|
let filter = 'update';
|
|
2974
2976
|
let sending = false; let checking = false;
|
|
2975
2977
|
let sure = '';
|
|
2976
|
-
let
|
|
2978
|
+
let reposDone = 0; let reading = true;
|
|
2977
2979
|
const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter;
|
|
2978
2980
|
const picked = () => rows.filter((r) => r.picked && r.out?.state === 'ahead' && shownRow(r));
|
|
2979
2981
|
const label = (r) => (rows.filter((x) => x.name === r.name).length > 1 ? `${r.name} (${r.branch})` : r.name);
|
|
@@ -2985,19 +2987,28 @@
|
|
|
2985
2987
|
r.out = out; r.keep = keep; r.branch = out.branch ?? r.branch; r.target = out.target ?? r.target; r.check = null;
|
|
2986
2988
|
if (out.state !== 'ahead') r.picked = false;
|
|
2987
2989
|
}
|
|
2990
|
+
/* The server keeps the run: a request hears "running" after a while, and asks again until it ends. */
|
|
2988
2991
|
async function checkRow(r) {
|
|
2989
2992
|
const { head, target } = r.out;
|
|
2990
|
-
r.check = { status: 'running' }; paint();
|
|
2993
|
+
r.check = { status: 'running' }; r.open = false; paint();
|
|
2991
2994
|
let result;
|
|
2992
|
-
|
|
2993
|
-
|
|
2995
|
+
for (let first = true; ; first = false) {
|
|
2996
|
+
try { result = await post(`${API}/git/${r.name}/check`, { head, target, ...(first ? {} : { join: true }) }); }
|
|
2997
|
+
catch (error) { result = { status: 'unavailable', output: `The page could not reach the server: ${error.message}` }; }
|
|
2998
|
+
if (result?.status !== 'running' || r.out?.head !== head || r.out?.target !== target) break;
|
|
2999
|
+
}
|
|
2994
3000
|
if (r.out?.head !== head || r.out?.target !== target) return;
|
|
2995
3001
|
r.check = result; paint();
|
|
2996
3002
|
}
|
|
3003
|
+
/* What its agent is told when checks did not pass: where, and the end of what they said. */
|
|
3004
|
+
const forAgent = (r) => `The checks of ${r.name} (${r.out.branch} → ${r.out.target}) did not pass before sending. Please fix it, commit, and tell me.\n\n\`\`\`\n${String(r.check?.output ?? '').slice(-3000)}\n\`\`\``;
|
|
2997
3005
|
const stopped = (r) => Boolean(r.keep?.settings?.requireForSend) && r.check?.status !== 'passed';
|
|
2998
3006
|
function paintProgress() {
|
|
2999
3007
|
const count = (k) => rows.filter((r) => kindOfRow(r.out) === k).length;
|
|
3000
|
-
|
|
3008
|
+
/* By repositories: how many there are is known from the start, how many branches each has is not. */
|
|
3009
|
+
meter.hidden = !reading; meterFill.style.width = `${names.length ? Math.round((reposDone / names.length) * 100) : 100}%`;
|
|
3010
|
+
progress.toggleAttribute('data-busy', reading);
|
|
3011
|
+
if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `Reading the repositories: ${reposDone} of ${names.length}${rows.length ? ` · ${rows.length} branch${rows.length === 1 ? '' : 'es'} found` : ''}`; }
|
|
3001
3012
|
else { progress.dataset.tone = count('update') + count('new') ? 'ok' : ''; progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new · all read` : 'Nothing to send · all read'; }
|
|
3002
3013
|
filters.replaceChildren(...TS_FILTERS.map(([key, word]) => {
|
|
3003
3014
|
const n = key === 'all' ? rows.length : count(key);
|
|
@@ -3067,9 +3078,36 @@
|
|
|
3067
3078
|
else if (r.check.status === 'running') state.append(el('span', 'warn', 'Checking...'));
|
|
3068
3079
|
else {
|
|
3069
3080
|
const [word, tone] = CHECK_WORDS[r.check.status] ?? [String(r.check.status), ''];
|
|
3070
|
-
|
|
3081
|
+
const text = r.check.status === 'passed' ? '✓ Checks passed' : r.check.status === 'failed' ? '✗ Checks failed' : word;
|
|
3082
|
+
/* What did not pass says why, one tap away: the reason, what they printed, and what to do. */
|
|
3083
|
+
if (r.check.status === 'failed' || r.check.status === 'unavailable') {
|
|
3084
|
+
const open = el('button', `ts-why-open ${tone}`, `${text} ${r.open ? '▴' : '▾'}`); open.type = 'button'; open.setAttribute('aria-expanded', String(Boolean(r.open)));
|
|
3085
|
+
open.addEventListener('click', () => { r.open = !r.open; paint(); });
|
|
3086
|
+
state.append(open);
|
|
3087
|
+
} else state.append(el('b', tone || 'quiet', text));
|
|
3071
3088
|
}
|
|
3072
3089
|
row.append(tick, who, way, size, state);
|
|
3090
|
+
if (!r.seen) { r.seen = true; if (reading) row.classList.add('ts-new'); }
|
|
3091
|
+
if (r.open && r.check && !r.sent) {
|
|
3092
|
+
const lines = String(r.check.output ?? '').split('\n').map((x) => x.trim()).filter(Boolean);
|
|
3093
|
+
const box = el('div', 'ts-why-box');
|
|
3094
|
+
box.append(el('p', '', lines[0] ?? 'Nothing was said.'));
|
|
3095
|
+
if (lines.length > 1) box.append(el('pre', 'ts-output', String(r.check.output).slice(-4000)));
|
|
3096
|
+
const acts = el('div', 'action-row');
|
|
3097
|
+
const again = el('button', '', 'Check again'); again.type = 'button'; again.dataset.act = 'check-again';
|
|
3098
|
+
again.disabled = checking || sending;
|
|
3099
|
+
again.addEventListener('click', async () => { checking = true; await checkRow(r); checking = false; paint(); });
|
|
3100
|
+
const tell = el('button', '', talk.on && talkOf === current ? 'Ask its agent to fix it' : 'Copy for its agent'); tell.type = 'button'; tell.dataset.act = 'tell-agent';
|
|
3101
|
+
tell.addEventListener('click', async () => {
|
|
3102
|
+
try {
|
|
3103
|
+
if (talk.on && talkOf === current) { await post(talkPath(current), { text: forAgent(r) }); tell.textContent = '✓ Sent to its chat'; }
|
|
3104
|
+
else { await navigator.clipboard.writeText(forAgent(r)); tell.textContent = '✓ Copied'; }
|
|
3105
|
+
tell.disabled = true;
|
|
3106
|
+
} catch (error) { tell.textContent = `Not done: ${error.message}`; }
|
|
3107
|
+
});
|
|
3108
|
+
acts.append(again, tell); box.append(acts);
|
|
3109
|
+
row.append(box);
|
|
3110
|
+
}
|
|
3073
3111
|
if (r.sent && !r.sent.ok) row.append(el('p', 'ts-note bad', r.sent.text));
|
|
3074
3112
|
list.append(row);
|
|
3075
3113
|
}
|
|
@@ -3188,18 +3226,18 @@
|
|
|
3188
3226
|
await Promise.all(names.map(async (name) => {
|
|
3189
3227
|
const first = { name, out: null, keep: null, branch: '', target: '', picked: false, check: null, sent: null };
|
|
3190
3228
|
rows.push(first);
|
|
3191
|
-
await look(first);
|
|
3229
|
+
await look(first);
|
|
3192
3230
|
first.movedAt = (first.out?.agentBranches ?? []).find((b) => b.name === first.branch)?.movedAt ?? null;
|
|
3193
3231
|
first.picked = kindOfRow(first.out) === 'update';
|
|
3194
3232
|
const others = (first.out?.agentBranches ?? []).filter((b) => b.name !== first.branch).slice(0, BRANCHES_MORE);
|
|
3195
|
-
planned += others.length;
|
|
3196
3233
|
paint();
|
|
3197
3234
|
await Promise.all(others.map(async (b) => {
|
|
3198
3235
|
const r = { name, out: null, keep: first.keep, branch: b.name, target: '', picked: false, check: null, sent: null, movedAt: b.movedAt };
|
|
3199
|
-
await look(r);
|
|
3236
|
+
await look(r);
|
|
3200
3237
|
if (r.out?.state === 'ahead') { r.picked = kindOfRow(r.out) === 'update' && lately(r); rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
|
|
3201
3238
|
paint();
|
|
3202
3239
|
}));
|
|
3240
|
+
reposDone++; paint();
|
|
3203
3241
|
}));
|
|
3204
3242
|
reading = false;
|
|
3205
3243
|
paint();
|
|
@@ -5940,13 +5978,17 @@
|
|
|
5940
5978
|
const PREVIEW_MAX = 25 * 1024 * 1024;
|
|
5941
5979
|
const TEXT_MAX = 1024 * 1024;
|
|
5942
5980
|
const PICTURES = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp' };
|
|
5943
|
-
const TEXTS = ['txt', 'md', 'csv', 'tsv', 'json', 'log', 'yaml', 'yml', 'toml', 'ini', 'xml', 'html', 'css', 'js', 'mjs', 'ts', 'py', 'sh', 'sql', 'c', 'h', 'go', 'rs', 'java', 'rb', 'php', 'tex', 'eml'];
|
|
5981
|
+
const TEXTS = ['txt', 'md', 'markdown', 'csv', 'tsv', 'json', 'log', 'yaml', 'yml', 'toml', 'ini', 'xml', 'html', 'css', 'js', 'mjs', 'ts', 'py', 'sh', 'sql', 'c', 'h', 'go', 'rs', 'java', 'rb', 'php', 'tex', 'eml'];
|
|
5944
5982
|
const PDF_PAGES = 30;
|
|
5983
|
+
/* Beyond this, a Markdown file is shown as its text: formatting it would hold the page. */
|
|
5984
|
+
const MD_MAX = 512 * 1024;
|
|
5945
5985
|
let shownUrl = null;
|
|
5946
5986
|
/* The file is shown in a WINDOW over the screen, wherever it was asked
|
|
5947
5987
|
from: closing it leaves the terminal, or the list, as it was. */
|
|
5948
5988
|
function closePreview() {
|
|
5949
5989
|
if (shownUrl) { URL.revokeObjectURL(shownUrl); shownUrl = null; }
|
|
5990
|
+
for (const url of mdUrls) URL.revokeObjectURL(url);
|
|
5991
|
+
mdUrls.clear();
|
|
5950
5992
|
editing = null;
|
|
5951
5993
|
delete $('viewer').dataset.editing;
|
|
5952
5994
|
$('preview-body').replaceChildren();
|
|
@@ -6011,6 +6053,142 @@
|
|
|
6011
6053
|
const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range);
|
|
6012
6054
|
return true;
|
|
6013
6055
|
}
|
|
6056
|
+
/* A MARKDOWN FILE, SHOWN FORMATTED, as the chat shows what the tool
|
|
6057
|
+
writes. Parley reads the text into plain data (its markdown()); the
|
|
6058
|
+
page is built from that data element by element, its text as text:
|
|
6059
|
+
never the file as markup. Parley does not export its painter yet: once
|
|
6060
|
+
it does (renderMarkdown, with these same slots), it is used instead of
|
|
6061
|
+
the one here. Slots: picture(src) the address of a picture this
|
|
6062
|
+
preview may show, or null (then its caption is shown); open(href) a
|
|
6063
|
+
function opening a file of the same folder, or null; diagram and
|
|
6064
|
+
highlight as for the chat. Blob addresses made go into `urls`. */
|
|
6065
|
+
const mdUrls = new Set();
|
|
6066
|
+
let mdWords = null;
|
|
6067
|
+
async function markdownPage(text, slots) {
|
|
6068
|
+
const P = await import(new URL('vendor/parley-ui.js', new URL(DEVICE ? '/c/' : '/', location.href)).href);
|
|
6069
|
+
if (!mdWords) mdWords = await readWords().catch(() => ({}));
|
|
6070
|
+
const all = { words: mdWords, urls: mdUrls, ...slots };
|
|
6071
|
+
if (typeof P.renderMarkdown === 'function') return P.renderMarkdown(text, all);
|
|
6072
|
+
return paintMarkdown(P.markdown(text), P.safeLink, all);
|
|
6073
|
+
}
|
|
6074
|
+
function paintMarkdown(data, safeLink, { words, picture, open, diagram, highlight, urls }) {
|
|
6075
|
+
const el = (tag, className, text) => { const e = document.createElement(tag); if (className) e.className = className; if (text !== undefined) e.textContent = text; return e; };
|
|
6076
|
+
const said = (key, fallback) => (typeof words?.[key] === 'string' ? words[key] : fallback);
|
|
6077
|
+
const KINDS = { note: 'Note', tip: 'Tip', important: 'Important', warning: 'Warning', caution: 'Caution' };
|
|
6078
|
+
const BADGES = { ok: 'ok', todo: 'todo', blocked: 'blocked', warn: 'warn' };
|
|
6079
|
+
function inlines(nodes, into) {
|
|
6080
|
+
for (const n of nodes) {
|
|
6081
|
+
if (n.t === 'text') into.append(n.v);
|
|
6082
|
+
else if (n.t === 'br') into.append(el('br'));
|
|
6083
|
+
else if (n.t === 'code') into.append(el('code', '', n.v));
|
|
6084
|
+
else if (n.t === 'em' || n.t === 'strong' || n.t === 'del' || n.t === 'mark') into.append(inlines(n.c, el(n.t === 'del' ? 's' : n.t)));
|
|
6085
|
+
else if (n.t === 'badge') { const b = el('span', 'parley-badge', said(`badge-${n.kind}`, BADGES[n.kind] ?? n.kind)); b.dataset.kind = n.kind; into.append(b); }
|
|
6086
|
+
else if (n.t === 'link') {
|
|
6087
|
+
const href = safeLink(n.href);
|
|
6088
|
+
const go = href ? null : open?.(n.href);
|
|
6089
|
+
if (href) { const a = el('a', 'parley-link'); a.href = href; a.target = '_blank'; a.rel = 'noopener noreferrer nofollow'; a.title = href; into.append(inlines(n.c, a)); }
|
|
6090
|
+
else if (go) { const b = el('button', 'parley-pathlink'); b.type = 'button'; b.title = n.href; b.addEventListener('click', go); into.append(inlines(n.c, b)); }
|
|
6091
|
+
else into.append(inlines(n.c, el('span')));
|
|
6092
|
+
} else if (n.t === 'img') {
|
|
6093
|
+
const url = picture?.(n.src);
|
|
6094
|
+
if (url) { const img = el('img'); img.src = url; img.alt = n.alt || n.src.split('/').pop(); img.loading = 'lazy'; img.decoding = 'async'; into.append(img); }
|
|
6095
|
+
else { const off = el('span', 'parley-noimg', n.alt || n.src.split('/').pop()); off.title = said('not-shown', 'Not shown here'); into.append(off); }
|
|
6096
|
+
}
|
|
6097
|
+
}
|
|
6098
|
+
return into;
|
|
6099
|
+
}
|
|
6100
|
+
function tokens(list, depth) {
|
|
6101
|
+
const out = [];
|
|
6102
|
+
for (const t of list) {
|
|
6103
|
+
if (typeof t === 'string') { out.push(t); continue; }
|
|
6104
|
+
if (!t || typeof t !== 'object' || depth > 12) continue;
|
|
6105
|
+
const span = el('span', 'parley-tok');
|
|
6106
|
+
for (const n of [t.type, ...(Array.isArray(t.alias) ? t.alias : [t.alias])]) if (typeof n === 'string' && /^[a-z][a-z-]{0,30}$/.test(n)) span.classList.add(`parley-tok-${n}`);
|
|
6107
|
+
span.append(...(Array.isArray(t.content) ? tokens(t.content, depth + 1) : [String(t.content ?? '')]));
|
|
6108
|
+
out.push(span);
|
|
6109
|
+
}
|
|
6110
|
+
return out;
|
|
6111
|
+
}
|
|
6112
|
+
function code(b) {
|
|
6113
|
+
const holder = el('div', 'parley-code');
|
|
6114
|
+
const bar = el('div', 'parley-code-bar');
|
|
6115
|
+
const c = el('code', '', b.text);
|
|
6116
|
+
const pre = el('pre'); pre.append(c);
|
|
6117
|
+
const copy = el('button', 'parley-copy', said('copy', 'Copy')); copy.type = 'button';
|
|
6118
|
+
copy.addEventListener('click', () => {
|
|
6119
|
+
const done = () => { copy.textContent = said('copied', 'Copied'); setTimeout(() => { copy.textContent = said('copy', 'Copy'); }, 1500); };
|
|
6120
|
+
try { void navigator.clipboard.writeText(b.text).then(done, () => selectAll(c)); } catch { selectAll(c); }
|
|
6121
|
+
});
|
|
6122
|
+
bar.append(el('span', 'parley-code-lang', b.lang), copy);
|
|
6123
|
+
holder.append(bar, pre);
|
|
6124
|
+
if (highlight && b.lang && b.text.length <= 40_000) Promise.resolve().then(() => highlight(b.text, b.lang)).then((tree) => { if (Array.isArray(tree)) c.replaceChildren(...tokens(tree, 0)); }, () => {});
|
|
6125
|
+
return holder;
|
|
6126
|
+
}
|
|
6127
|
+
function drawing(b) {
|
|
6128
|
+
if (!diagram || b.text.length > 20_000) return code(b);
|
|
6129
|
+
const fig = el('figure', 'parley-diagram');
|
|
6130
|
+
fig.append(el('span', 'parley-diagram-wait', said('diagram', 'Diagram')));
|
|
6131
|
+
Promise.resolve().then(() => diagram(b.text)).then((svg) => {
|
|
6132
|
+
if (typeof svg !== 'string' || !/^\s*(<\?xml[^>]*>\s*)?<svg[\s>]/i.test(svg)) throw new Error('not a drawing');
|
|
6133
|
+
/* A picture runs nothing and loads nothing: the drawing is shown as one. */
|
|
6134
|
+
const url = URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
|
|
6135
|
+
urls?.add(url);
|
|
6136
|
+
const img = el('img'); img.src = url; img.alt = said('diagram', 'Diagram');
|
|
6137
|
+
fig.replaceChildren(img);
|
|
6138
|
+
}).catch(() => fig.replaceWith(code(b)));
|
|
6139
|
+
return fig;
|
|
6140
|
+
}
|
|
6141
|
+
function block(b) {
|
|
6142
|
+
if (b.t === 'p') return inlines(b.c, el('p'));
|
|
6143
|
+
if (b.t === 'h') return inlines(b.c, el(`h${Math.min(6, b.level + 1)}`, `parley-h parley-h${b.level}`));
|
|
6144
|
+
if (b.t === 'hr') return el('hr');
|
|
6145
|
+
if (b.t === 'code') return b.lang === 'mermaid' ? drawing(b) : code(b);
|
|
6146
|
+
if (b.t === 'quote') return blocks(b.c, el('blockquote'));
|
|
6147
|
+
if (b.t === 'alert') {
|
|
6148
|
+
const box = el('div', 'parley-callout'); box.dataset.kind = b.kind; box.setAttribute('role', 'note');
|
|
6149
|
+
box.append(el('p', 'parley-callout-head', said(b.kind, KINDS[b.kind] ?? b.kind)));
|
|
6150
|
+
return blocks(b.c, box);
|
|
6151
|
+
}
|
|
6152
|
+
if (b.t === 'list') {
|
|
6153
|
+
const list = el(b.ordered ? 'ol' : 'ul');
|
|
6154
|
+
if (Number.isInteger(b.start)) list.start = b.start;
|
|
6155
|
+
for (const item of b.items) {
|
|
6156
|
+
const li = el('li');
|
|
6157
|
+
if (item.task !== null) { li.className = 'parley-task'; const box = el('span', 'parley-check', item.task ? '☑' : '☐'); box.dataset.done = String(item.task); li.append(box); }
|
|
6158
|
+
if (item.c.length === 1 && item.c[0].t === 'p') inlines(item.c[0].c, li); else blocks(item.c, li);
|
|
6159
|
+
list.append(li);
|
|
6160
|
+
}
|
|
6161
|
+
return list;
|
|
6162
|
+
}
|
|
6163
|
+
if (b.t === 'table') {
|
|
6164
|
+
const wrap = el('div', 'parley-table'); wrap.tabIndex = 0;
|
|
6165
|
+
const table = el('table'); const head = el('thead'); const tr = el('tr'); const body = el('tbody');
|
|
6166
|
+
b.head.forEach((cell, k) => { const th = el('th'); if (b.align[k]) th.style.textAlign = b.align[k]; tr.append(inlines(cell, th)); });
|
|
6167
|
+
head.append(tr);
|
|
6168
|
+
for (const row of b.rows) { const r = el('tr'); row.forEach((cell, k) => { const td = el('td'); if (b.align[k]) td.style.textAlign = b.align[k]; r.append(inlines(cell, td)); }); body.append(r); }
|
|
6169
|
+
table.append(head, body); wrap.append(table);
|
|
6170
|
+
return wrap;
|
|
6171
|
+
}
|
|
6172
|
+
return el('span');
|
|
6173
|
+
}
|
|
6174
|
+
function blocks(list, into) { for (const b of list) into.append(block(b)); return into; }
|
|
6175
|
+
return blocks(data, el('div', 'parley-md'));
|
|
6176
|
+
}
|
|
6177
|
+
/* A path written in a Markdown file, as a place in the same folder kept
|
|
6178
|
+
here: relative to the file, or absolute under /work or the folder's own
|
|
6179
|
+
/resources/<name>. Never above the top of the folder; anything else: null. */
|
|
6180
|
+
function besideFile(tab, inner, href) {
|
|
6181
|
+
let raw = String(href ?? '').trim().replace(/[?#].*$/, '');
|
|
6182
|
+
if (!raw || /^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith('//')) return null;
|
|
6183
|
+
try { raw = decodeURIComponent(raw); } catch { return null; }
|
|
6184
|
+
let parts;
|
|
6185
|
+
const top = tab === 'work' ? '/work/' : `/resources/${tab}/`;
|
|
6186
|
+
if (raw.startsWith('/')) { if (!raw.startsWith(top)) return null; parts = raw.slice(top.length).split('/'); }
|
|
6187
|
+
else parts = [...inner.split('/').slice(0, -1), ...raw.split('/')];
|
|
6188
|
+
const out = [];
|
|
6189
|
+
for (const p of parts) { if (p === '' || p === '.') continue; if (p === '..') { if (!out.length) return null; out.pop(); } else out.push(p); }
|
|
6190
|
+
return out.length ? out.join('/') : null;
|
|
6191
|
+
}
|
|
6014
6192
|
/* `tab`, `inner`: its place in a folder kept here. `from`: an address to
|
|
6015
6193
|
read it at instead (a file of the machine's own disk). */
|
|
6016
6194
|
async function preview(tab, inner, name, size, from) {
|
|
@@ -6085,9 +6263,9 @@
|
|
|
6085
6263
|
} catch { body.replaceChildren(); note('This PDF could not be shown here. Download it to open it.'); }
|
|
6086
6264
|
} else {
|
|
6087
6265
|
const text = new TextDecoder('utf-8', { fatal: false }).decode(bytes);
|
|
6088
|
-
const source = () => { const pre = document.createElement('pre'); pre.textContent = text; return pre; };
|
|
6266
|
+
const source = () => { const pre = document.createElement('pre'); pre.className = 'source'; pre.textContent = text; return pre; };
|
|
6089
6267
|
/* Copy: all its text, the source of a page too. Refused, the text is shown and selected. */
|
|
6090
|
-
offerCopy({ text }, { select: () => { if (!body.querySelector('pre')) body.querySelector('button')?.click(); return selectAll(body.querySelector('pre')); } });
|
|
6268
|
+
offerCopy({ text }, { select: () => { if (!body.querySelector('pre.source')) body.querySelector('button')?.click(); return selectAll(body.querySelector('pre.source')); } });
|
|
6091
6269
|
/* A page written by the tool is SHOWN AS A PAGE -- in a frame that is
|
|
6092
6270
|
nobody: no session, no network, nothing of this site (the server
|
|
6093
6271
|
answers it with those rules; see files.mjs). Its source is one
|
|
@@ -6109,6 +6287,38 @@
|
|
|
6109
6287
|
});
|
|
6110
6288
|
body.append(toggle, frame);
|
|
6111
6289
|
note('A page written by the tool, shown in a closed frame: it reaches nothing outside itself. Never type a password into it.');
|
|
6290
|
+
} else if ((kind === 'md' || kind === 'markdown') && text.length <= MD_MAX) {
|
|
6291
|
+
/* Markdown: formatted, its text one tap away (the choice kept on this device). */
|
|
6292
|
+
let page;
|
|
6293
|
+
try {
|
|
6294
|
+
page = await markdownPage(text, {
|
|
6295
|
+
/* Pictures as the thumbnails of Files allow them (the server checks the folder and the bytes); a file of the machine's disk shows none. */
|
|
6296
|
+
picture: (src) => { const p = from ? null : besideFile(tab, inner, src); return p && /\.(png|jpe?g|gif|webp)$/i.test(p) ? `${API}/files/thumb?${new URLSearchParams({ c: current, r: tab, p })}` : null; },
|
|
6297
|
+
open: (href) => { const p = from ? null : besideFile(tab, inner, href); return p ? () => { void preview(tab, p, p.split('/').pop(), 0); } : null; },
|
|
6298
|
+
diagram: drawDiagram, highlight: colourCode,
|
|
6299
|
+
});
|
|
6300
|
+
} catch { page = null; }
|
|
6301
|
+
if ($('viewer').hidden || $('preview-name').textContent !== name) return;
|
|
6302
|
+
if (!page) { body.append(source()); note(''); return; }
|
|
6303
|
+
const formatted = document.createElement('div'); formatted.className = 'parley md-view'; formatted.dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
6304
|
+
formatted.append(page);
|
|
6305
|
+
const raw = source();
|
|
6306
|
+
const switcher = document.createElement('div'); switcher.className = 'md-switch'; switcher.setAttribute('role', 'group'); switcher.setAttribute('aria-label', 'Show');
|
|
6307
|
+
const choice = (label, what) => { const b = document.createElement('button'); b.type = 'button'; b.textContent = label; b.dataset.show = what; b.addEventListener('click', () => show(what, true)); return b; };
|
|
6308
|
+
const asFormatted = choice('Formatted', 'formatted'); const asText = choice('Text', 'text');
|
|
6309
|
+
switcher.append(asFormatted, asText);
|
|
6310
|
+
const show = (what, keep) => {
|
|
6311
|
+
asFormatted.setAttribute('aria-pressed', String(what === 'formatted')); asText.setAttribute('aria-pressed', String(what === 'text'));
|
|
6312
|
+
formatted.dataset.theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
6313
|
+
body.replaceChildren(switcher, what === 'text' ? raw : formatted);
|
|
6314
|
+
if (keep) { try { localStorage.setItem('clavarium-md-show', what); } catch { /* a private window: not kept */ } }
|
|
6315
|
+
};
|
|
6316
|
+
let first = 'formatted';
|
|
6317
|
+
try { if (localStorage.getItem('clavarium-md-show') === 'text') first = 'text'; } catch { /* as above */ }
|
|
6318
|
+
show(first, false);
|
|
6319
|
+
/* Refused copy: the text is shown and selected. */
|
|
6320
|
+
offerCopy({ text }, { select: () => { show('text', false); return selectAll(raw); } });
|
|
6321
|
+
note('');
|
|
6112
6322
|
} else { body.append(source()); note(offline && (kind === 'html' || kind === 'htm') ? 'This conversation is offline: its page is shown as text, not run.' : ''); }
|
|
6113
6323
|
}
|
|
6114
6324
|
}
|
package/web/style.css
CHANGED
|
@@ -351,6 +351,28 @@ footer button.careful { border-style: dashed; color: var(--ink2); }
|
|
|
351
351
|
/* A page written by the tool: a frame with a visible edge, so it never passes for this site. */
|
|
352
352
|
#preview-body iframe { display: block; width: 100%; height: min(70vh, 900px); border: 2px solid var(--brass); border-radius: 8px; background: #fff; }
|
|
353
353
|
#preview-body > button { margin-bottom: 8px; min-height: 40px; }
|
|
354
|
+
/* A Markdown file, formatted as the chat shows what the tool writes: the page's
|
|
355
|
+
colours, a reading measure; tables, code and drawings scroll in their box. */
|
|
356
|
+
.md-switch { position: sticky; top: 0; z-index: 1; display: inline-flex; margin-bottom: 10px; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
|
|
357
|
+
#viewer .md-switch button { min-height: 32px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--ink2); font-weight: 600; }
|
|
358
|
+
#viewer .md-switch button[aria-pressed="true"] { background: var(--bar); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
|
|
359
|
+
#preview-body .md-view { display: block; container: none; min-height: 0; padding: 0 2px 24px; font-size: .9375rem; line-height: 1.55;
|
|
360
|
+
--parley-bg: var(--panel); --parley-text: var(--ink); --parley-dim: var(--ink2); --parley-line: var(--line); --parley-agent: var(--bar); --parley-action: var(--brass); --parley-measure: 80ch; }
|
|
361
|
+
:root[data-theme="light"] #preview-body .md-view { --parley-action: #8a5d00; }
|
|
362
|
+
#preview-body .md-view .parley-md { max-width: 80ch; }
|
|
363
|
+
#preview-body .md-view .parley-md > * + * { margin-top: .8em; }
|
|
364
|
+
#preview-body .md-view .parley-md > .parley-h { margin-top: 1.3em; }
|
|
365
|
+
#preview-body .md-view .parley-md > .parley-h:first-child { margin-top: 0; }
|
|
366
|
+
#preview-body .md-view .parley-h1 { font-size: 1.6em; padding-bottom: .25em; border-bottom: 1px solid var(--line); }
|
|
367
|
+
#preview-body .md-view .parley-h2 { font-size: 1.3em; padding-bottom: .2em; border-bottom: 1px solid var(--line); }
|
|
368
|
+
#preview-body .md-view .parley-h3 { font-size: 1.12em; }
|
|
369
|
+
#preview-body .md-view pre { white-space: pre; overflow-wrap: normal; font-size: .8125rem; }
|
|
370
|
+
#preview-body .md-view img { display: inline-block; max-width: 100%; max-height: 28rem; margin: 0; border-radius: 6px; vertical-align: top; }
|
|
371
|
+
#preview-body .md-view .parley-diagram img { display: block; background: #fff; padding: 8px; }
|
|
372
|
+
#viewer .md-view button.parley-copy { min-height: 28px; }
|
|
373
|
+
#viewer .md-view button.parley-pathlink { min-height: 0; }
|
|
374
|
+
#preview-body .md-view .parley-callout-head { margin: 0; }
|
|
375
|
+
#preview-body .md-view .parley-table { max-width: 100%; }
|
|
354
376
|
|
|
355
377
|
/* Answers in the owner's place. */
|
|
356
378
|
#answerer-fields textarea { width: 100%; min-height: 4.5rem; resize: vertical; font: inherit; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
|
|
@@ -1529,4 +1551,17 @@ details.more[open] > summary { margin-bottom: 4px; }
|
|
|
1529
1551
|
:is(#updates, #wifi) > .set-rows { padding: 0; }
|
|
1530
1552
|
:is(#updates, #wifi) > .hint { padding-top: 8px; padding-bottom: 8px; }
|
|
1531
1553
|
.ts-progress { margin: 10px 0 0; font-size: .875rem; }
|
|
1554
|
+
/* While the repositories are read: a turning ring on the line, and a true bar under it (repositories read of all). */
|
|
1555
|
+
.ts-progress[data-busy]::before { width: 10px; height: 10px; background: none; border: 2px solid var(--warn); border-right-color: transparent; animation: ts-turn .8s linear infinite; }
|
|
1556
|
+
@keyframes ts-turn { to { transform: rotate(360deg); } }
|
|
1557
|
+
.ts-meter { height: 4px; border-radius: 2px; background: var(--line); margin: 6px 0 2px; overflow: hidden; max-width: 28rem; }
|
|
1558
|
+
.ts-meter i { display: block; height: 100%; background: var(--warn); border-radius: 2px; transition: width .3s ease; }
|
|
1559
|
+
/* A row read just now slides in: it is seen arriving. */
|
|
1560
|
+
.ts-row.ts-new { animation: ts-arrive .35s ease-out; }
|
|
1561
|
+
@keyframes ts-arrive { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
|
|
1562
|
+
@media (prefers-reduced-motion: reduce) { .ts-row.ts-new, .ts-progress[data-busy]::before { animation: none; } }
|
|
1563
|
+
.ts-why-open { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; cursor: pointer; text-align: inherit; }
|
|
1564
|
+
.ts-why-open.bad { color: var(--danger); } .ts-why-open.warn { color: var(--warn); }
|
|
1565
|
+
.ts-why-box { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
|
|
1566
|
+
.ts-why-box p { margin: 0; }
|
|
1532
1567
|
.ts-filters { margin-top: 10px; }
|