clavarium 0.2.12 → 0.2.13-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.
@@ -17,4 +17,13 @@ esac
17
17
  [ $# -gt 0 ] || { echo "launch: no command to run" >&2; exit 64; }
18
18
  node "$(dirname "$0")/json-set.mjs" .claude/settings.json "$keys" \
19
19
  || echo "launch: the settings of Claude Code were not changed: it may ask before acting" >&2
20
+ # PARLEY AS ITS OWN TOOLS (MCP): the chat of the conversation, when it has one (its folder holds
21
+ # Parley's server), given to Claude Code as tools always in its list -- the same as the command
22
+ # "parley", which stays. Declared once, by Claude Code itself (its other servers kept); looked for
23
+ # in its settings first, since asking Claude Code takes seconds. Nothing stops the start.
24
+ chat="${PARLEY_DIR:-/work/.parley}"
25
+ if [ -f "$chat/server.mjs" ] && ! grep -q "\"$chat/server.mjs\"" "$HOME/.claude.json" 2>/dev/null; then
26
+ claude mcp add --scope user parley -- node "$chat/server.mjs" --dir "$chat" >/dev/null 2>&1 \
27
+ || echo "launch: Parley was not given to Claude Code as tools: the command parley still works" >&2
28
+ fi
20
29
  exec "$@"
@@ -699,6 +699,41 @@ case "$AREA $VERB" in
699
699
  if [ "$SAY" = "yes" ]; then echo "lsblk -J -b -o NAME,PATH,TYPE,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINT,MODEL,RO,RM,PKNAME,TRAN"; exit 0; fi
700
700
  lsblk -J -b -o NAME,PATH,TYPE,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINT,MODEL,RO,RM,PKNAME,TRAN
701
701
  exit 0 ;;
702
+ "disks room")
703
+ # ROOM SET ASIDE AND NOT USED: a file system on a logical volume (LVM) whose group still has
704
+ # free space -- often the system's, made small at installation. Read-only.
705
+ # lvroom <mount point> <volume> <group> <free MB> <file system>
706
+ [ $# -eq 0 ] || usage
707
+ if [ "$SAY" = "yes" ]; then echo "findmnt; lvs; vgs (read-only)"; exit 0; fi
708
+ command -v lvs >/dev/null 2>&1 || exit 0
709
+ for at in / $(findmnt -rn -o TARGET | grep -E '^/(mnt|media)/[A-Za-z0-9/._-]+$|^/home$' || true); do
710
+ # (Most mounts are no logical volume: under pipefail, a refusal of lvs must not stop this program.)
711
+ src="$(findmnt -nvo SOURCE -- "$at" 2>/dev/null || true)"; [ -n "$src" ] || continue
712
+ fs="$(findmnt -nvo FSTYPE -- "$at" 2>/dev/null || true)"
713
+ vg="$( { lvs --noheadings -o vg_name -- "$src" 2>/dev/null || true; } | tr -d ' ')"
714
+ [ -n "$vg" ] || continue
715
+ free="$( { vgs --noheadings --units m --nosuffix -o vg_free -- "$vg" 2>/dev/null || true; } | tr -d ' ' | cut -d. -f1)"
716
+ [[ "$free" =~ ^[0-9]+$ ]] || continue
717
+ printf 'lvroom %s %s %s %s %s\n' "$at" "$src" "$vg" "$free" "$fs"
718
+ done
719
+ exit 0 ;;
720
+ "disks grow")
721
+ # THAT ROOM GIVEN TO THE FILE SYSTEM, while it is in use (lvextend -r): the system's ("/"),
722
+ # or one under /mnt, /media, /home. Nothing on it is erased. Only ext4 and xfs.
723
+ [ $# -eq 1 ] || usage
724
+ case "$1" in /|/mnt/?*|/media/?*|/home) : ;; *) refuse "not a place that may be grown here: $1" ;; esac
725
+ [[ "$1" =~ ^/[A-Za-z0-9/._-]*$ ]] && [[ "$1" != *..* ]] || refuse "not a plain path: $1"
726
+ if [ "$SAY" = "yes" ]; then echo "lvextend -r -l +100%FREE <the volume of $1>"; exit 0; fi
727
+ mountpoint -q -- "$1" || refuse "nothing is mounted at $1"
728
+ src="$(findmnt -nvo SOURCE -- "$1")"; fs="$(findmnt -nvo FSTYPE -- "$1")"
729
+ case "$fs" in ext4|xfs) : ;; *) refuse "$1 holds $fs: only ext4 and xfs are grown here" ;; esac
730
+ vg="$( { lvs --noheadings -o vg_name -- "$src" 2>/dev/null || true; } | tr -d ' ')"
731
+ [ -n "$vg" ] || refuse "$1 is not on a logical volume: nothing set aside to give it"
732
+ free="$( { vgs --noheadings --units m --nosuffix -o vg_free -- "$vg" 2>/dev/null || true; } | tr -d ' ' | cut -d. -f1)"
733
+ [ "${free:-0}" -ge 1024 ] || refuse "less than 1 GB set aside in $vg: nothing worth giving"
734
+ lvextend -q -r -l +100%FREE -- "$src" >/dev/null 2>&1 || refuse "the volume of $1 could not be grown"
735
+ printf 'grown %s %s\n' "$1" "$(df -Pm -- "$1" | awk 'NR==2 {print $2}')"
736
+ exit 0 ;;
702
737
  "disks mount")
