clavarium 0.2.482-next.1 → 0.2.484-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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +16 -1
- package/server/main.mjs +6 -2
- package/server/talk.mjs +74 -28
- package/server/vm.mjs +6 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.484-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.484-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -1961,6 +1961,19 @@ export class Conversations {
|
|
|
1961
1961
|
/* The conversations whose machine should be running: built, not asleep. */
|
|
1962
1962
|
/* (Stopped by its owner: not running either, until somebody starts it.) */
|
|
1963
1963
|
awake() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep !== true && c.stopped !== true).map((c) => c.name); }
|
|
1964
|
+
/* Every machine running, its disk trimmed (vm.mjs trim), one machine at a time, a shared one once. */
|
|
1965
|
+
async trimAll() {
|
|
1966
|
+
const seen = new Set();
|
|
1967
|
+
for (const name of this.awake()) {
|
|
1968
|
+
const vm = this.#vms.vmOf?.(name) ?? name;
|
|
1969
|
+
if (seen.has(vm)) continue;
|
|
1970
|
+
seen.add(vm);
|
|
1971
|
+
if ((await this.#vms.state(name).catch(() => undefined)) !== 'Running') continue;
|
|
1972
|
+
await this.#trim(name);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
/* Before a stop or a sleep: what it erased given back first, never holding the stop up long. */
|
|
1976
|
+
async #trim(name, timeoutMs) { if (typeof this.#vms.trim !== 'function') return; await this.#vms.trim(name, timeoutMs).catch(() => undefined); }
|
|
1964
1977
|
/* Put to sleep, and nothing else: not one being built (02-11: a reset machine was taken for a sleeper and
|
|
1965
1978
|
suspended mid-build), not a failed one. */
|
|
1966
1979
|
/* (One woken the time a copy reads it -- #borrowed -- is not asleep then: its memory is never "reclaimed" under it.) */
|
|
@@ -2171,6 +2184,7 @@ export class Conversations {
|
|
|
2171
2184
|
this.#plan(name, act, ['suspend']);
|
|
2172
2185
|
this.drop(name);
|
|
2173
2186
|
act.ctl = new AbortController();
|
|
2187
|
+
await this.#trim(name, 60_000);
|
|
2174
2188
|
const r = await this.#vms.suspend(name, { signal: act.ctl.signal, onLine: (line) => this.#seen(name, act, line) });
|
|
2175
2189
|
if (r.aborted) result = { ok: false, preempted: true };
|
|
2176
2190
|
else {
|
|
@@ -2285,12 +2299,13 @@ export class Conversations {
|
|
|
2285
2299
|
has its tool, a screen or an action: then only this one's programs end, the others go on. */
|
|
2286
2300
|
async #stopUnlessShared(name) {
|
|
2287
2301
|
const shared = this.#store.get(name)?.sharedMachine;
|
|
2288
|
-
if (!shared) return this.#vms.stop(name);
|
|
2302
|
+
if (!shared) { await this.#trim(name, 60_000); return this.#vms.stop(name); }
|
|
2289
2303
|
for (const other of this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared)) {
|
|
2290
2304
|
if (this.#watching.has(other.name) || this.#acts.has(other.name) || this.#timers.has(other.name)) return this.#endShared(name);
|
|
2291
2305
|
const alive = await this.#vms.exec(other.name, ['tmux', '-L', SOCKET, 'has-session', '-t', `=${SESSION}`]).catch(() => ({ code: 1 }));
|
|
2292
2306
|
if (alive.code === 0) return this.#endShared(name);
|
|
2293
2307
|
}
|
|
2308
|
+
await this.#trim(name, 60_000);
|
|
2294
2309
|
return this.#vms.stop(name);
|
|
2295
2310
|
}
|
|
2296
2311
|
#endShared(name) { return this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: STEP_MS }).catch(() => undefined); }
|
package/server/main.mjs
CHANGED
|
@@ -562,7 +562,9 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
562
562
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
563
563
|
/* A line typed down the terminal already open when there is one, and
|
|
564
564
|
what is already known of a machine used instead of asking (talk.mjs). */
|
|
565
|
-
|
|
565
|
+
/* `settled` (17-11): how long its terminal has been open and quiet -- without it, the line after a restart
|
|
566
|
+
was typed REREAD_AFTER_MS after, into a tool maybe still loading (talk.mjs, READY). */
|
|
567
|
+
terminal: { open: (name) => bridge?.open(name) ?? false, type: (name, line, ms) => bridge?.type(name, line, ms) ?? false, droppedAt: (name) => bridge?.droppedAt(name), settled: (name) => bridge?.settled(name) ?? null },
|
|
566
568
|
health: { of: (name) => health?.of(name) ?? null },
|
|
567
569
|
/* A secret pasted in a message is lifted out before the message is kept:
|
|
568
570
|
it goes to the short-lived vault and the message keeps only a marker
|
|
@@ -788,6 +790,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
788
790
|
for (const name of all.awake()) { const now = await secrets.reconcile(name, delivered.get(name)).catch(() => null); if (now !== null) delivered.set(name, now); }
|
|
789
791
|
};
|
|
790
792
|
const secretsTimer = setInterval(() => { void secretsGuard().catch(() => {}); }, 60_000); secretsTimer.unref?.();
|
|
793
|
+
/* The machines' disks give back what was erased, every hour (conversations.trimAll, vm.mjs trim). */
|
|
794
|
+
const trimTimer = setInterval(() => { void all.trimAll().catch(() => {}); }, 60 * 60_000); trimTimer.unref?.();
|
|
791
795
|
/* The certificate the front serves, said in Settings (certificate.mjs). */
|
|
792
796
|
const certificate = new Certificate({ origin: publicOrigin, alerts });
|
|
793
797
|
/* All the machines to another disk, from Settings (machinesmove.mjs). */
|
|
@@ -924,7 +928,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
924
928
|
screen: await quick(screenNow(), 1500, null), catalogue: await quick(catalogue.providers().catch(() => []), 1500, []),
|
|
925
929
|
}) });
|
|
926
930
|
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, machineList, features, desks: new Desks({ file: new JsonFile(`${dataDir}/desktops.json`, {}) }), apikeys, relayJoin: host.length ? new RelayJoin({ host: asHost }) : null, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
927
|
-
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopNetworkWatch(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); clearInterval(stopSigninHelp); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
931
|
+
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); clearInterval(trimTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopNetworkWatch(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); clearInterval(stopSigninHelp); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
928
932
|
let closing = false;
|
|
929
933
|
boxes.attach(server, WebSocketServer);
|
|
930
934
|
browsers.attach(server, WebSocketServer); server.on('close', () => browsers.shutdown());
|
package/server/talk.mjs
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* until the tool has read, never while somebody
|
|
18
18
|
* types there, never into a machine that does not
|
|
19
19
|
* run (the message waits, and the line is typed
|
|
20
|
-
* when it runs again)
|
|
20
|
+
* when it runs again); still unread a while
|
|
21
|
+
* after, typed again by itself (RENUDGE_MS).
|
|
21
22
|
* agent-asked, waiting the owner's devices are alerted.
|
|
22
23
|
* agent-showed a file under /work or in an attached folder is
|
|
23
24
|
* opened from the page; any other is said to be
|
|
@@ -116,15 +117,27 @@ export const HEALTH_KNOWN_MS = 150_000;
|
|
|
116
117
|
export const enterCommand = () => ['tmux', '-L', SOCKET, 'send-keys', '-t', PANE, 'Enter'];
|
|
117
118
|
/* Escape, alone: what the Esc key of the page's key row sends -- a tool's current turn stopped (an API key that may act, apikeys.mjs). */
|
|
118
119
|
export const escapeCommand = () => ['tmux', '-L', SOCKET, 'send-keys', '-t', PANE, 'Escape'];
|
|
120
|
+
/* A PANE SCROLLED BACK IS IN COPY MODE (`mouse on`: the wheel of any screen puts it there, and it stays
|
|
121
|
+
there when that screen goes away): the keys of a line typed then are copy-mode commands, the line never
|
|
122
|
+
reaches the tool and its Enter only leaves the mode (tried with tmux 3.4). The mode is left first, in
|
|
123
|
+
the same command -- nothing is done to a pane that is not in a mode (no shell: -F reads a format). */
|
|
124
|
+
const LEAVE_MODE = ['if-shell', '-F', '-t', PANE, '#{pane_in_mode}', `send-keys -t ${PANE} -X cancel`, ';'];
|
|
119
125
|
export function typeCommand(line) {
|
|
120
126
|
const text = line.endsWith(';') ? `${line.slice(0, -1)}\\;` : line;
|
|
121
|
-
return ['tmux', '-L', SOCKET, 'send-keys', '-t', PANE, '-l', '--', text, ';', 'run-shell', '-d', String(ENTER_AFTER_MS / 1000), ';', 'send-keys', '-t', PANE, 'Enter'];
|
|
127
|
+
return ['tmux', '-L', SOCKET, ...LEAVE_MODE, 'send-keys', '-t', PANE, '-l', '--', text, ';', 'run-shell', '-d', String(ENTER_AFTER_MS / 1000), ';', 'send-keys', '-t', PANE, 'Enter'];
|
|
122
128
|
}
|
|
129
|
+
/* Where the line is in typeCommand's argument vector. */
|
|
130
|
+
export const TYPED_AT = 3 + LEAVE_MODE.length + 5;
|
|
123
131
|
/* Added to Parley's invitation, this server's own sentence: a branch can be
|
|
124
132
|
checked out in one folder only, and /tmp is emptied when the machine
|
|
125
133
|
restarts, with the work left there. Typed in a terminal: no quote, no
|
|
126
134
|
backquote, nothing a shell would run. */
|
|
127
135
|
export const BRANCHES = 'Check out your branches in the main folder of the repository or under /work, never in /tmp: a branch can be checked out in one folder only, and /tmp is emptied when the machine restarts. The checks before sending run in a copy made at exactly the commit to send (CLAVARIUM_CHECK_COPY, CLAVARIUM_CHECK_HEAD): never write a check that needs the main folder on a branch or at that commit.';
|
|
136
|
+
/* THE LINE TYPED AGAIN BY ITSELF (17-11): one line lost (a pane in copy mode, a tool drawing a modal)
|
|
137
|
+
silenced every later one, the tool "told" till it read. A message still unread this long after its
|
|
138
|
+
line was typed has it typed again, these long after the last, then every last one of them -- till the
|
|
139
|
+
tool reads (its read count moves). Kept in its record: a restart of this server goes on. */
|
|
140
|
+
export const RENUDGE_MS = Object.freeze([60_000, 180_000, 600_000]);
|
|
128
141
|
/* After a restart, the tool is given this long to start before REREAD is typed. */
|
|
129
142
|
export const REREAD_AFTER_MS = 10_000;
|
|
130
143
|
/* READY, NOT JUST STARTED. The tool starts when its terminal is opened, which
|
|
@@ -222,8 +235,8 @@ export const windowOf = (choice) => { const [kind, n] = String(choice).split(':'
|
|
|
222
235
|
const PART = /^[A-Za-z0-9._~-]{1,200}$/;
|
|
223
236
|
export class Talk {
|
|
224
237
|
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #spoke; #inRoom; #listening = new Map(); #every; #now;
|
|
225
|
-
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
226
|
-
#terminal; #health; #ranAt = new Map(); #kept; #screen; #dropSecret;
|
|
238
|
+
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #ticking = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
239
|
+
#terminal; #health; #ranAt = new Map(); #kept; #screen; #dropSecret; #log;
|
|
227
240
|
|
|
228
241
|
/* `alert({ title, body, url })`: told when the tool asks, or waits.
|
|
229
242
|
`words`: a store for the owner's choice of words (one record). */
|
|
@@ -233,7 +246,8 @@ export class Talk {
|
|
|
233
246
|
/* `keptDir`: where each conversation's thread is kept (its own folder),
|
|
234
247
|
in this server's data -- never in the work folder, which its machine
|
|
235
248
|
writes. Without it, the bridge folder is all there is. */
|
|
236
|
-
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, inRoom = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null }) {
|
|
249
|
+
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, spoke = () => {}, inRoom = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null, screen = null, dropSecret = null, log = (line) => console.log(line) }) {
|
|
250
|
+
this.#log = log;
|
|
237
251
|
this.#terminal = terminal; this.#health = health; this.#kept = keptDir; this.#screen = screen; this.#dropSecret = dropSecret;
|
|
238
252
|
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.#spoke = spoke; this.#inRoom = inRoom; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
239
253
|
for (const s of store.all()) if (s.on === true) this.#listen(s.name);
|
|
@@ -476,17 +490,22 @@ export class Talk {
|
|
|
476
490
|
return this.of(name);
|
|
477
491
|
}
|
|
478
492
|
|
|
479
|
-
/* Types a line and Enter in the tool's terminal.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
493
|
+
/* Types a line and Enter in the tool's terminal. BY ONE COMMAND IN THE MACHINE FIRST (17-11): it
|
|
494
|
+
leaves copy mode before it types (typeCommand), which the terminal the bridge keeps open cannot --
|
|
495
|
+
bytes down it are copy-mode keys while the pane is scrolled back, and the line was lost, said
|
|
496
|
+
typed. That terminal, into the same tmux pane, when the command fails. Each line said in the log,
|
|
497
|
+
and each one lost, with why. */
|
|
483
498
|
async #type(name, line) {
|
|
499
|
+
const what = line === WAKE ? 'wake' : line === URGENT ? 'urgent' : line.length > 60 ? `${line.slice(0, 60)}...` : line;
|
|
484
500
|
await this.#warm(name);
|
|
501
|
+
const ran = await this.#vms.exec(name, typeCommand(line), { timeoutMs: 30_000 }).catch((error) => ({ code: -1, stderr: error?.message }));
|
|
502
|
+
if (ran.code === 0) { this.#ranAt.set(name, this.#now()); this.#log(`talk: ${name}: typed (${what})`); return true; }
|
|
503
|
+
const why = `exit ${ran.code}${ran.stderr ? `: ${String(ran.stderr).trim().slice(0, 200)}` : ''}`;
|
|
485
504
|
const down = this.#terminal?.open(name) ? await Promise.resolve(this.#terminal.type(name, line, ENTER_AFTER_MS)).catch(() => false) : false;
|
|
486
|
-
if (down === true) { this.#ranAt.set(name, this.#now()); return true; }
|
|
487
505
|
/* The line went, its Enter did not (the channel closed meanwhile): the Enter alone, never the line twice. */
|
|
488
|
-
const ok = (await this.#vms.exec(name,
|
|
506
|
+
const ok = down === true || (down === 'enter' && (await this.#vms.exec(name, enterCommand(), { timeoutMs: 30_000 }).catch(() => ({ code: -1 }))).code === 0);
|
|
489
507
|
if (ok) this.#ranAt.set(name, this.#now());
|
|
508
|
+
this.#log(ok ? `talk: ${name}: typed down its terminal (${what}), the command in the machine failed (${why})` : `talk: ${name}: NOT typed (${what}): ${why}; ${this.#terminal?.open(name) ? 'its terminal refused too' : 'no terminal open'}`);
|
|
490
509
|
return ok;
|
|
491
510
|
}
|
|
492
511
|
|
|
@@ -749,10 +768,10 @@ export class Talk {
|
|
|
749
768
|
this.#store.put({ ...this.#store.get(name), reread: false, renewedText: undefined });
|
|
750
769
|
return 'told';
|
|
751
770
|
}
|
|
752
|
-
if (!(await this.#type(name, this.rereadLine()).catch(() => false))) return later(RETRY_MS);
|
|
771
|
+
if (!(await this.#type(name, this.rereadLine()).catch((error) => { this.#log(`talk: ${name}: NOT typed: ${error?.message}`); return false; }))) return later(RETRY_MS);
|
|
753
772
|
/* Reading the whole thread, it reads what waits too: that line is not typed after it. */
|
|
754
773
|
const waits = this.#parley(name).unread() > 0;
|
|
755
|
-
this.#store.put({ ...this.#store.get(name), reread: false, ...(waits ? { pending: false, woke: true, why: null, again: false } : {}), typedAt: new Date(this.#now()).toISOString() });
|
|
774
|
+
this.#store.put({ ...this.#store.get(name), reread: false, ...(waits ? { pending: false, woke: true, why: null, again: false, toldRead: this.#readCount(name), renudged: 0 } : {}), typedAt: new Date(this.#now()).toISOString() });
|
|
756
775
|
return 'typed';
|
|
757
776
|
}
|
|
758
777
|
|
|
@@ -760,6 +779,12 @@ export class Talk {
|
|
|
760
779
|
/* Somebody typed in its terminal: nothing is typed over them. */
|
|
761
780
|
typed(name) { this.#typedAt.set(name, this.#now()); }
|
|
762
781
|
|
|
782
|
+
/* How far the tool has read (Parley's read.json: messages read, archived ones counted). Grows only. */
|
|
783
|
+
#readCount(name) { try { return Math.max(0, Number(JSON.parse(readFileSync(`${this.#dir(name)}/read.json`, 'utf8')).lines) || 0); } catch { return 0; } }
|
|
784
|
+
/* TOLD, THEN READ, THEN WRITTEN TO AGAIN before `woke` was put back (the tick's, every second -- or
|
|
785
|
+
never, while a tick waited on another conversation): the line typed was used, the next is owed. */
|
|
786
|
+
#readSince(name, r) { return Number.isInteger(r?.toldRead) && this.#readCount(name) > r.toldRead; }
|
|
787
|
+
|
|
763
788
|
#want(name) {
|
|
764
789
|
const r = this.#store.get(name);
|
|
765
790
|
if (r?.on === true && r.woke !== true) this.#store.put({ ...r, pending: true });
|
|
@@ -769,27 +794,28 @@ export class Talk {
|
|
|
769
794
|
'typed', 'read' (nothing waits), 'told' (typed already, not read yet),
|
|
770
795
|
'asleep', 'typing', 'failed' -- the last three wait, and are tried
|
|
771
796
|
again. `again`: the owner asked to remind it, typed before or not. */
|
|
772
|
-
#wake(name, again = false, urgent = false) {
|
|
797
|
+
#wake(name, again = false, urgent = false, renudge = false) {
|
|
773
798
|
const going = this.#trying.get(name);
|
|
774
799
|
if (going) return going;
|
|
775
|
-
const run = this.#tryWake(name, again, urgent).finally(() => this.#trying.delete(name));
|
|
800
|
+
const run = this.#tryWake(name, again, urgent, renudge).finally(() => this.#trying.delete(name));
|
|
776
801
|
this.#trying.set(name, run);
|
|
777
802
|
return run;
|
|
778
803
|
}
|
|
779
|
-
async #tryWake(name, again, urgent = false) {
|
|
804
|
+
async #tryWake(name, again, urgent = false, renudge = false) {
|
|
780
805
|
const r = this.#store.get(name);
|
|
781
806
|
if (r?.on !== true) return 'read';
|
|
782
|
-
const waits = (why, ms) => { this.#store.put({ ...this.#store.get(name), pending: true, why, again }); this.#nextTry.set(name, this.#now() + ms); return why; };
|
|
783
|
-
if (this.#parley(name).unread() === 0) { if (r.pending || r.woke) this.#store.put({ ...r, pending: false, woke: false, why: null, again: false }); return 'read'; }
|
|
807
|
+
const waits = (why, ms) => { this.#store.put({ ...this.#store.get(name), pending: true, why, again, renudge }); this.#nextTry.set(name, this.#now() + ms); return why; };
|
|
808
|
+
if (this.#parley(name).unread() === 0) { if (r.pending || r.woke) this.#store.put({ ...r, pending: false, woke: false, why: null, again: false, renudge: false }); return 'read'; }
|
|
784
809
|
/* Its machine has just restarted: the line that will be typed tells it to read everything. */
|
|
785
810
|
if (r.reread === true) { this.#store.put({ ...r, pending: true, why: 'restarting', again }); return 'restarting'; }
|
|
786
|
-
if (r.woke === true && !again) { if (r.pending) this.#store.put({ ...r, pending: false, why: null }); return 'told'; }
|
|
811
|
+
if (r.woke === true && !again && !this.#readSince(name, r)) { if (r.pending) this.#store.put({ ...r, pending: false, why: null }); return 'told'; }
|
|
787
812
|
if (!this.#conversations.awake().includes(name)) return waits('asleep', RETRY_MS);
|
|
788
813
|
const quiet = this.#now() - (this.#typedAt.get(name) ?? 0);
|
|
789
814
|
if (quiet < TYPING_QUIET_MS) return waits('typing', TYPING_QUIET_MS - quiet + 100);
|
|
790
815
|
if (!(await this.#runs(name))) return waits('asleep', RETRY_MS);
|
|
791
|
-
if (
|
|
792
|
-
|
|
816
|
+
if (renudge) this.#log(`talk: ${name}: still unread ${Math.round((this.#now() - Date.parse(r.typedAt ?? '')) / 1000)} s after its line: typed again (${(r.renudged ?? 0) + 1})`);
|
|
817
|
+
if (!(await this.#type(name, urgent ? URGENT : WAKE).catch((error) => { this.#log(`talk: ${name}: NOT typed: ${error?.message}`); return false; }))) return waits('failed', RETRY_MS);
|
|
818
|
+
this.#store.put({ ...this.#store.get(name), pending: false, woke: true, why: null, again: false, renudge: false, typedAt: new Date(this.#now()).toISOString(), toldRead: this.#readCount(name), renudged: renudge ? (r.renudged ?? 0) + 1 : 0 });
|
|
793
819
|
return 'typed';
|
|
794
820
|
}
|
|
795
821
|
|
|
@@ -801,16 +827,36 @@ export class Talk {
|
|
|
801
827
|
return { ...this.of(name), told };
|
|
802
828
|
}
|
|
803
829
|
|
|
804
|
-
|
|
830
|
+
/* NO CONVERSATION WAITS ON ANOTHER: each one's work is started, never awaited in turn -- a machine
|
|
831
|
+
that does not answer (its terminal opening, its state asked) held every conversation after it in
|
|
832
|
+
the store, ticks piling up behind, and their `woke` never put back: their next line was never
|
|
833
|
+
typed. One run at a time for each (#wake's own, and this one's for the rest). */
|
|
834
|
+
#tick() {
|
|
805
835
|
for (const r of this.#store.all()) {
|
|
806
|
-
if (
|
|
807
|
-
|
|
808
|
-
|
|
836
|
+
if (this.#ticking.has(r.name)) continue;
|
|
837
|
+
const run = this.#tickOne(r).catch(() => {}).finally(() => this.#ticking.delete(r.name));
|
|
838
|
+
this.#ticking.set(r.name, run);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
async #tickOne(r) {
|
|
842
|
+
if (r.on === true) this.#reapForgets(r);
|
|
843
|
+
if (r.on === true && r.reread === true) { await this.#tryReread(r.name); return; }
|
|
844
|
+
if (r.on !== true || (!r.pending && !r.woke)) return;
|
|
845
|
+
if (r.woke && !r.pending) {
|
|
846
|
+
let unread;
|
|
847
|
+
try { unread = this.#parley(r.name).unread(); } catch { return; /* its folder went */ }
|
|
809
848
|
/* It has read: what waited is done, and the next message wakes it again. */
|
|
810
|
-
if (
|
|
811
|
-
|
|
812
|
-
|
|
849
|
+
if (unread === 0) { this.#store.put({ ...r, woke: false }); return; }
|
|
850
|
+
/* It read since, and more was written: the line is owed now. */
|
|
851
|
+
if (this.#readSince(r.name, r)) { await this.#wake(r.name); return; }
|
|
852
|
+
/* Still unread long after: typed again, RENUDGE_MS apart, the last of them for ever after. */
|
|
853
|
+
const after = RENUDGE_MS[Math.min(r.renudged ?? 0, RENUDGE_MS.length - 1)];
|
|
854
|
+
const at = Date.parse(r.typedAt ?? '');
|
|
855
|
+
if (Number.isFinite(at) && this.#now() - at >= after && this.#now() >= (this.#nextTry.get(r.name) ?? 0)) await this.#wake(r.name, true, false, true);
|
|
856
|
+
return;
|
|
813
857
|
}
|
|
858
|
+
if (this.#now() < (this.#nextTry.get(r.name) ?? 0)) return;
|
|
859
|
+
await this.#wake(r.name, r.again === true, false, r.renudge === true);
|
|
814
860
|
}
|
|
815
861
|
|
|
816
862
|
/* The agent asked to forget short-lived secrets (parley forget -> forget.jsonl beside its thread): the
|
package/server/vm.mjs
CHANGED
|
@@ -79,6 +79,7 @@ export function runner(prefix) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/* The verbs that change a machine: its state is asked again after them. */
|
|
82
|
+
export const TRIM_MS = 120_000;
|
|
82
83
|
const CHANGES = new Set(['launch', 'clone', 'start', 'stop', 'suspend', 'kill', 'halt', 'hardstop', 'delete', 'purge', 'set', 'rename', 'restore', 'snapshot', 'revive', 'reclaim']);
|
|
83
84
|
export const STATES_FRESH_MS = 3000;
|
|
84
85
|
/* The VM manager did not say what a machine is in: not an answer about the machine. */
|
|
@@ -141,6 +142,11 @@ export class Vms {
|
|
|
141
142
|
}
|
|
142
143
|
/* In a shared machine: its machine-wide work, as its admin user, never through a door (the door itself installed). */
|
|
143
144
|
execMachine(conversation, argv, options) { return this.run(['vm', 'exec', this.vmOf(conversation), '--', ...argv], options); }
|
|
145
|
+
/* ITS DISK GIVES BACK WHAT WAS ERASED (17-11): the system inside tells the disk which blocks are free
|
|
146
|
+
(fstrim; the VM manager's disks take it, discard=unmap), and the disk file on the host shrinks to what
|
|
147
|
+
is really used. Ubuntu does it once a week by itself; asked here every hour and before each stop or
|
|
148
|
+
sleep. A second one is quick: only what changed since is looked at. */
|
|
149
|
+
trim(conversation, timeoutMs = TRIM_MS) { return this.execMachine(conversation, ['sudo', '-n', 'fstrim', '--all'], { timeoutMs }); }
|
|
144
150
|
/* The host's list of who lives in a shared machine (vm share / unshare). */
|
|
145
151
|
share(conversation) { return this.run(['vm', 'share', this.vmOf(conversation), conversation]); }
|
|
146
152
|
unshare(conversation) { return this.run(['vm', 'unshare', this.vmOf(conversation), conversation]); }
|