clavarium 0.2.183-next.1 → 0.2.184-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/README.md +4 -0
- package/config/launch/claude-code.sh +36 -19
- package/config/launch/codex.sh +36 -0
- package/config/launch/json-set.mjs +5 -2
- package/config/launch/mcp-relay.mjs +98 -0
- package/config/launch/screen-watch.mjs +99 -0
- package/config/launch/toml-block.mjs +26 -0
- package/config/launch/vibe.sh +39 -0
- package/config/tools.json +57 -0
- package/deploy/clavarium-host +84 -2
- package/deploy/install.sh +10 -3
- package/deploy/maintenance.html +5 -2
- package/deploy/updater.mjs +70 -3
- package/npm-shrinkwrap.json +245 -19
- package/package.json +8 -6
- package/server/accounts.mjs +2 -1
- package/server/api.mjs +257 -28
- package/server/apikeys.mjs +952 -0
- package/server/boxcollect.mjs +276 -0
- package/server/boxes.mjs +779 -26
- package/server/capacity.mjs +3 -1
- package/server/catalog.mjs +48 -0
- package/server/conversations.mjs +41 -5
- package/server/demandes.mjs +200 -0
- package/server/devices.mjs +1 -0
- package/server/dictation-engines.mjs +91 -0
- package/server/door.mjs +16 -3
- package/server/events.mjs +1 -0
- package/server/features.mjs +366 -0
- package/server/files.mjs +57 -6
- package/server/gitpush.mjs +170 -53
- package/server/grants.mjs +43 -11
- package/server/guide.mjs +5 -1
- package/server/health.mjs +41 -4
- package/server/linkguard.mjs +191 -0
- package/server/mailbox.mjs +9 -0
- package/server/mailref.mjs +90 -0
- package/server/main.mjs +194 -22
- package/server/mcpx.mjs +154 -0
- package/server/network.mjs +121 -13
- package/server/pocket.mjs +136 -0
- package/server/resources.mjs +6 -0
- package/server/rooms.mjs +462 -0
- package/server/serverlogs.mjs +6 -0
- package/server/settingswords.mjs +185 -0
- package/server/speech.mjs +47 -4
- package/server/spoken.mjs +60 -0
- package/server/suggest.mjs +66 -0
- package/server/talk.mjs +84 -24
- package/server/tethers.mjs +162 -10
- package/server/vm.mjs +2 -0
- package/server/voice.mjs +254 -46
- package/server/wakelearn.mjs +214 -0
- package/web/app.js +3318 -913
- package/web/device.html +2 -0
- package/web/features.js +480 -0
- package/web/index.html +690 -493
- package/web/kit.js +953 -0
- package/web/links.js +2 -2
- package/web/mail-view.js +386 -0
- package/web/manifest.webmanifest +4 -0
- package/web/style.css +1105 -238
- package/web/voice-core.js +25 -0
- package/web/voice.js +9 -3
package/README.md
CHANGED
|
@@ -301,3 +301,7 @@ Without a guard, nothing commits. That is on purpose.
|
|
|
301
301
|
## Licence
|
|
302
302
|
|
|
303
303
|
MIT. See `LICENSE`.
|
|
304
|
+
|
|
305
|
+
## Credits
|
|
306
|
+
|
|
307
|
+
The voice boxes speak with **Pocket TTS** by **Kyutai** (program MIT, weights CC-BY-4.0), fetched at run time; Piper voices (sherpa-onnx) are the fallback. See CREDITS.md in the repository.
|
|
@@ -17,33 +17,50 @@ 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
|
-
#
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# ITS FIRST QUESTIONS ANSWERED BEFORE THEY ARE ASKED (02-11): the welcome (theme, tips) taken as seen, and its
|
|
21
|
+
# work folder trusted -- in its own file, as it records them itself; nothing to answer in the terminal.
|
|
22
|
+
node "$(dirname "$0")/json-set.mjs" .claude.json '{"hasCompletedOnboarding": true, "projects": {"/work": {"hasTrustDialogAccepted": true}}}' \
|
|
23
|
+
|| echo "launch: Claude Code may ask its first questions in the terminal" >&2
|
|
24
|
+
# ITS TOOLS (MCP), EACH THROUGH THE RELAY (02-11): a tool updated on the machine is taken up between two of
|
|
25
|
+
# its requests -- whatever the tool, the session never restarted, nothing for the agent to do. Declared
|
|
26
|
+
# once, by Claude Code itself (its other servers kept); an older declaration without the relay is replaced.
|
|
27
|
+
# Looked for in its settings first, since asking Claude Code takes seconds. Nothing stops the start.
|
|
28
|
+
relay="$(dirname "$0")/mcp-relay.mjs"
|
|
29
|
+
tool() { # NAME FOLDER COMMAND ARGS...
|
|
30
|
+
name="$1"; folder="$2"; shift 2
|
|
31
|
+
if grep -q "\"$folder\"" "$HOME/.claude.json" 2>/dev/null && grep -q "mcp-relay.mjs" "$HOME/.claude.json" 2>/dev/null \
|
|
32
|
+
&& node -e 'const d=require(process.argv[1]);const s=d.mcpServers?.[process.argv[2]];const a=JSON.stringify(s?.args??[]);process.exit(a.includes("mcp-relay.mjs")&&a.includes(JSON.stringify(process.argv[3]))?0:1)' "$HOME/.claude.json" "$name" "$1" 2>/dev/null; then return 0; fi
|
|
33
|
+
claude mcp remove --scope user "$name" >/dev/null 2>&1
|
|
34
|
+
claude mcp add --scope user "$name" -- node "$relay" "$@" >/dev/null 2>&1 \
|
|
35
|
+
|| echo "launch: $name was not given to Claude Code as tools: the command $name still works" >&2
|
|
36
|
+
}
|
|
37
|
+
# Parley, the chat of the conversation, when it has one: the version installed on the machine (parley-mcp),
|
|
38
|
+
# else the copy beside the chat.
|
|
24
39
|
chat="${PARLEY_DIR:-/work/.parley}"
|
|
25
|
-
if [ -f "$chat/server.mjs" ]
|
|
26
|
-
|
|
27
|
-
|| echo "launch: Parley was not given to Claude Code as tools: the command parley still works" >&2
|
|
40
|
+
if [ -f "$chat/server.mjs" ]; then
|
|
41
|
+
if command -v parley-mcp >/dev/null 2>&1; then tool parley "$chat" parley-mcp --dir "$chat"; else tool parley "$chat" node "$chat/server.mjs" --dir "$chat"; fi
|
|
28
42
|
fi
|
|
29
|
-
#
|
|
30
|
-
# reminders it sets itself. The same as the command "docket", installed in every machine.
|
|
43
|
+
# Its docket, with its chat: what woke it, to say done or failed; the reminders it sets itself.
|
|
31
44
|
docket="/work/.docket"
|
|
32
|
-
if [ -f "$chat/server.mjs" ] && command -v docket-mcp >/dev/null 2>&1
|
|
33
|
-
|
|
34
|
-
|| echo "launch: Docket was not given to Claude Code as tools: the command docket still works" >&2
|
|
35
|
-
fi
|
|
36
|
-
# ITS TETHER AS ITS OWN TOOLS (MCP): the accesses it was given -- a mailbox, a calendar, an address
|
|
37
|
-
# book, an online folder, a machine over SSH. The server holds the keys; it acts within its rights.
|
|
45
|
+
if [ -f "$chat/server.mjs" ] && command -v docket-mcp >/dev/null 2>&1; then tool docket "$docket" docket-mcp --dir "$docket"; fi
|
|
46
|
+
# Its tether: the accesses it was given (a mailbox, a calendar, a folder, a machine over SSH).
|
|
38
47
|
tether="/work/.tether"
|
|
39
|
-
if command -v tether-mcp >/dev/null 2>&1
|
|
40
|
-
claude mcp add --scope user tether -- tether-mcp --dir "$tether" >/dev/null 2>&1 \
|
|
41
|
-
|| echo "launch: Tether was not given to Claude Code as tools: the command tether still works" >&2
|
|
42
|
-
fi
|
|
48
|
+
if command -v tether-mcp >/dev/null 2>&1; then tool tether "$tether" tether-mcp --dir "$tether"; fi
|
|
43
49
|
# ITS PULSE: Claude Code's own hooks say to the chat that it acts, and when its turn ends, so that
|
|
44
50
|
# the person sees "Working..." while it works without a word (parley pulse; nothing posted).
|
|
45
51
|
if [ -f "$chat/server.mjs" ]; then
|
|
46
52
|
node "$(dirname "$0")/claude-pulse.mjs" "$chat" \
|
|
47
53
|
|| echo "launch: the chat will not say when Claude Code works without a word" >&2
|
|
48
54
|
fi
|
|
55
|
+
# WHAT ITS SCREEN ASKS (02-11), read by the generic screen-watch -- Claude Code's own words, here and only
|
|
56
|
+
# here: not signed in, its sign-in started by itself, its link sent to the person's chat, the code they paste
|
|
57
|
+
# there typed back (02-11, tried on a real Claude Code); an update installed told to the agent, which restarts
|
|
58
|
+
# when it suits it (never in the middle of its work). A tool that changes its words: only these lines change.
|
|
59
|
+
node "$(dirname "$0")/screen-watch.mjs" \
|
|
60
|
+
'type:Not logged in · Run /login=/login' \
|
|
61
|
+
'keys:Select login method:=Enter' \
|
|
62
|
+
'link:https://(claude\.ai|claude\.com|console\.anthropic\.com)/\S*oauth\S*' \
|
|
63
|
+
'code:Paste code here' \
|
|
64
|
+
'notice:(update|updated|installed)[^\n]{0,80}restart=Your tool was updated: when nothing runs, touch /work/.parley/restart-asked to take it up.' \
|
|
65
|
+
</dev/null >/dev/null 2>&1 &
|
|
49
66
|
exec "$@"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# THE LAUNCHER OF CODEX (OpenAI), run by Clavarium in its machine at each start (config/tools.json,
|
|
3
|
+
# "launch"), from the read-only /tools. Arguments: the rights chosen by the owner (full, ask), then the
|
|
4
|
+
# command to run, as Clavarium made it. All that is Codex's own is here, and only here (02-11).
|
|
5
|
+
mode="$1"; shift
|
|
6
|
+
case "$mode" in full|ask) ;; *) echo "launch: the first argument is full or ask" >&2; exit 64 ;; esac
|
|
7
|
+
[ $# -gt 0 ] || { echo "launch: no command to run" >&2; exit 64; }
|
|
8
|
+
here="$(dirname "$0")"; relay="$here/mcp-relay.mjs"
|
|
9
|
+
chat="${PARLEY_DIR:-/work/.parley}"; docket="/work/.docket"; tether="/work/.tether"
|
|
10
|
+
# ITS SETTINGS (~/.codex/config.toml), in a block of their own, the rest kept: its work folder trusted (no
|
|
11
|
+
# question at its first start), and its tools (MCP) each through the relay -- a tool updated on the
|
|
12
|
+
# machine taken up between two requests, never a restart.
|
|
13
|
+
block='[projects."/work"]
|
|
14
|
+
trust_level = "trusted"'
|
|
15
|
+
if [ -f "$chat/server.mjs" ] && command -v parley-mcp >/dev/null 2>&1; then block="$block
|
|
16
|
+
[mcp_servers.parley]
|
|
17
|
+
command = \"node\"
|
|
18
|
+
args = [\"$relay\", \"parley-mcp\", \"--dir\", \"$chat\"]"; fi
|
|
19
|
+
if [ -f "$chat/server.mjs" ] && command -v docket-mcp >/dev/null 2>&1; then block="$block
|
|
20
|
+
[mcp_servers.docket]
|
|
21
|
+
command = \"node\"
|
|
22
|
+
args = [\"$relay\", \"docket-mcp\", \"--dir\", \"$docket\"]"; fi
|
|
23
|
+
if command -v tether-mcp >/dev/null 2>&1; then block="$block
|
|
24
|
+
[mcp_servers.tether]
|
|
25
|
+
command = \"node\"
|
|
26
|
+
args = [\"$relay\", \"tether-mcp\", \"--dir\", \"$tether\"]"; fi
|
|
27
|
+
node "$here/toml-block.mjs" .codex/config.toml tools "$block" \
|
|
28
|
+
|| echo "launch: Codex may ask its first questions, and has not its tools (MCP)" >&2
|
|
29
|
+
# WHAT ITS SCREEN ASKS, read by the generic screen-watch -- Codex's own words: its sign-in link (and the
|
|
30
|
+
# code beside it) sent to the person's chat; an update told to the agent, which restarts when it suits it.
|
|
31
|
+
node "$here/screen-watch.mjs" \
|
|
32
|
+
'link:https://auth\.openai\.com/\S+' \
|
|
33
|
+
'link:https://chatgpt\.com/\S*auth\S*' \
|
|
34
|
+
'notice:update available[^\n]{0,120}=Your tool has an update: when nothing runs, touch /work/.parley/restart-asked to take it up.' \
|
|
35
|
+
</dev/null >/dev/null 2>&1 &
|
|
36
|
+
exec "$@"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* json-set FILE KEYS: sets KEYS (a JSON object; null takes a key out) in the
|
|
2
|
-
* JSON file FILE of the home, every other key kept
|
|
2
|
+
* JSON file FILE of the home, every other key kept -- inside objects too (02-11:
|
|
3
|
+
* {"projects": {"/work": {...}}} keeps the other projects and their other keys). Written only when it
|
|
3
4
|
* changes, readable by its owner alone. A file that is not a JSON object is
|
|
4
5
|
* not touched (exit 3): a person's settings are never overwritten by a guess.
|
|
5
6
|
*
|
|
@@ -21,7 +22,9 @@ try { data = JSON.parse(readFileSync(at, 'utf8')); } catch (error) {
|
|
|
21
22
|
}
|
|
22
23
|
if (!data || typeof data !== 'object' || Array.isArray(data)) { console.error(`json-set: ${file} is not a JSON object: left as it is`); process.exit(3); }
|
|
23
24
|
const was = JSON.stringify(data);
|
|
24
|
-
|
|
25
|
+
const plain = (v) => v && typeof v === 'object' && !Array.isArray(v);
|
|
26
|
+
const merge = (into, from) => { for (const [k, v] of Object.entries(from)) { if (v === null) delete into[k]; else if (plain(v) && plain(into[k])) merge(into[k], v); else into[k] = v; } };
|
|
27
|
+
merge(data, keys);
|
|
25
28
|
if (JSON.stringify(data) !== was) {
|
|
26
29
|
mkdirSync(dirname(at), { recursive: true, mode: 0o700 });
|
|
27
30
|
writeFileSync(`${at}.new`, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* TAKEN UP WITHOUT A RESTART (02-11), FOR EVERY TOOL OF EVERY CONVERSATION: the launcher gives Claude Code
|
|
2
|
+
* each MCP server through this relay -- `node mcp-relay.mjs COMMAND ARGS...` -- so a tool updated on the
|
|
3
|
+
* machine is taken up between two requests, whatever the tool, with nothing for the agent to do. Its
|
|
4
|
+
* version is the package.json of the package its command comes from.
|
|
5
|
+
*
|
|
6
|
+
* (Below, the relay as each Clavarium tool also carries it.)
|
|
7
|
+
* An MCP server lives as long as the session that started it: a new
|
|
8
|
+
* version installed under it was not seen until the session itself was restarted ("on ne peut pas mettre à
|
|
9
|
+
* jour un composant sans redémarrer la session ?"). So the server runs as a child of this relay; between two
|
|
10
|
+
* requests, when the version installed on disk is no longer the child's, the relay starts the new one, says
|
|
11
|
+
* hello to it as the session did, and tells the session its tools may have changed. Nothing is lost: a
|
|
12
|
+
* request in flight is answered by the child it went to, the next goes to the new one. */
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
import { createInterface } from 'node:readline';
|
|
16
|
+
|
|
17
|
+
/* -> the version installed now, read from package.json (null if unreadable: keep the child). */
|
|
18
|
+
export const installedVersion = (packageJson) => { try { return String(JSON.parse(readFileSync(packageJson, 'utf8')).version ?? '') || null; } catch { return null; } };
|
|
19
|
+
|
|
20
|
+
export function relay({ command = process.execPath, args, packageJson, input = process.stdin, output = process.stdout, spawner = spawn, version = installedVersion, log = () => {} }) {
|
|
21
|
+
let child = null; let running = null; let hello = null; let helloDone = false;
|
|
22
|
+
const pending = new Set(); const queue = [];
|
|
23
|
+
const send = (m) => output.write(`${JSON.stringify(m)}\n`);
|
|
24
|
+
const start = () => {
|
|
25
|
+
running = version(packageJson);
|
|
26
|
+
const c = spawner(command, args, { stdio: ['pipe', 'pipe', 'inherit'], env: { ...process.env, MCP_RELAYED: '1' } });
|
|
27
|
+
child = c;
|
|
28
|
+
createInterface({ input: c.stdout }).on('line', (line) => {
|
|
29
|
+
let m; try { m = JSON.parse(line); } catch { return; }
|
|
30
|
+
if (m && typeof m.id === 'string' && m.id.startsWith('relay:')) return; /* its answer to our own hello */
|
|
31
|
+
if (m && m.id !== undefined) pending.delete(m.id);
|
|
32
|
+
output.write(`${line}\n`);
|
|
33
|
+
if (pending.size === 0) flush();
|
|
34
|
+
});
|
|
35
|
+
c.on('exit', () => {
|
|
36
|
+
if (child !== c) return;
|
|
37
|
+
child = null;
|
|
38
|
+
/* It stopped under a request: answered, never left waiting; the next one starts it again. */
|
|
39
|
+
for (const id of pending) send({ jsonrpc: '2.0', id, error: { code: -32603, message: 'The tool stopped; try again.' } });
|
|
40
|
+
pending.clear(); flush();
|
|
41
|
+
});
|
|
42
|
+
return c;
|
|
43
|
+
};
|
|
44
|
+
const greet = (c) => {
|
|
45
|
+
if (!hello) return;
|
|
46
|
+
c.stdin.write(`${JSON.stringify({ ...hello, id: `relay:${Date.now()}` })}\n`);
|
|
47
|
+
c.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' })}\n`);
|
|
48
|
+
};
|
|
49
|
+
/* Between requests: the new version if there is one (once nothing is in flight), then what waited. */
|
|
50
|
+
const needsNew = () => { if (!child) return true; if (!helloDone) return false; const now = version(packageJson); return Boolean(now && now !== running); };
|
|
51
|
+
const flush = () => {
|
|
52
|
+
while (queue.length) {
|
|
53
|
+
if (needsNew()) {
|
|
54
|
+
if (pending.size > 0) return;
|
|
55
|
+
const old = child; const was = running;
|
|
56
|
+
const c = start(); greet(c);
|
|
57
|
+
log(`relay: ${was} -> ${running}`);
|
|
58
|
+
try { old?.stdin.end(); old?.kill(); } catch { /* gone already */ }
|
|
59
|
+
if (helloDone) send({ jsonrpc: '2.0', method: 'notifications/tools/list_changed' });
|
|
60
|
+
}
|
|
61
|
+
const m = queue.shift();
|
|
62
|
+
if (m.id !== undefined) pending.add(m.id);
|
|
63
|
+
child.stdin.write(`${JSON.stringify(m)}\n`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
start();
|
|
67
|
+
createInterface({ input }).on('line', (line) => {
|
|
68
|
+
let m; try { m = JSON.parse(line); } catch { return; }
|
|
69
|
+
if (!m || typeof m !== 'object') return;
|
|
70
|
+
if (m.method === 'initialize') { hello = m; }
|
|
71
|
+
if (m.method === 'notifications/initialized') helloDone = true;
|
|
72
|
+
queue.push(m);
|
|
73
|
+
flush();
|
|
74
|
+
});
|
|
75
|
+
input.on('end', () => { try { child?.stdin.end(); } catch { /* gone */ } });
|
|
76
|
+
return { get child() { return child; }, get version() { return running; } };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* The package a command comes from: its file followed to the end of its links, then up to a package.json. */
|
|
80
|
+
import { realpathSync, existsSync, statSync } from 'node:fs';
|
|
81
|
+
import { delimiter, dirname, join, isAbsolute } from 'node:path';
|
|
82
|
+
import { fileURLToPath } from 'node:url';
|
|
83
|
+
export function packageOf(command, path = process.env.PATH ?? '') {
|
|
84
|
+
const found = isAbsolute(command) ? command : path.split(delimiter).map((d) => join(d, command)).find((f) => { try { return statSync(f).isFile(); } catch { return false; } });
|
|
85
|
+
if (!found) return null;
|
|
86
|
+
let at; try { at = dirname(realpathSync(found)); } catch { return null; }
|
|
87
|
+
for (let i = 0; i < 6; i++) { if (existsSync(join(at, 'package.json'))) return join(at, 'package.json'); const up = dirname(at); if (up === at) break; at = up; }
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const HERE = fileURLToPath(import.meta.url);
|
|
91
|
+
const main = (() => { try { return realpathSync(process.argv[1] ?? '') === realpathSync(HERE); } catch { return false; } })();
|
|
92
|
+
if (main) {
|
|
93
|
+
const [command, ...args] = process.argv.slice(2);
|
|
94
|
+
if (!command) { process.stderr.write('mcp-relay: COMMAND [ARGS...]\n'); process.exit(64); }
|
|
95
|
+
/* A node script given by its path (node /x/server.mjs): its package is that of the script. */
|
|
96
|
+
const target = /(^|\/)node$/.test(command) && args[0] ? args[0] : command;
|
|
97
|
+
relay({ command, args, packageJson: packageOf(target) ?? '/nonexistent/package.json' });
|
|
98
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* screen-watch RULE... : a generic reader of the tool's terminal (02-11). Every few seconds it reads the
|
|
2
|
+
* bottom of the screen of the tool (tmux) and acts on what a launcher said to look for -- nothing here
|
|
3
|
+
* knows a tool: its launcher (claude-code.sh, a codex.sh...) gives the rules, so a tool that changes its
|
|
4
|
+
* words is followed by changing its launcher alone.
|
|
5
|
+
*
|
|
6
|
+
* A rule: KIND:PATTERN[=VALUE], PATTERN a JavaScript regular expression (flag i).
|
|
7
|
+
* link:PATTERN a link on the screen (the match): sent in the chat, to be opened by the person
|
|
8
|
+
* (a sign-in, say); once per link.
|
|
9
|
+
* notice:PATTERN=TEXT something the agent should know (an update installed, to be taken up by a
|
|
10
|
+
* restart): TEXT given to the agent, as a reminder it is woken by (docket); once per screen.
|
|
11
|
+
* The agent decides when it suits it -- never restarted in the middle of its work (02-11).
|
|
12
|
+
* keys:PATTERN=K a question with one answer always: the keys K typed (Enter, Down, Up, Escape, 1, y...),
|
|
13
|
+
* once per screen. Only what its launcher wrote: nothing else is ever typed.
|
|
14
|
+
* type:PATTERN=TEXT the same with a few words (a command such as /login), then Enter; once per screen.
|
|
15
|
+
* code:PATTERN the tool waits for a code the person gets after signing in: the next message they write
|
|
16
|
+
* in the chat that looks like one (no space, 10 to 300 signs) is typed there, then Enter.
|
|
17
|
+
* Only the last LINES lines are read: what the tool prints of its own work above never counts.
|
|
18
|
+
*/
|
|
19
|
+
import { spawnSync } from 'node:child_process';
|
|
20
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
21
|
+
|
|
22
|
+
const LINES = 12; const EVERY_MS = 3000;
|
|
23
|
+
const KEYS = new Set(['Enter', 'Down', 'Up', 'Left', 'Right', 'Escape', 'Tab', 'y', 'n', '1', '2', '3']);
|
|
24
|
+
export function rulesOf(args) {
|
|
25
|
+
return args.flatMap((a) => {
|
|
26
|
+
const m = /^(link|notice|keys|type|code):(.+)$/s.exec(a); if (!m) return [];
|
|
27
|
+
let pattern = m[2]; let value = null;
|
|
28
|
+
if (m[1] === 'type') { const at = pattern.lastIndexOf('='); if (at < 1) return []; value = pattern.slice(at + 1).slice(0, 80); pattern = pattern.slice(0, at); if (!value.trim()) return []; }
|
|
29
|
+
if (m[1] === 'notice') { const at = pattern.lastIndexOf('='); if (at < 1) return []; value = pattern.slice(at + 1).trim().slice(0, 300); pattern = pattern.slice(0, at); if (!value) return []; }
|
|
30
|
+
if (m[1] === 'keys') { const at = pattern.lastIndexOf('='); if (at < 1) return []; value = pattern.slice(at + 1).split(',').filter((k) => KEYS.has(k)); pattern = pattern.slice(0, at); if (!value.length) return []; }
|
|
31
|
+
try { return [{ kind: m[1], re: new RegExp(pattern, 'i'), value }]; } catch { return []; }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/* -> what to do on this screen: [{ kind, match, value }], each once (seen: a Set kept between looks). */
|
|
35
|
+
export function actionsOn(screen, rules, seen) {
|
|
36
|
+
/* A long link the tool's screen broke over several lines (full lines, no space): put back in one. */
|
|
37
|
+
const raw = String(screen).replace(/\s+$/u, '').split('\n').map((l) => l.replace(/\s+$/u, ''));
|
|
38
|
+
const width = Math.max(0, ...raw.map((l) => l.length));
|
|
39
|
+
const joined = [];
|
|
40
|
+
for (const l of raw) { const prev = joined.at(-1); if (prev !== undefined && width > 40 && prev.length >= width - 1 && /^\S+$/.test(prev.split(' ').at(-1)) && /^\S+$/.test(l) && /https?:\/\//.test(prev)) joined[joined.length - 1] = prev + l; else joined.push(l); }
|
|
41
|
+
const bottom = joined.slice(-LINES).join('\n');
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const r of rules) {
|
|
44
|
+
const m = r.re.exec(bottom); if (!m) continue;
|
|
45
|
+
const key = `${r.kind}:${r.kind === 'link' ? m[0] : bottom}`;
|
|
46
|
+
if (seen.has(key)) continue;
|
|
47
|
+
/* A notice once an hour at most: its own words on the screen never bring it back in a loop. */
|
|
48
|
+
if (r.kind === 'notice' && Date.now() - (r.last ?? 0) < 60 * 60_000) { seen.add(key); continue; }
|
|
49
|
+
if (r.kind === 'notice') r.last = Date.now();
|
|
50
|
+
/* With a link, the lines around it (a code to type there, often): the person sees what the tool said. */
|
|
51
|
+
const lines = bottom.split('\n'); const i = lines.findIndex((l) => l.includes(m[0].split('\n')[0]));
|
|
52
|
+
const around = r.kind === 'link' && i >= 0 ? lines.slice(Math.max(0, i - 2), i + 4).map((l) => l.trim()).filter(Boolean).join('\n') : '';
|
|
53
|
+
seen.add(key); out.push({ kind: r.kind, match: m[0], value: r.value, around });
|
|
54
|
+
}
|
|
55
|
+
if (seen.size > 200) for (const k of [...seen].slice(0, 100)) seen.delete(k);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const main = process.argv[1]?.endsWith('screen-watch.mjs');
|
|
60
|
+
if (main) {
|
|
61
|
+
const rules = rulesOf(process.argv.slice(2));
|
|
62
|
+
const tmux = ['-L', process.env.SCREEN_WATCH_SOCKET ?? 'clavarium'];
|
|
63
|
+
const pane = process.env.SCREEN_WATCH_PANE ?? '=main:';
|
|
64
|
+
const chat = process.env.PARLEY_DIR ?? '/work/.parley';
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
/* Waiting for a code: the person's chat, from where it stood when the tool asked (to-agent.jsonl). */
|
|
67
|
+
let awaiting = null;
|
|
68
|
+
const inbox = `${chat}/to-agent.jsonl`;
|
|
69
|
+
const codeFrom = () => { try { return statSync(inbox).size; } catch { return 0; } };
|
|
70
|
+
const typeCode = () => {
|
|
71
|
+
if (awaiting === null) return;
|
|
72
|
+
let text = ''; try { const b = readFileSync(inbox); text = b.subarray(awaiting).toString('utf8'); } catch { return; }
|
|
73
|
+
for (const line of text.split('\n').filter(Boolean)) {
|
|
74
|
+
let m; try { m = JSON.parse(line); } catch { continue; }
|
|
75
|
+
const code = String(m?.text ?? '').trim();
|
|
76
|
+
if (/^[A-Za-z0-9_#.~+/=-]{10,300}$/.test(code)) {
|
|
77
|
+
spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, '-l', '--', code], { timeout: 5000 });
|
|
78
|
+
spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, 'Enter'], { timeout: 5000 });
|
|
79
|
+
awaiting = null; return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const look = () => {
|
|
84
|
+
typeCode();
|
|
85
|
+
const r = spawnSync('tmux', [...tmux, 'capture-pane', '-p', '-t', pane], { encoding: 'utf8', timeout: 5000 });
|
|
86
|
+
if (r.status !== 0) return;
|
|
87
|
+
for (const a of actionsOn(r.stdout, rules, seen)) {
|
|
88
|
+
if (a.kind === 'link') spawnSync('parley', ['tell', `Your tool asks you to open this link: ${a.match}${a.around && a.around !== a.match ? `\n\n\`\`\`\n${a.around}\n\`\`\`` : ''}`, '--dir', chat], { timeout: 10_000 });
|
|
89
|
+
if (a.kind === 'notice') spawnSync('docket', ['remind', '--in', '1m', a.value, '--dir', process.env.DOCKET_DIR ?? '/work/.docket'], { timeout: 10_000 });
|
|
90
|
+
if (a.kind === 'keys') for (const k of a.value) spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, k], { timeout: 5000 });
|
|
91
|
+
if (a.kind === 'type') { spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, '-l', '--', a.value], { timeout: 5000 }); spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, 'Enter'], { timeout: 5000 }); }
|
|
92
|
+
if (a.kind === 'code') { awaiting = codeFrom(); spawnSync('parley', ['tell', 'Once signed in, paste here the code the page gives you.', '--dir', chat], { timeout: 10_000 }); }
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/* Its life is the tool's: started just before the launcher becomes the tool (exec), it ends with it. */
|
|
96
|
+
const tool = process.ppid;
|
|
97
|
+
const alive = () => { try { process.kill(tool, 0); return true; } catch { return false; } };
|
|
98
|
+
if (rules.length) setInterval(() => { if (!alive()) process.exit(0); look(); }, EVERY_MS);
|
|
99
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* toml-block FILE NAME [TEXT]: keeps, in the TOML file FILE of the home, one block of its own --
|
|
2
|
+
* "# >>> clavarium NAME" ... "# <<< clavarium NAME" -- written anew with TEXT (its tables), every other
|
|
3
|
+
* line kept as the person or the tool wrote it. No TEXT: the block taken out. Written only when it
|
|
4
|
+
* changes, readable by its owner alone (02-11: Codex, Vibe -- their settings are TOML).
|
|
5
|
+
* Only tables go in a block (a key outside a table would land in the table above it).
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, writeFileSync, mkdirSync, renameSync } from 'node:fs';
|
|
8
|
+
import { dirname, join, isAbsolute } from 'node:path';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
|
|
11
|
+
const [file, name, text = ''] = process.argv.slice(2);
|
|
12
|
+
if (!file || !name || isAbsolute(file) || file.split('/').includes('..') || !/^[a-z0-9-]+$/.test(name)) { console.error('usage: toml-block <file in the home> <name> [text]'); process.exit(64); }
|
|
13
|
+
const at = join(homedir(), file);
|
|
14
|
+
let was = '';
|
|
15
|
+
try { was = readFileSync(at, 'utf8'); } catch (error) { if (error.code !== 'ENOENT') { console.error(`toml-block: ${file} cannot be read`); process.exit(3); } }
|
|
16
|
+
const open = `# >>> clavarium ${name}`; const close = `# <<< clavarium ${name}`;
|
|
17
|
+
const lines = was.split('\n'); const kept = []; let inside = false;
|
|
18
|
+
for (const l of lines) { if (l === open) { inside = true; continue; } if (l === close) { inside = false; continue; } if (!inside) kept.push(l); }
|
|
19
|
+
let out = kept.join('\n').replace(/\n+$/, '');
|
|
20
|
+
if (text.trim()) out = `${out ? `${out}\n\n` : ''}${open}\n${text.trim()}\n${close}`;
|
|
21
|
+
out = out ? `${out}\n` : '';
|
|
22
|
+
if (out !== was) {
|
|
23
|
+
mkdirSync(dirname(at), { recursive: true, mode: 0o700 });
|
|
24
|
+
writeFileSync(`${at}.new`, out, { mode: 0o600 });
|
|
25
|
+
renameSync(`${at}.new`, at);
|
|
26
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# THE LAUNCHER OF VIBE (Mistral), run by Clavarium in its machine at each start (config/tools.json,
|
|
3
|
+
# "launch"), from the read-only /tools. Arguments: the rights chosen by the owner (full, ask), then the
|
|
4
|
+
# command to run, as Clavarium made it. All that is Vibe's own is here, and only here (02-11).
|
|
5
|
+
mode="$1"; shift
|
|
6
|
+
case "$mode" in full|ask) ;; *) echo "launch: the first argument is full or ask" >&2; exit 64 ;; esac
|
|
7
|
+
[ $# -gt 0 ] || { echo "launch: no command to run" >&2; exit 64; }
|
|
8
|
+
here="$(dirname "$0")"; relay="$here/mcp-relay.mjs"
|
|
9
|
+
chat="${PARLEY_DIR:-/work/.parley}"; docket="/work/.docket"; tether="/work/.tether"
|
|
10
|
+
# ITS KEY: a secret named MISTRAL_API_KEY given to the conversation is in its environment; Vibe reads it
|
|
11
|
+
# there, and asks nothing. Without it, Vibe asks for it in its terminal at its first start.
|
|
12
|
+
# ITS TOOLS (MCP) in its settings (~/.vibe/config.toml), a block of their own, each through the relay.
|
|
13
|
+
block=''
|
|
14
|
+
if [ -f "$chat/server.mjs" ] && command -v parley-mcp >/dev/null 2>&1; then block="$block
|
|
15
|
+
[[mcp_servers]]
|
|
16
|
+
name = \"parley\"
|
|
17
|
+
transport = \"stdio\"
|
|
18
|
+
command = \"node\"
|
|
19
|
+
args = [\"$relay\", \"parley-mcp\", \"--dir\", \"$chat\"]"; fi
|
|
20
|
+
if [ -f "$chat/server.mjs" ] && command -v docket-mcp >/dev/null 2>&1; then block="$block
|
|
21
|
+
[[mcp_servers]]
|
|
22
|
+
name = \"docket\"
|
|
23
|
+
transport = \"stdio\"
|
|
24
|
+
command = \"node\"
|
|
25
|
+
args = [\"$relay\", \"docket-mcp\", \"--dir\", \"$docket\"]"; fi
|
|
26
|
+
if command -v tether-mcp >/dev/null 2>&1; then block="$block
|
|
27
|
+
[[mcp_servers]]
|
|
28
|
+
name = \"tether\"
|
|
29
|
+
transport = \"stdio\"
|
|
30
|
+
command = \"node\"
|
|
31
|
+
args = [\"$relay\", \"tether-mcp\", \"--dir\", \"$tether\"]"; fi
|
|
32
|
+
node "$here/toml-block.mjs" .vibe/config.toml tools "$block" \
|
|
33
|
+
|| echo "launch: Vibe has not its tools (MCP)" >&2
|
|
34
|
+
# WHAT ITS SCREEN ASKS, read by the generic screen-watch -- Vibe's own words: an update told to the
|
|
35
|
+
# agent, which restarts when it suits it.
|
|
36
|
+
node "$here/screen-watch.mjs" \
|
|
37
|
+
'notice:(new version|update) (is )?available[^\n]{0,120}=Your tool has an update: when nothing runs, touch /work/.parley/restart-asked to take it up.' \
|
|
38
|
+
</dev/null >/dev/null 2>&1 &
|
|
39
|
+
exec "$@"
|
package/config/tools.json
CHANGED
|
@@ -174,6 +174,63 @@
|
|
|
174
174
|
"@openai/codex"
|
|
175
175
|
],
|
|
176
176
|
"npm-writable"
|
|
177
|
+
],
|
|
178
|
+
"launch": "codex.sh"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"id": "vibe",
|
|
182
|
+
"instructions": ".vibe/AGENTS.md",
|
|
183
|
+
"label": "Mistral Vibe",
|
|
184
|
+
"launch": "vibe.sh",
|
|
185
|
+
"command": [
|
|
186
|
+
"vibe"
|
|
187
|
+
],
|
|
188
|
+
"resume": [
|
|
189
|
+
"vibe",
|
|
190
|
+
"--continue"
|
|
191
|
+
],
|
|
192
|
+
"memoryMb": 2048,
|
|
193
|
+
"rights": {
|
|
194
|
+
"full": [
|
|
195
|
+
"--auto-approve"
|
|
196
|
+
]
|
|
197
|
+
},
|
|
198
|
+
"install": [
|
|
199
|
+
[
|
|
200
|
+
"sudo",
|
|
201
|
+
"-n",
|
|
202
|
+
"apt-get",
|
|
203
|
+
"install",
|
|
204
|
+
"-y",
|
|
205
|
+
"-q",
|
|
206
|
+
"--no-install-recommends",
|
|
207
|
+
"python3-venv"
|
|
208
|
+
],
|
|
209
|
+
[
|
|
210
|
+
"sudo",
|
|
211
|
+
"-n",
|
|
212
|
+
"python3",
|
|
213
|
+
"-m",
|
|
214
|
+
"venv",
|
|
215
|
+
"/opt/vibe"
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
"sudo",
|
|
219
|
+
"-n",
|
|
220
|
+
"/opt/vibe/bin/pip",
|
|
221
|
+
"install",
|
|
222
|
+
"-q",
|
|
223
|
+
"--disable-pip-version-check",
|
|
224
|
+
"mistral-vibe"
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
"sudo",
|
|
228
|
+
"-n",
|
|
229
|
+
"ln",
|
|
230
|
+
"-sf",
|
|
231
|
+
"/opt/vibe/bin/vibe",
|
|
232
|
+
"/usr/local/bin/vibe"
|
|
233
|
+
]
|
|
177
234
|
]
|
|
178
235
|
},
|
|
179
236
|
{
|
package/deploy/clavarium-host
CHANGED
|
@@ -82,11 +82,13 @@ SHELF_MEMORY="1536M"
|
|
|
82
82
|
SHELF_STORE="/var/snap/multipass/common"
|
|
83
83
|
SHELF_INSTANCES="$SHELF_STORE/data/multipassd/vault/instances"
|
|
84
84
|
SHELF_CACHE="$SHELF_STORE/cache"
|
|
85
|
+
# The leases its DHCP server gave its machines: "<expiry> <mac> <ip> <name> <client id>" per line.
|
|
86
|
+
LEASES="$SHELF_STORE/data/multipassd/network/dnsmasq.leases"
|
|
85
87
|
# Moved to another disk (deploy/move-machines.sh, Multipass's own way: its
|
|
86
88
|
# MULTIPASS_STORAGE in a drop-in of its service): <path>/data, <path>/cache.
|
|
87
89
|
# (No drop-in is the usual case: under pipefail a missing file must not stop this program.)
|
|
88
90
|
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
|
-
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
|
|
91
|
+
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"; LEASES="$MOVED_TO/data/network/dnsmasq.leases"; fi
|
|
90
92
|
# Also the floor under a grown disk (grow_room): the server keeps the same
|
|
91
93
|
# (MIN_FREE_MB in server/shelf.mjs, used by server/capacity.mjs).
|
|
92
94
|
SHELF_MIN_FREE_MB="6144"
|
|
@@ -731,6 +733,14 @@ MESHUNIT
|
|
|
731
733
|
[ $# -ge 2 ] || usage
|
|
732
734
|
AREA="$1"; VERB="$2"; shift 2
|
|
733
735
|
|
|
736
|
+
# What changes something is written to the system log, by this program: sudo itself is told not to log
|
|
737
|
+
# the server's account (its probes every few seconds made some 800 lines in ten minutes, 31-10). Reading
|
|
738
|
+
# verbs, and commands run inside a machine (the server's own probes, mostly), are not written.
|
|
739
|
+
case "$AREA $VERB" in
|
|
740
|
+
"vm exec"|"vm ping"|"vm states"|"vm info"|"server logs"|"server room"|"server usage"|"shelf info"|"shelf room"|"shelf list"|"shelf size"|"shelf exec"|"git read"|"work room"|"disks list"|"disks room"|"machines places"|"machines moving"|"machines old"|"net taps"|"net leases"|"wifi status"|"wifi scan"|"path held"|"disk room"|"update check"|"meshcentral status"|"operator "*) : ;;
|
|
741
|
+
*) [ "$SAY" = yes ] || logger -t clavarium-host -- "$AREA $VERB$(printf ' %.80s' "$@" | head -c 400)" 2>/dev/null || true ;;
|
|
742
|
+
esac
|
|
743
|
+
|
|
734
744
|
# The remote screen's path carries a per-instance suffix: resolve it before any of its verbs run.
|
|
735
745
|
[ "$AREA" = meshcentral ] && mesh_resolve_path
|
|
736
746
|
|
|
@@ -986,6 +996,36 @@ case "$AREA $VERB" in
|
|
|
986
996
|
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=2 systemctl restart clavarium.service"; exit 0; fi
|
|
987
997
|
systemd-run --quiet --collect --unit="clavarium-restart-$(date +%s)" --on-active=2 /usr/bin/systemctl restart clavarium.service
|
|
988
998
|
exit 0 ;;
|
|
999
|
+
"server reboot")
|
|
1000
|
+
# THE WHOLE SERVER STARTED AGAIN, asked from the page (Settings, This server), after a
|
|
1001
|
+
# confirmation there: in five seconds, by systemd, so that the page is answered first.
|
|
1002
|
+
# Every machine stops with it (cleanly, by the VM manager) and starts again after.
|
|
1003
|
+
[ $# -eq 0 ] || usage
|
|
1004
|
+
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=5 systemctl reboot"; exit 0; fi
|
|
1005
|
+
systemd-run --quiet --collect --unit="clavarium-reboot-$(date +%s)" --on-active=5 /usr/bin/systemctl reboot
|
|
1006
|
+
exit 0 ;;
|
|
1007
|
+
"server protect")
|
|
1008
|
+
# WHAT KEEPS THE SERVER IN HAND (04-11), at each start of the server: should memory run out,
|
|
1009
|
+
# the kernel stops a machine first, never this server, its front or ssh. Made so for the next
|
|
1010
|
+
# start of each (a drop-in) and at once for what runs (choom). No argument; done again is the same.
|
|
1011
|
+
[ $# -eq 0 ] || usage
|
|
1012
|
+
if [ "$SAY" = "yes" ]; then echo "OOMScoreAdjust=-900 for clavarium caddy dex oauth2-proxy ssh"; exit 0; fi
|
|
1013
|
+
changed=no
|
|
1014
|
+
for unit in clavarium caddy dex oauth2-proxy ssh; do
|
|
1015
|
+
systemctl cat "$unit.service" >/dev/null 2>&1 || continue
|
|
1016
|
+
dir="/etc/systemd/system/$unit.service.d"; file="$dir/clavarium-oom.conf"
|
|
1017
|
+
want='# Written by clavarium-host (server protect): stopped last should memory run out.
|
|
1018
|
+
[Service]
|
|
1019
|
+
OOMScoreAdjust=-900'
|
|
1020
|
+
if [ "$(cat "$file" 2>/dev/null)" != "$want" ]; then
|
|
1021
|
+
mkdir -p "$dir" && printf '%s\n' "$want" > "$file" && changed=yes
|
|
1022
|
+
fi
|
|
1023
|
+
pid=$(systemctl show -p MainPID --value "$unit.service" 2>/dev/null)
|
|
1024
|
+
[ -n "$pid" ] && [ "$pid" != 0 ] && choom -n -900 -p "$pid" >/dev/null 2>&1 || true
|
|
1025
|
+
done
|
|
1026
|
+
[ "$changed" = no ] || systemctl daemon-reload
|
|
1027
|
+
echo "protected"
|
|
1028
|
+
exit 0 ;;
|
|
989
1029
|
"server room")
|
|
990
1030
|
# WHAT THE SERVER HAS LEFT, for Settings (This server) and for the
|
|
991
1031
|
# reserve that creating, starting, waking or growing a machine must
|
|
@@ -1129,6 +1169,17 @@ case "$AREA $VERB" in
|
|
|
1129
1169
|
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1130
1170
|
if [ -f "$img" ] && [ ! -L "$img" ]; then mv -n "$img" "$MNT/removed/$1-work-$(date -u +%Y%m%dT%H%M%SZ)-$$.img"; fi
|
|
1131
1171
|
exit 0 ;;
|
|
1172
|
+
"work erase")
|
|
1173
|
+
# Deleted for good, or its machine reset, BY ITS OWNER, after a confirmation that names the conversation
|
|
1174
|
+
# (01-11): its work disk is ERASED, not put aside. Only that one file and its mount point.
|
|
1175
|
+
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a conversation name: $1"
|
|
1176
|
+
img="$MNT/work-disks/$1.img"; at="$MNT/work/$1"
|
|
1177
|
+
if [ "$SAY" = "yes" ]; then printf 'disk %s erased\n' "$img"; exit 0; fi
|
|
1178
|
+
kept work; kept work-disks
|
|
1179
|
+
if mountpoint -q "$at"; then umount "$at" || refuse "the work disk of $1 is in use"; fi
|
|
1180
|
+
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1181
|
+
if [ -f "$img" ] && [ ! -L "$img" ]; then rm -f -- "$img"; fi
|
|
1182
|
+
exit 0 ;;
|
|
1132
1183
|
"view make")
|
|
1133
1184
|
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
|
|
1134
1185
|
folder_of "$1"; kept views
|
|
@@ -1340,14 +1391,38 @@ case "$AREA $VERB" in
|
|
|
1340
1391
|
"net taps")
|
|
1341
1392
|
[ $# -eq 0 ] || usage
|
|
1342
1393
|
run pgrep -a qemu-system ;;
|
|
1394
|
+
"net leases")
|
|
1395
|
+
# Which address the VM manager's DHCP server gave which MAC: one "<mac> <ip>" per
|
|
1396
|
+
# line, each checked; nothing else of that file is printed (the name in it is the
|
|
1397
|
+
# VM's own word, never trusted). Read-only. No file yet: nothing.
|
|
1398
|
+
[ $# -eq 0 ] || usage
|
|
1399
|
+
if [ "$SAY" = "yes" ]; then echo "<mac> <ip> of each lease in $LEASES"; exit 0; fi
|
|
1400
|
+
[ -f "$LEASES" ] || exit 0
|
|
1401
|
+
while read -r _ mac ip _; do
|
|
1402
|
+
if [[ "$mac" =~ ^[0-9a-f]{2}(:[0-9a-f]{2}){5}$ && "$ip" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then printf '%s %s\n' "$mac" "$ip"; fi
|
|
1403
|
+
done < "$LEASES"
|
|
1404
|
+
exit 0 ;;
|
|
1343
1405
|
"net bridge")
|
|
1406
|
+
# The bridge the machines' taps are on: multipass 1.17 names it per zone
|
|
1407
|
+
# (mpqemubrzone1, ...), older ones mpqemubr0 (04-11: the offline rules
|
|
1408
|
+
# were never written, their bridge not found). The first tap's says.
|
|
1344
1409
|
[ $# -eq 0 ] || usage
|
|
1345
|
-
|
|
1410
|
+
if [ "$SAY" = "yes" ]; then echo "ip -4 -o addr show <the bridge of the taps, else $BRIDGE>"; exit 0; fi
|
|
1411
|
+
bridge="$BRIDGE"
|
|
1412
|
+
for t in /sys/class/net/tap-*; do
|
|
1413
|
+
[ -e "$t/master" ] || continue
|
|
1414
|
+
m=$(basename "$(readlink "$t/master")"); [[ "$m" =~ ^mpqemubr[a-z0-9]{1,12}$ ]] && { bridge="$m"; break; }
|
|
1415
|
+
done
|
|
1416
|
+
if [ "$bridge" = "$BRIDGE" ] && ! [ -e "/sys/class/net/$BRIDGE" ]; then
|
|
1417
|
+
for b in /sys/class/net/mpqemubr*; do [ -e "$b" ] && { bridge=$(basename "$b"); break; }; done
|
|
1418
|
+
fi
|
|
1419
|
+
run ip -4 -o addr show "$bridge" ;;
|
|
1346
1420
|
"net apply")
|
|
1347
1421
|
# <ruleset>: the whole table, as text. Each line must be one of the
|
|
1348
1422
|
# shapes the server writes; one unknown line refuses the whole.
|
|
1349
1423
|
[ $# -eq 1 ] || usage
|
|
1350
1424
|
tap='"tap-[0-9a-f]{1,12}"'; addr='[0-9]{1,3}(\.[0-9]{1,3}){3}'
|
|
1425
|
+
mac='[0-9a-f]{2}(:[0-9a-f]{2}){5}'; addrs="\\{ $addr(, $addr)* \\}"
|
|
1351
1426
|
while IFS= read -r line; do
|
|
1352
1427
|
[[ -z "$line"
|
|
1353
1428
|
|| "$line" =~ ^(delete\ )?table\ bridge\ $TABLE(\ \{)?$
|
|
@@ -1355,6 +1430,13 @@ case "$AREA $VERB" in
|
|
|
1355
1430
|
|| "$line" =~ ^\ \ \ \ type\ filter\ hook\ (forward|input)\ priority\ 0\;$
|
|
1356
1431
|
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (drop|udp\ dport\ 67\ accept|ether\ type\ arp\ accept)$
|
|
1357
1432
|
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ daddr\ $addr\ (accept|meta\ l4proto\ \{\ tcp,\ udp\ \}\ th\ dport\ 53\ drop)$
|
|
1433
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (ether\ saddr|arp\ saddr\ ether)\ !=\ $mac\ drop$
|
|
1434
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ether\ type\ !=\ \{\ ip,\ arp\ \}\ drop$
|
|
1435
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ udp\ dport\ 67\ @th,288,48\ !=\ 0x[0-9a-f]{12}\ drop$
|
|
1436
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ saddr\ 0\.0\.0\.0\ ip\ daddr\ 255\.255\.255\.255\ udp\ dport\ 67\ accept$
|
|
1437
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ saddr\ !=\ $addr\ drop$
|
|
1438
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ arp\ saddr\ ip\ !=\ \{\ 0\.0\.0\.0,\ $addr\ \}\ drop$
|
|
1439
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (ip\ saddr|arp\ saddr\ ip)\ $addrs\ drop$
|
|
1358
1440
|
|| "$line" =~ ^(\ \ )?\}$ ]] || refuse "a network rule of an unknown shape: $line"
|
|
1359
1441
|
done <<< "$1"
|
|
1360
1442
|
run nft "$1" ;;
|