clavarium 0.2.224-beta.1 → 0.2.225-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/gitchecks.mjs +17 -3
- package/web/app.js +48 -13
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.225-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.225-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/gitchecks.mjs
CHANGED
|
@@ -97,11 +97,24 @@ exit "$status"`;
|
|
|
97
97
|
// eslint-disable-next-line no-control-regex
|
|
98
98
|
const printable = (text) => String(text ?? '').replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '').replace(/[\u0000-\u0008\u000B-\u001F\u007F]/gu, '').slice(-OUTPUT_MAX);
|
|
99
99
|
|
|
100
|
+
/* The agents' copies brought up to date at most so many at a time, across every repository: each is a
|
|
101
|
+
sudo and a `vm exec` on the host, and the keeper's tick reads its repositories side by side -- after a
|
|
102
|
+
start, every reference is due at once, and one fetch per repository and machine (48 seen in a few
|
|
103
|
+
seconds, 17-11) held up the host while the new server was watched for its answer. */
|
|
104
|
+
export const FETCHES_AT_ONCE = 2;
|
|
105
|
+
|
|
100
106
|
export class GitChecks {
|
|
101
|
-
#vms; #conversations; #resources; #now;
|
|
107
|
+
#vms; #conversations; #resources; #now; #free; #waiting = [];
|
|
102
108
|
|
|
103
|
-
constructor({ vms, conversations, resources, now = () => new Date() }) {
|
|
109
|
+
constructor({ vms, conversations, resources, now = () => new Date(), fetchesAtOnce = FETCHES_AT_ONCE }) {
|
|
104
110
|
this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#now = now;
|
|
111
|
+
this.#free = Math.max(1, fetchesAtOnce);
|
|
112
|
+
}
|
|
113
|
+
/* A place among the fetches running, waited for in turn; given back by the function it resolves to. */
|
|
114
|
+
async #slot() {
|
|
115
|
+
if (this.#free > 0) this.#free -= 1; else await new Promise((go) => this.#waiting.push(go));
|
|
116
|
+
let given = false;
|
|
117
|
+
return () => { if (given) return; given = true; const next = this.#waiting.shift(); if (next) next(); else this.#free += 1; };
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
/* A machine that runs and has the repository attached: one it may write
|
|
@@ -119,8 +132,9 @@ export class GitChecks {
|
|
|
119
132
|
origin/* only: its branches, its files and what it left uncommitted are not touched.
|
|
120
133
|
-> { ok, moved: [{ branch, upstream, from, to }] }: the branches it follows whose upstream moved. */
|
|
121
134
|
async fetchIn(conversation, repository) {
|
|
135
|
+
const done = await this.#slot();
|
|
122
136
|
const r = await this.#vms.exec(conversation, ['timeout', '-k', '10', '120', 'sh', '-c', FETCH_SCRIPT, 'clavarium-fetch', `/resources/${repository}`, `/resources/${originFolder(repository)}`], { timeoutMs: 180_000 })
|
|
123
|
-
.catch(() => ({ code: -1, stdout: '' }));
|
|
137
|
+
.catch(() => ({ code: -1, stdout: '' })).finally(done);
|
|
124
138
|
if (r.code !== 0) return { ok: false, moved: [] };
|
|
125
139
|
const moved = String(r.stdout ?? '').split('\n').map((l) => l.trim().split(' ')).filter((x) => x.length === 4 && /^[0-9a-f]{40,64}$/.test(x[2]) && /^[0-9a-f]{40,64}$/.test(x[3]))
|
|
126
140
|
.map(([branch, upstream, from, to]) => ({ branch: printable(branch), upstream: printable(upstream), from, to }));
|
package/web/app.js
CHANGED
|
@@ -1971,7 +1971,19 @@
|
|
|
1971
1971
|
$('items').querySelector(again)?.focus();
|
|
1972
1972
|
});
|
|
1973
1973
|
|
|
1974
|
-
|
|
1974
|
+
/* One reading of the list at a time: one asked while one runs waits for it, then one more is made for all
|
|
1975
|
+
who asked meanwhile (what they just changed is in it) -- never two side by side, nor two timers left armed. */
|
|
1976
|
+
let refreshing = null;
|
|
1977
|
+
let refreshAgain = null;
|
|
1978
|
+
function refresh() {
|
|
1979
|
+
if (refreshing) { refreshAgain ??= refreshing.then(() => { refreshAgain = null; return refresh(); }); return refreshAgain; }
|
|
1980
|
+
refreshing = refreshOnce().finally(() => { refreshing = null; });
|
|
1981
|
+
return refreshing;
|
|
1982
|
+
}
|
|
1983
|
+
/* A page out of sight (another tab, a tablet asleep) reads its list seldom; shown again, at once. */
|
|
1984
|
+
const HIDDEN_POLL_MS = 30_000;
|
|
1985
|
+
document.addEventListener('visibilitychange', () => { if (!document.hidden && home) void refresh(); });
|
|
1986
|
+
async function refreshOnce() {
|
|
1975
1987
|
clearTimeout(pollTimer);
|
|
1976
1988
|
try {
|
|
1977
1989
|
const mark = (x) => (x ? `${x.phase}/${x.asleep === true}/${holds(x)}/${Boolean(x.machine)}/${x.stopped === true}/${Boolean(x.lentTo)}` : '');
|
|
@@ -2024,7 +2036,9 @@
|
|
|
2024
2036
|
if (!DEVICE && panelShown) { void paintAnswerer(); paintWakeups(); paintMachine(conversations.find((x) => x.name === current)); }
|
|
2025
2037
|
if (!DEVICE && home) void paintJobs();
|
|
2026
2038
|
/* A start told step by step is asked about more often: its tool appears soon after its last step. */
|
|
2027
|
-
|
|
2039
|
+
clearTimeout(pollTimer);
|
|
2040
|
+
const every = conversations.some(holds) || conversations.some((c) => c.machine) ? 1500 : conversations.some((c) => c.phase === 'building' || c.phase === 'moving' || c.phase === 'restarting') ? 2500 : 10000;
|
|
2041
|
+
if (home) pollTimer = setTimeout(refresh, document.hidden ? Math.max(every, HIDDEN_POLL_MS) : every);
|
|
2028
2042
|
}
|
|
2029
2043
|
|
|
2030
2044
|
/* ---------- WHAT IT IS DOING (jobs.mjs, 14-11) ----------
|
|
@@ -3573,7 +3587,8 @@
|
|
|
3573
3587
|
: state === 'live' ? 'It is there. Below: what is ready, and what it says now.' : `Its screen: ${state}.`;
|
|
3574
3588
|
$('simple-state').dataset.needs = String(Boolean(c?.answerer?.needs));
|
|
3575
3589
|
$('simple-says').textContent = saysNow() || 'Nothing on its screen yet.';
|
|
3576
|
-
|
|
3590
|
+
/* Its files are under the plain screen: not read while the chat covers it. */
|
|
3591
|
+
if (Date.now() - simpleFilesAt > 8000 && !$('simple-plain').hidden) void paintSimpleFiles();
|
|
3577
3592
|
}
|
|
3578
3593
|
$('simple-toggle').addEventListener('click', () => toggleSimple());
|
|
3579
3594
|
function toggleSimple() {
|
|
@@ -3596,6 +3611,7 @@
|
|
|
3596
3611
|
it moved, and then only what changed (the server's cursor). The chat open keeps its own copy as it
|
|
3597
3612
|
looks again. Opened, the copy is drawn at once, then the whole window is fetched and put in its place. */
|
|
3598
3613
|
const KEPT_LAST = 50;
|
|
3614
|
+
const KEPT_EVERY_MS = 10_000;
|
|
3599
3615
|
const kept = new Map();
|
|
3600
3616
|
/* Kept once loaded: an import() asked again resolves only after the next frame, a blank one. */
|
|
3601
3617
|
let parleyLoaded = null;
|
|
@@ -3613,6 +3629,8 @@
|
|
|
3613
3629
|
const mark = JSON.stringify(c.talk);
|
|
3614
3630
|
const was = kept.get(c.name);
|
|
3615
3631
|
if (was?.mark === mark && was.thread) continue;
|
|
3632
|
+
/* Moved again soon after (the list read every 1.5 s while a machine works): its copy waits a little. */
|
|
3633
|
+
if (was?.thread && Date.now() - (was.at ?? 0) < KEPT_EVERY_MS) continue;
|
|
3616
3634
|
const cursor = typeof was?.thread?.cursor === 'string' && was.thread.cursor ? was.thread.cursor : null;
|
|
3617
3635
|
const ask = (params) => fetch(talkPath(c.name, '', params)).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
3618
3636
|
const [state, got] = await Promise.all([ask({ state: 1 }), ask({ last: KEPT_LAST, ...(cursor ? { since: cursor } : {}) })]);
|
|
@@ -3620,7 +3638,7 @@
|
|
|
3620
3638
|
if (c.name === threadOf) continue;
|
|
3621
3639
|
if (state && state.on !== true) { kept.delete(c.name); continue; }
|
|
3622
3640
|
if (!state || !Array.isArray(got?.messages)) continue;
|
|
3623
|
-
kept.set(c.name, { state, thread: cursor ? since(was.thread, got) : got, mark });
|
|
3641
|
+
kept.set(c.name, { state, thread: cursor ? since(was.thread, got) : got, mark, at: Date.now() });
|
|
3624
3642
|
}
|
|
3625
3643
|
} finally { keeping = false; }
|
|
3626
3644
|
}
|
|
@@ -3668,7 +3686,8 @@
|
|
|
3668
3686
|
if (talk.on) keptOf(name).state = talk; else kept.delete(name);
|
|
3669
3687
|
return talk;
|
|
3670
3688
|
}
|
|
3671
|
-
|
|
3689
|
+
/* `look`: false from the clock below -- the thread drawn already is not asked again (its own clock does). */
|
|
3690
|
+
async function paintThread(look = true) {
|
|
3672
3691
|
const box = $('simple-thread');
|
|
3673
3692
|
const wanted = talk.on && talkOf === current;
|
|
3674
3693
|
box.hidden = !wanted;
|
|
@@ -3696,7 +3715,7 @@
|
|
|
3696
3715
|
if ((wanted || offer) && simple && stopListening) stopVoice();
|
|
3697
3716
|
paintSimple();
|
|
3698
3717
|
if (!wanted) { thread?.destroy(); thread = null; threadOf = ''; return; }
|
|
3699
|
-
if (thread && threadOf === current) { void thread.refresh(); return; }
|
|
3718
|
+
if (thread && threadOf === current) { if (look !== false) void thread.refresh(); return; }
|
|
3700
3719
|
thread?.destroy(); thread = null; threadOf = '';
|
|
3701
3720
|
const name = current;
|
|
3702
3721
|
/* From where this page is: a device's page lives under /c/, and nothing else is open to it. */
|
|
@@ -3851,7 +3870,7 @@
|
|
|
3851
3870
|
tasksTimer = setInterval(async () => {
|
|
3852
3871
|
if (!thread) { clearInterval(tasksTimer); tasksTimer = null; return; }
|
|
3853
3872
|
if (document.hidden) return;
|
|
3854
|
-
const now = await
|
|
3873
|
+
const now = await peopleNow();
|
|
3855
3874
|
if (!now || now.changes === tasksChanges) return;
|
|
3856
3875
|
tasksChanges = now.changes; binderPeople = now.people;
|
|
3857
3876
|
void paintTasks(threadOf);
|
|
@@ -4249,7 +4268,9 @@
|
|
|
4249
4268
|
all.hidden = !all.hidden;
|
|
4250
4269
|
if (!all.hidden && wordsSettings) all.textContent = JSON.stringify(Object.fromEntries(Object.entries(wordsSettings.english).filter(([key]) => key !== 'lang')), null, 2);
|
|
4251
4270
|
});
|
|
4252
|
-
|
|
4271
|
+
/* Its chat drawn already: Parley's own clock looks at its thread (every 3 s) -- not asked again here,
|
|
4272
|
+
which made two looks side by side (paintThread(false)). */
|
|
4273
|
+
setInterval(() => { if (!document.hidden && current) void readTalk().then(() => { if (simple) void paintThread(false); paintSimple(); }); }, 5000);
|
|
4253
4274
|
|
|
4254
4275
|
$('simple-say').addEventListener('submit', (event) => {
|
|
4255
4276
|
event.preventDefault();
|
|
@@ -4536,6 +4557,17 @@
|
|
|
4536
4557
|
}
|
|
4537
4558
|
return fallback;
|
|
4538
4559
|
};
|
|
4560
|
+
/* WHO MAY OWN A CARD, and the binders' count of changes (GET /binder/people): asked by two clocks (the chat's
|
|
4561
|
+
batches, the Binders tab) and a binder opened. One question at a time, and its answer kept a moment, under
|
|
4562
|
+
the 4 s of those clocks: each still sees a change at its next turn, without asking twice. */
|
|
4563
|
+
const PEOPLE_KEPT_MS = 3000;
|
|
4564
|
+
let peopleAsked = null; let peopleAt = 0;
|
|
4565
|
+
const peopleNow = () => {
|
|
4566
|
+
if (peopleAsked && (peopleAt === 0 || Date.now() - peopleAt < PEOPLE_KEPT_MS)) return peopleAsked;
|
|
4567
|
+
const asking = getJson('/binder/people', null).then((got) => { if (peopleAsked === asking) { if (got) peopleAt = Date.now(); else peopleAsked = null; } return got; });
|
|
4568
|
+
peopleAsked = asking; peopleAt = 0;
|
|
4569
|
+
return asking;
|
|
4570
|
+
};
|
|
4539
4571
|
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
|
|
4540
4572
|
/* A commit: its line, and the rest of its message under it, opened by a click. */
|
|
4541
4573
|
function commitRow(c) {
|
|
@@ -6618,6 +6650,8 @@
|
|
|
6618
6650
|
if (v.root.isConnected) { v.away = 0; continue; }
|
|
6619
6651
|
v.away += 1;
|
|
6620
6652
|
if (v.away >= 3 && v.socket) { const ws = v.socket; v.socket = null; v.phase = 'closed'; try { ws.close(); } catch { /* gone */ } }
|
|
6653
|
+
/* Its chat too: not read every 3 s for a screen no longer there (drawn again when it is shown). */
|
|
6654
|
+
if (v.away >= 3 && v.chat) { v.chat.destroy(); v.chat = null; v.chatOf = ''; }
|
|
6621
6655
|
}
|
|
6622
6656
|
}, 10_000);
|
|
6623
6657
|
/* The parts: the console (kept), then what the AI proposes and has typed, then the journal (drawn each paint). */
|
|
@@ -6633,6 +6667,7 @@
|
|
|
6633
6667
|
if (!v.opened) { v.term.open(v.screen); v.opened = true; }
|
|
6634
6668
|
v.fit();
|
|
6635
6669
|
if (!v.socket) consoleConnect(v);
|
|
6670
|
+
if ((v.full || v.below) && !v.chatOf) void consoleChat(v);
|
|
6636
6671
|
if (hadFocus) v.term.focus();
|
|
6637
6672
|
});
|
|
6638
6673
|
consolePaint(v);
|
|
@@ -7101,7 +7136,7 @@
|
|
|
7101
7136
|
card.dataset.room = r.id;
|
|
7102
7137
|
return card;
|
|
7103
7138
|
}
|
|
7104
|
-
let salonThread = null; let salonId = '';
|
|
7139
|
+
let salonThread = null; let salonId = '';
|
|
7105
7140
|
/* A room's bar while one of its AIs speaks: its dot at work (gold, breathing), the words under its name. */
|
|
7106
7141
|
function salonLive(who) {
|
|
7107
7142
|
const dot = $('salon-state'); const line = $('salon-live');
|
|
@@ -7118,7 +7153,7 @@
|
|
|
7118
7153
|
const rows = ['person', 'ai', 'box'].map((k) => { const of = r.members.filter((m) => m.kind === k); if (!of.length) return null; const row = el('div', 'salon-members-row'); row.append(el('span', 'hint', k === 'person' ? uiSaid('set-room-people', 'People') : k === 'ai' ? uiSaid('set-room-ais-of', 'AIs') : uiSaid('set-room-boxes-of', 'Boxes')), ...of.map((m) => { const x = el('span', 'salon-member'); x.append(memberChips([m], 1), document.createTextNode(m.name)); if (m.host) x.append(el('span', 'salon-host', uiSaid('set-room-host-mark', 'host'))); return x; })); return row; }).filter(Boolean);
|
|
7119
7154
|
$('salon-members').replaceChildren(...rows);
|
|
7120
7155
|
}
|
|
7121
|
-
function salonLeft() {
|
|
7156
|
+
function salonLeft() { salonThread?.destroy(); salonThread = null; salonId = ''; }
|
|
7122
7157
|
/* `step`: picked by the owner (the list, the deck): as a conversation picked, the list folds. */
|
|
7123
7158
|
async function openSalon(id, push = true, { step = false } = {}) {
|
|
7124
7159
|
if (DEVICE) return;
|
|
@@ -7204,7 +7239,7 @@
|
|
|
7204
7239
|
draft: `room:${id}`,
|
|
7205
7240
|
act: (action) => { tetherAct(action, () => salonThread?.refresh?.()); },
|
|
7206
7241
|
});
|
|
7207
|
-
|
|
7242
|
+
/* Looked at again by Parley's own clock (every 3 s, while the page is in sight): no second clock here. */
|
|
7208
7243
|
}
|
|
7209
7244
|
$('salon-close').addEventListener('click', () => leavePlace());
|
|
7210
7245
|
$('salon-who').addEventListener('click', () => { const open = $('salon-members').hidden; $('salon-members').hidden = !open; $('salon-who').setAttribute('aria-expanded', String(open)); });
|
|
@@ -7902,7 +7937,7 @@
|
|
|
7902
7937
|
/* `still()`: whether it is still wanted once its parts are read (another one asked meanwhile: not drawn). */
|
|
7903
7938
|
async function mountBinder(holder, keep, { onLists, of, place: at = null, steps = null, still = () => true } = {}) {
|
|
7904
7939
|
binderParts ??= Promise.all([import(new URL('vendor/binder-ui.js', new URL('/', location.href)).href), fetch(`/vendor/binder-${binderLang()}.json`).then((r) => r.json()).catch(() => ({}))]);
|
|
7905
|
-
const [[{ mount }, words], seen] = await Promise.all([binderParts,
|
|
7940
|
+
const [[{ mount }, words], seen] = await Promise.all([binderParts, peopleNow()]);
|
|
7906
7941
|
if (seen) { binderPeople = seen.people; binderChanges = seen.changes; }
|
|
7907
7942
|
if (!holder.isConnected || !still()) return null;
|
|
7908
7943
|
let shown = [];
|
|
@@ -8099,7 +8134,7 @@
|
|
|
8099
8134
|
/* Read again every screen of a binder when the binders changed. Taken as seen only once every
|
|
8100
8135
|
screen read it again: one that failed (the server restarting) is read again at the next turn. */
|
|
8101
8136
|
async function catchUpBinders() {
|
|
8102
|
-
const now = await
|
|
8137
|
+
const now = await peopleNow();
|
|
8103
8138
|
if (!now) return;
|
|
8104
8139
|
binderPeople = now.people;
|
|
8105
8140
|
if (now.changes === binderChanges) return;
|