703
738
  # A DISK (or a partition) THAT HOLDS A FILE SYSTEM, mounted under /mnt
704
739
  # for good (/etc/fstab, by its UUID, "nofail": the server starts without
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.12",
3
+ "version": "0.2.13-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.12",
9
+ "version": "0.2.13-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.12",
3
+ "version": "0.2.13-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.",
package/server/api.mjs CHANGED
@@ -70,6 +70,7 @@
70
70
  * GET /api/conversations/<name>/health-react POST the same {on?, message?, command?}: what it does when its machine is short
71
71
  * GET /api/machines/places GET /api/machines/moving POST /api/machines/move {to}: all the machines to another disk
72
72
  * POST /api/machines/forget-old: the copy a move left behind, removed
73
+ * POST /api/machines/grow {mount}: room set aside and unused, given to that file system
73
74
  * GET /api/machines/disks: every disk, whole POST /api/machines/mount {path} POST /api/machines/prepare {path, typed}: erased
74
75
  * GET /api/events?kind=&conversation=&q=&before=&limit= what happened, newest first
75
76
  * GET /api/history?of=server|<name>&span=1h|24h|7d the curves of memory, CPU and disk (and the reserve, for the server)
@@ -385,6 +386,7 @@ export async function handleApi(request, response, conversations, headers, resou
385
386
  if (reactSet && reacting) { const n = decodeURIComponent(reactSet[1]); if (!conversations.list().some((c) => c.name === n)) throw new Refusal(404, 'No such conversation.'); return send(200, reacting.set(n, body)), true; }
386
387
  if (pathname === '/api/machines/move' && machinesMove) return send(202, await machinesMove.move(String(body.to ?? ''))), true;
387
388
  if (pathname === '/api/server/restart' && serverLogs) return send(202, await serverLogs.restart()), true;
389
+ if (pathname === '/api/machines/grow' && machinesMove) return send(200, await machinesMove.grow(String(body.mount ?? ''))), true;
388
390
  if (pathname === '/api/machines/mount' && machinesMove) return send(200, await machinesMove.mount(String(body.path ?? ''))), true;
389
391
  if (pathname === '/api/machines/prepare' && machinesMove) return send(200, await machinesMove.prepare(String(body.path ?? ''), body.typed)), true;
390
392
  if (pathname === '/api/machines/forget-old' && machinesMove) return send(200, await machinesMove.forgetOld()), true;
package/server/events.mjs CHANGED
@@ -51,6 +51,7 @@ const SAID = [
51
51
  [/^\/api\/server\/reserve$/, 'server', (m, b) => `Reserve set${b.diskMb !== undefined ? `: disk ${b.diskMb} MB` : ''}${b.memoryMb !== undefined ? `, memory ${b.memoryMb} MB` : ''}`],
52
52
  [/^\/api\/machines\/move$/, 'server', (m, b) => `All the machines moved to ${clip(b.to, 60)}`],
53
53
  [/^\/api\/machines\/prepare$/, 'server', (m, b) => `Disk ${clip(b.path, 40)} erased and prepared for the machines`],
54
+ [/^\/api\/machines\/grow$/, 'server', (m, b, a) => `${clip(b.mount, 60)} grown with the room set aside on its disk${a?.sizeMb ? `: now ${Math.round(a.sizeMb / 1024)} GB` : ''}`],
54
55
  [/^\/api\/machines\/mount$/, 'server', (m, b) => `Disk ${clip(b.path, 40)} mounted`],
55
56
  [/^\/api\/machines\/forget-old$/, 'server', () => 'The old copy of the machines removed'],
56
57
  [/^\/api\/instance$/, 'server', (m, b) => (String(b.name ?? '').trim() ? `This Clavarium named "${clip(b.name, 40)}"` : 'This Clavarium given back the name drawn from its address')],
@@ -11,6 +11,8 @@
11
11
  * disks() the disks of this server, WHOLE, formatted or not (lsblk): for each,
12
12
  * what can be done -- move the machines to one of its file systems,
13
13
  * mount one, or prepare (erase) the disk; and why not
14
+ * grow(mount) room set aside in a logical volume's group and not used, given to the
15
+ * file system at `mount` while in use (disks() says it: unused, by disk)
14
16
  * mount(path) / prepare(path, typed) a file system mounted under /mnt for good;
15
17
  * a whole disk erased, one ext4 on it, mounted (its name typed again)
16
18
  */
@@ -31,6 +33,16 @@ function aDisk(d) {
31
33
  if (d.type === 'loop') return FILE_SYSTEMS.includes(d.fstype) && /^\/(mnt|media)\//.test(d.mountpoint ?? '');
32
34
  return d.type === 'disk' && MB(d.size) >= 4096;
33
35
  }
36
+ /* "disks room": [{ mount, volume, group, freeMb, fs }], only lines of the expected shape. */
37
+ export function readRooms(text) {
38
+ const out = [];
39
+ for (const line of String(text ?? '').split('\n').slice(0, 50)) {
40
+ const p = line.trim().split(' ');
41
+ if (p[0] !== 'lvroom' || p.length !== 6 || !/^\/[A-Za-z0-9/._-]*$/.test(p[1]) || !/^\d+$/.test(p[4])) continue;
42
+ out.push({ mount: p[1], volume: p[2], group: p[3], freeMb: Number(p[4]), fs: p[5] });
43
+ }
44
+ return out;
45
+ }
34
46
  /* lsblk -J (deploy/clavarium-host, "disks list") as the page needs it. */
35
47
  export function readDisks(json) {
36
48
  let all;
@@ -97,9 +109,15 @@ export class MachinesMove {
97
109
  return { removed: true };
98
110
  }
99
111
  async disks() {
100
- const [r, places] = await Promise.all([this.#host(['disks', 'list']), this.places().catch(() => null)]);
112
+ const [r, places, room] = await Promise.all([this.#host(['disks', 'list']), this.places().catch(() => null), this.#host(['disks', 'room']).catch(() => ({ code: 1 }))]);
101
113
  if (r.code !== 0) throw new Refusal(502, `The disks could not be listed: ${firstLine(r.stderr) || `exit ${r.code}`}`);
102
114
  const disks = readDisks(r.stdout);
115
+ /* Room set aside and not used (a logical volume made small at installation): said on its disk, offered. */
116
+ const rooms = room.code === 0 ? readRooms(room.stdout) : [];
117
+ for (const d of disks) {
118
+ const mounts = d.parts.map((p) => p.mount).filter(Boolean);
119
+ d.unused = rooms.filter((x) => mounts.includes(x.mount) || (d.system && x.mount === '/'));
120
+ }
103
121
  const now = places?.now?.place ?? null;
104
122
  for (const d of disks) for (const p of d.parts) {
105
123
  const at = places?.places.find((x) => x.at === p.mount);
@@ -110,6 +128,17 @@ export class MachinesMove {
110
128
  disks.sort((a, b) => Number(b.parts.some((p) => p.machines)) - Number(a.parts.some((p) => p.machines)) || b.sizeMb - a.sizeMb);
111
129
  return { disks, needMb: places?.needMb ?? null, now };
112
130
  }
131
+ /* That room given to the file system mounted at `mount`, while in use. */
132
+ async grow(mount) {
133
+ const { disks } = await this.disks();
134
+ const x = disks.flatMap((d) => d.unused).find((u) => u.mount === mount);
135
+ if (!x) throw new Refusal(404, 'There is no room set aside for that place.');
136
+ if (x.freeMb < 1024) throw new Refusal(409, 'Less than 1 GB is set aside there: nothing worth giving.');
137
+ const r = await this.#host(['disks', 'grow', mount], { timeoutMs: 600_000 });
138
+ if (r.code !== 0) throw new Refusal(r.code === 78 ? 409 : 502, firstLine(r.stderr) || `exit ${r.code}`);
139
+ const m = /^grown (\S+) (\d+)$/m.exec(String(r.stdout ?? ''));
140
+ return { grown: mount, sizeMb: m ? Number(m[2]) : null };
141
+ }
113
142
  async mount(path) {
114
143
  const { disks } = await this.disks();
115
144
  const p = disks.flatMap((d) => d.parts).find((x) => x.path === path);
package/web/app.js CHANGED
@@ -3828,6 +3828,19 @@
3828
3828
  }
3829
3829
  card.append(line);
3830
3830
  }
3831
+ /* ROOM SET ASIDE AND NOT USED (a volume made small at installation): given to it, while in use. */
3832
+ for (const u of (d.unused ?? []).filter((x) => x.freeMb >= 1024)) {
3833
+ const box = el('div', 'disk-room');
3834
+ const where = u.mount === '/' ? 'the system (and the machines on it)' : u.mount;
3835
+ box.append(el('p', '', `${size(u.freeMb)} of this disk is set aside but not used. It can be given to ${where}, while it runs: nothing is erased.`));
3836
+ const go = el('button', 'primary', `Give ${size(u.freeMb)} to ${u.mount === '/' ? 'the system' : u.mount}...`); go.type = 'button';
3837
+ go.addEventListener('click', () => {
3838
+ if (go.dataset.sure !== 'yes') { go.dataset.sure = 'yes'; go.textContent = `Yes: grow ${u.mount} by ${size(u.freeMb)}`; return; }
3839
+ go.disabled = true; said(`Growing ${u.mount}...`);
3840
+ void post(`${API}/machines/grow`, { mount: u.mount }).then((r) => { said(`${u.mount} has grown${r.sizeMb ? `: ${size(r.sizeMb)} now` : ''}.`); void paintMoveMachines(); void paintServer(); }).catch((error) => { said(error.message); go.disabled = false; });
3841
+ });
3842
+ box.append(go); card.append(box);
3843
+ }
3831
3844
  /* PREPARE: erase it, one file system on it, mounted. Its name typed again. */
3832
3845
  if (!d.prepare) {
3833
3846
  const box = el('div', 'disk-prepare');
package/web/style.css CHANGED
@@ -1369,3 +1369,5 @@ select.pill { appearance: auto; }
1369
1369
  button.inline.more-recent { text-decoration: none; }
1370
1370
  /* Marked seen: said, not offered again. */
1371
1371
  .parley-act[data-act="seen-done"] { color: var(--ok); border-color: transparent; background: transparent; cursor: default; opacity: .85; }
1372
+ .disk-room { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px 10px; border: 1px solid color-mix(in srgb, var(--ok) 50%, transparent); border-radius: 8px; }
1373
+ .disk-room p { margin: 0; }