clavarium 0.2.161-next.1 → 0.2.162-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.
Files changed (54) hide show
  1. package/README.md +4 -0
  2. package/config/launch/claude-code.sh +36 -19
  3. package/config/launch/codex.sh +36 -0
  4. package/config/launch/json-set.mjs +5 -2
  5. package/config/launch/mcp-relay.mjs +98 -0
  6. package/config/launch/screen-watch.mjs +99 -0
  7. package/config/launch/toml-block.mjs +26 -0
  8. package/config/launch/vibe.sh +39 -0
  9. package/config/tools.json +57 -0
  10. package/deploy/clavarium-host +89 -6
  11. package/deploy/install.sh +7 -1
  12. package/deploy/maintenance.html +5 -2
  13. package/deploy/updater.mjs +48 -0
  14. package/npm-shrinkwrap.json +245 -19
  15. package/package.json +8 -6
  16. package/server/accounts.mjs +2 -1
  17. package/server/api.mjs +121 -11
  18. package/server/boxes.mjs +826 -35
  19. package/server/capacity.mjs +3 -1
  20. package/server/catalog.mjs +48 -0
  21. package/server/conversations.mjs +41 -5
  22. package/server/demandes.mjs +150 -0
  23. package/server/dictation-engines.mjs +91 -0
  24. package/server/door.mjs +9 -2
  25. package/server/events.mjs +1 -0
  26. package/server/features.mjs +366 -0
  27. package/server/files.mjs +50 -6
  28. package/server/gitpush.mjs +170 -53
  29. package/server/guide.mjs +3 -1
  30. package/server/mailbox.mjs +9 -0
  31. package/server/main.mjs +102 -17
  32. package/server/network.mjs +121 -13
  33. package/server/pocket.mjs +136 -0
  34. package/server/rooms.mjs +219 -0
  35. package/server/serverlogs.mjs +38 -5
  36. package/server/settingswords.mjs +52 -0
  37. package/server/setup.mjs +1 -1
  38. package/server/speech.mjs +72 -6
  39. package/server/spoken.mjs +60 -0
  40. package/server/suggest.mjs +66 -0
  41. package/server/talk.mjs +44 -11
  42. package/server/tethers.mjs +44 -7
  43. package/server/vm.mjs +2 -0
  44. package/server/voice.mjs +254 -46
  45. package/server/wakelearn.mjs +214 -0
  46. package/web/app.js +2054 -425
  47. package/web/device.html +2 -0
  48. package/web/features.js +480 -0
  49. package/web/index.html +634 -471
  50. package/web/kit.js +272 -0
  51. package/web/mail-view.js +386 -0
  52. package/web/style.css +854 -202
  53. package/web/voice-core.js +25 -0
  54. 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
- # 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.
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" ] && ! 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
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
- # ITS DOCKET AS ITS OWN TOOLS (MCP), with its chat: what woke it, to say done or failed; the
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 && ! grep -q "\"$docket\"" "$HOME/.claude.json" 2>/dev/null; then
33
- claude mcp add --scope user docket -- docket-mcp --dir "$docket" >/dev/null 2>&1 \
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 && ! grep -q "\"$tether\"" "$HOME/.claude.json" 2>/dev/null; then
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. Written only when it
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
- for (const [k, v] of Object.entries(keys)) { if (v === null) delete data[k]; else data[k] = v; }
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
  {