clavarium 0.2.142-next.1 → 0.2.143-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 +24 -4
- package/deploy/install.sh +7 -1
- package/deploy/updater.mjs +48 -0
- package/npm-shrinkwrap.json +346 -20
- package/package.json +11 -6
- package/server/accounts.mjs +2 -1
- package/server/api.mjs +89 -9
- package/server/boxes.mjs +911 -0
- package/server/capacity.mjs +3 -1
- package/server/catalog.mjs +48 -0
- package/server/conversations.mjs +27 -5
- package/server/files.mjs +14 -5
- package/server/gitaccess.mjs +32 -0
- package/server/gitchecks.mjs +6 -1
- package/server/gitkeeper.mjs +8 -5
- package/server/gitpush.mjs +15 -2
- package/server/guide.mjs +2 -0
- package/server/health.mjs +5 -1
- package/server/history.mjs +40 -0
- package/server/mailbox.mjs +9 -0
- package/server/main.mjs +95 -10
- package/server/pocket.mjs +136 -0
- package/server/secrets.mjs +14 -0
- package/server/serverlogs.mjs +32 -5
- package/server/setup.mjs +2 -0
- package/server/speech.mjs +125 -0
- package/server/suggest.mjs +66 -0
- package/server/talk.mjs +59 -6
- package/server/tethers.mjs +34 -1
- package/server/vm.mjs +2 -0
- package/server/voice.mjs +124 -7
- package/web/app.js +939 -36
- package/web/index.html +86 -14
- package/web/links.js +1 -1
- package/web/style.css +295 -40
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
|
@@ -731,6 +731,14 @@ MESHUNIT
|
|
|
731
731
|
[ $# -ge 2 ] || usage
|
|
732
732
|
AREA="$1"; VERB="$2"; shift 2
|
|
733
733
|
|
|
734
|
+
# What changes something is written to the system log, by this program: sudo itself is told not to log
|
|
735
|
+
# the server's account (its probes every few seconds made some 800 lines in ten minutes, 31-10). Reading
|
|
736
|
+
# verbs, and commands run inside a machine (the server's own probes, mostly), are not written.
|
|
737
|
+
case "$AREA $VERB" in
|
|
738
|
+
"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"|"wifi status"|"wifi scan"|"path held"|"disk room"|"update check"|"meshcentral status"|"operator "*) : ;;
|
|
739
|
+
*) [ "$SAY" = yes ] || logger -t clavarium-host -- "$AREA $VERB$(printf ' %.80s' "$@" | head -c 400)" 2>/dev/null || true ;;
|
|
740
|
+
esac
|
|
741
|
+
|
|
734
742
|
# The remote screen's path carries a per-instance suffix: resolve it before any of its verbs run.
|
|
735
743
|
[ "$AREA" = meshcentral ] && mesh_resolve_path
|
|
736
744
|
|
|
@@ -962,7 +970,7 @@ case "$AREA $VERB" in
|
|
|
962
970
|
# WHAT THE SERVER'S PROGRAMS SAID, for Settings (This server, Logs): one
|
|
963
971
|
# source, over a span; read-only, bounded. The page masks what looks
|
|
964
972
|
# like a secret before showing it.
|
|
965
|
-
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <1|6|24|168|boot>
|
|
973
|
+
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <10m|1|6|24|168|boot>
|
|
966
974
|
[ $# -eq 2 ] || usage
|
|
967
975
|
case "$1" in
|
|
968
976
|
clavarium) units=(-u clavarium.service -u 'clavarium-view-*' -u clavarium-tools-view.service -u clavarium-move-machines.service) ;;
|
|
@@ -974,9 +982,10 @@ case "$AREA $VERB" in
|
|
|
974
982
|
system) units=(-k) ;;
|
|
975
983
|
*) refuse "not a source of logs: $1" ;;
|
|
976
984
|
esac
|
|
977
|
-
case "$2" in 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (1, 6, 24, 168 hours, or boot)" ;; esac
|
|
978
|
-
|
|
979
|
-
|
|
985
|
+
case "$2" in 10m) since=(--since "-10min") ;; 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (10m, 1, 6, 24, 168 hours, or boot)" ;; esac
|
|
986
|
+
# The newest 20000 lines at most: more is too much to read on a page, and to send.
|
|
987
|
+
if [ "$SAY" = "yes" ]; then echo "journalctl ${units[*]} ${since[*]} -o short-iso --no-pager (the last 20000 lines)"; exit 0; fi
|
|
988
|
+
journalctl "${units[@]}" "${since[@]}" -o short-iso --no-pager -n 20000 2>/dev/null | cut -c1-2000 || true
|
|
980
989
|
exit 0 ;;
|
|
981
990
|
"server restart")
|
|
982
991
|
# THIS SERVER STARTED AGAIN, asked from the page: in two seconds, by
|
|
@@ -1128,6 +1137,17 @@ case "$AREA $VERB" in
|
|
|
1128
1137
|
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1129
1138
|
if [ -f "$img" ] && [ ! -L "$img" ]; then mv -n "$img" "$MNT/removed/$1-work-$(date -u +%Y%m%dT%H%M%SZ)-$$.img"; fi
|
|
1130
1139
|
exit 0 ;;
|
|
1140
|
+
"work erase")
|
|
1141
|
+
# Deleted for good, or its machine reset, BY ITS OWNER, after a confirmation that names the conversation
|
|
1142
|
+
# (01-11): its work disk is ERASED, not put aside. Only that one file and its mount point.
|
|
1143
|
+
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a conversation name: $1"
|
|
1144
|
+
img="$MNT/work-disks/$1.img"; at="$MNT/work/$1"
|
|
1145
|
+
if [ "$SAY" = "yes" ]; then printf 'disk %s erased\n' "$img"; exit 0; fi
|
|
1146
|
+
kept work; kept work-disks
|
|
1147
|
+
if mountpoint -q "$at"; then umount "$at" || refuse "the work disk of $1 is in use"; fi
|
|
1148
|
+
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1149
|
+
if [ -f "$img" ] && [ ! -L "$img" ]; then rm -f -- "$img"; fi
|
|
1150
|
+
exit 0 ;;
|
|
1131
1151
|
"view make")
|
|
1132
1152
|
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
|
|
1133
1153
|
folder_of "$1"; kept views
|
package/deploy/install.sh
CHANGED
|
@@ -238,7 +238,7 @@ apt-get update -qq
|
|
|
238
238
|
# bindfs: the read-only views. nftables: the network rules. build-essential
|
|
239
239
|
# and python3: one module of the server (the terminal) is compiled here.
|
|
240
240
|
# qrencode: the public keys, shown as QR codes on a screen. openssh-client: the tunnel.
|
|
241
|
-
apt-get install -y -qq bindfs nftables build-essential python3 curl ca-certificates xz-utils sudo snapd openssl git qrencode openssh-client >/dev/null
|
|
241
|
+
apt-get install -y -qq bindfs nftables build-essential python3 curl ca-certificates xz-utils sudo snapd openssl git qrencode openssh-client ffmpeg >/dev/null
|
|
242
242
|
snap list multipass >/dev/null 2>&1 || snap install multipass >/dev/null
|
|
243
243
|
|
|
244
244
|
step "account"
|
|
@@ -319,6 +319,12 @@ printf 'DATA=%s\nMNT=%s\n' "$DATA" "$MNT" > "$ETC/host.conf"; chmod 0644 "$ETC/h
|
|
|
319
319
|
rule="$(mktemp)"
|
|
320
320
|
printf '# Clavarium: the server account may run ONE program as root, and nothing else.\n%s ALL=(root) NOPASSWD: %s\n' "$ACCOUNT" "$HOST_PROGRAM" > "$rule"
|
|
321
321
|
visudo -cf "$rule" >/dev/null || refuse "the sudo rule did not pass its check"
|
|
322
|
+
# Its probes every few seconds kept out of the system log, with what this sudo takes (the updater does the same).
|
|
323
|
+
for quiet in '!syslog, !pam_session' '!pam_session'; do
|
|
324
|
+
cp "$rule" "$rule.q"; printf 'Defaults:%s %s\n' "$ACCOUNT" "$quiet" >> "$rule.q"
|
|
325
|
+
if out="$(visudo -cf "$rule.q" 2>&1)" && ! printf '%s' "$out" | grep -qiE 'unknown setting|syntax error|parse error'; then mv "$rule.q" "$rule"; break; fi
|
|
326
|
+
rm -f "$rule.q"
|
|
327
|
+
done
|
|
322
328
|
install -o root -g root -m 0440 "$rule" /etc/sudoers.d/clavarium; rm -f -- "$rule"
|
|
323
329
|
|
|
324
330
|
step "what the machines are given, on root's chain"
|
package/deploy/updater.mjs
CHANGED
|
@@ -114,6 +114,52 @@ export async function ensureProxySettings({ file = PROXY_CFG, run = runCommand }
|
|
|
114
114
|
return true;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/* SUDO, QUIET FOR CLAVARIUM'S ONE PROGRAM, kept by the updater: the server asks the host program every
|
|
118
|
+
few seconds (machine states, memory, repositories), and sudo wrote three lines to the system log for
|
|
119
|
+
each call -- some 800 lines in ten minutes, nothing to read in them (found 31-10). The account may run
|
|
120
|
+
that one program and nothing else; what changes something, the program logs itself (clavarium-host). */
|
|
121
|
+
export const SUDOERS = '/etc/sudoers.d/clavarium';
|
|
122
|
+
/* What sudo is told, tried in this order: the first its version takes without a word wins. Some sudo builds do
|
|
123
|
+
not know « syslog » (found 01-11 on a real server: « unknown setting: 'syslog' » on every call); they keep
|
|
124
|
+
the session lines quiet at least. A line of ours their sudo does not take is replaced. */
|
|
125
|
+
export const QUIET_SETTINGS = ['!syslog, !pam_session', '!pam_session'];
|
|
126
|
+
export const quietLine = (account, setting = QUIET_SETTINGS[0]) => `Defaults:${account} ${setting}`;
|
|
127
|
+
const QUIET_COMMENT = '# Added by the Clavarium updater: its probes every few seconds are not written to the system log.';
|
|
128
|
+
export async function ensureQuietSudo({ file = SUDOERS, run = runCommand } = {}) {
|
|
129
|
+
let text;
|
|
130
|
+
try { text = readFileSync(file, 'utf8'); } catch { return false; }
|
|
131
|
+
const account = text.match(/^([a-z_][a-z0-9_-]*)\s+ALL=\(root\)\s+NOPASSWD:/m)?.[1];
|
|
132
|
+
if (!account) return false;
|
|
133
|
+
const accepted = async (candidate) => {
|
|
134
|
+
rmSync(`${file}.new`, { force: true });
|
|
135
|
+
writeFileSync(`${file}.new`, candidate, { mode: 0o440 });
|
|
136
|
+
const r = await run(['visudo', '-cf', `${file}.new`], { timeoutMs: 30_000 });
|
|
137
|
+
return r.code === 0 && !/unknown setting|syntax error|parse error/i.test(`${r.stdout}\n${r.stderr}`);
|
|
138
|
+
};
|
|
139
|
+
/* The rule as it is, without any line of ours. */
|
|
140
|
+
const base = text.split('\n').filter((l) => l !== QUIET_COMMENT && !l.startsWith(`Defaults:${account} `)).join('\n').replace(/\n*$/, '\n');
|
|
141
|
+
const current = QUIET_SETTINGS.map((q) => quietLine(account, q)).find((l) => text.includes(l));
|
|
142
|
+
try {
|
|
143
|
+
if (current && await accepted(text)) return false; /* ours, and taken as it is */
|
|
144
|
+
for (const setting of QUIET_SETTINGS) {
|
|
145
|
+
const next = `${base}${QUIET_COMMENT}\n${quietLine(account, setting)}\n`;
|
|
146
|
+
if (await accepted(next)) { renameSync(`${file}.new`, file); return true; }
|
|
147
|
+
}
|
|
148
|
+
/* None taken: the rule alone, as install.sh wrote it -- never a file sudo complains about. */
|
|
149
|
+
if (current && await accepted(base)) { renameSync(`${file}.new`, file); return true; }
|
|
150
|
+
return false;
|
|
151
|
+
} finally { rmSync(`${file}.new`, { force: true }); }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* FFMPEG, kept by the updater: the voice boxes play a radio, a podcast, a music file through it
|
|
155
|
+
(server/boxes.mjs, listen). Installed by install.sh; added once to a machine installed before. */
|
|
156
|
+
export async function ensureFfmpeg({ run = runCommand, has = () => ['/usr/bin/ffmpeg', '/usr/local/bin/ffmpeg'].some((f) => existsSync(f)) } = {}) {
|
|
157
|
+
if (has()) return false;
|
|
158
|
+
if (process.getuid?.() !== 0) return false;
|
|
159
|
+
await run(['apt-get', 'install', '-y', '-qq', 'ffmpeg'], { timeoutMs: 15 * 60_000, env: { ...process.env, DEBIAN_FRONTEND: 'noninteractive' } });
|
|
160
|
+
return has();
|
|
161
|
+
}
|
|
162
|
+
|
|
117
163
|
/* THE MAINTENANCE PAGE, kept by the updater: while the server is down (an update, a restart) the
|
|
118
164
|
front (Caddy) answers it instead of the sign-in proxy's "Bad Gateway". The sign-in proxy answers
|
|
119
165
|
502 in HTML when the server does not; the server's own errors are JSON and pass as they are. A
|
|
@@ -913,6 +959,8 @@ async function main(argv) {
|
|
|
913
959
|
update that brought it ran the PREVIOUS release's code. Idempotent; never stops the turn. */
|
|
914
960
|
try { const [{ installWatch }, { realSys }] = await Promise.all([import('./doctor.mjs'), import('./online.mjs')]); if (await installWatch(realSys())) console.error('updater: the certificate timer set up'); } catch (error) { console.error(`updater: the certificate timer could not be set up: ${error.message}`); }
|
|
915
961
|
try { if (await u.ensureDropIn()) console.error('updater: the drop-in of the server\'s unit written'); } catch (error) { console.error(`updater: the drop-in could not be written: ${error.message}`); }
|
|
962
|
+
try { if (await ensureFfmpeg()) console.error('updater: ffmpeg installed, for the sounds the voice boxes play'); } catch (error) { console.error(`updater: ffmpeg could not be installed: ${error.message}`); }
|
|
963
|
+
try { if (await ensureQuietSudo()) console.error('updater: sudo no longer logs the host program\'s probes'); } catch (error) { console.error(`updater: sudo could not be made quiet: ${error.message}`); }
|
|
916
964
|
try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy takes one CSRF cookie per sign-in'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
|
|
917
965
|
try { const c = await ensureGenericClientId({ run: runCommand }); if (c.changed.length) console.error('updater: the sign-in client id was made generic (nothing names the product in the open)'); } catch (error) { console.error(`updater: the sign-in client id could not be made generic: ${error.message}`); }
|
|
918
966
|
try { if (await ensureTunnel({ run: runCommand })) console.error('updater: the tunnel to the relay notices a cut sooner'); } catch (error) { console.error(`updater: the tunnel could not be set: ${error.message}`); }
|