clavarium 0.2.262-next.1 → 0.2.264-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,10 @@ 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
+ # 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
20
24
  # ITS TOOLS (MCP), EACH THROUGH THE RELAY (02-11): a tool updated on the machine is taken up between two of
21
25
  # its requests -- whatever the tool, the session never restarted, nothing for the agent to do. Declared
22
26
  # once, by Claude Code itself (its other servers kept); an older declaration without the relay is replaced.
@@ -48,4 +52,11 @@ if [ -f "$chat/server.mjs" ]; then
48
52
  node "$(dirname "$0")/claude-pulse.mjs" "$chat" \
49
53
  || echo "launch: the chat will not say when Claude Code works without a word" >&2
50
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: its sign-in link sent to the person's chat; "restart to apply" an update asked of the server (done
57
+ # when its turn ends). A tool that changes its words: only these lines change.
58
+ node "$(dirname "$0")/screen-watch.mjs" \
59
+ 'link:https://(claude\.ai|claude\.com|console\.anthropic\.com)/[^ ]*oauth[^ ]*' \
60
+ 'restart:(update|updated|installed)[^\n]{0,80}restart' \
61
+ </dev/null >/dev/null 2>&1 &
51
62
  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,62 @@
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
+ * restart:PATTERN the tool asks to be restarted (an update to apply): asked of the server, which does it
10
+ * once the tool's turn has ended (/work/.parley/restart-asked); once per screen.
11
+ * keys:PATTERN=K a question with one answer always: the keys K typed (Enter, Down, Up, Escape, 1, y...),
12
+ * once per screen. Only what its launcher wrote: nothing else is ever typed.
13
+ * Only the last LINES lines are read: what the tool prints of its own work above never counts.
14
+ */
15
+ import { spawnSync } from 'node:child_process';
16
+ import { writeFileSync, existsSync } from 'node:fs';
17
+
18
+ const LINES = 12; const EVERY_MS = 3000;
19
+ const KEYS = new Set(['Enter', 'Down', 'Up', 'Left', 'Right', 'Escape', 'Tab', 'y', 'n', '1', '2', '3']);
20
+ export function rulesOf(args) {
21
+ return args.flatMap((a) => {
22
+ const m = /^(link|restart|keys):(.+)$/s.exec(a); if (!m) return [];
23
+ let pattern = m[2]; let value = null;
24
+ 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 []; }
25
+ try { return [{ kind: m[1], re: new RegExp(pattern, 'i'), value }]; } catch { return []; }
26
+ });
27
+ }
28
+ /* -> what to do on this screen: [{ kind, match, value }], each once (seen: a Set kept between looks). */
29
+ export function actionsOn(screen, rules, seen) {
30
+ const bottom = String(screen).replace(/\s+$/u, '').split('\n').slice(-LINES).join('\n');
31
+ const out = [];
32
+ for (const r of rules) {
33
+ const m = r.re.exec(bottom); if (!m) continue;
34
+ const key = `${r.kind}:${r.kind === 'link' ? m[0] : bottom}`;
35
+ if (seen.has(key)) continue;
36
+ seen.add(key); out.push({ kind: r.kind, match: m[0], value: r.value });
37
+ }
38
+ if (seen.size > 200) for (const k of [...seen].slice(0, 100)) seen.delete(k);
39
+ return out;
40
+ }
41
+
42
+ const main = process.argv[1]?.endsWith('screen-watch.mjs');
43
+ if (main) {
44
+ const rules = rulesOf(process.argv.slice(2));
45
+ const tmux = ['-L', process.env.SCREEN_WATCH_SOCKET ?? 'clavarium'];
46
+ const pane = process.env.SCREEN_WATCH_PANE ?? '=main:';
47
+ const chat = process.env.PARLEY_DIR ?? '/work/.parley';
48
+ const seen = new Set();
49
+ const look = () => {
50
+ const r = spawnSync('tmux', [...tmux, 'capture-pane', '-p', '-t', pane], { encoding: 'utf8', timeout: 5000 });
51
+ if (r.status !== 0) return;
52
+ for (const a of actionsOn(r.stdout, rules, seen)) {
53
+ if (a.kind === 'link') spawnSync('parley', ['tell', `Your tool asks you to open this link: ${a.match}`, '--dir', chat], { timeout: 10_000 });
54
+ if (a.kind === 'restart' && existsSync(chat)) { try { writeFileSync(`${chat}/restart-asked`, ''); } catch { /* the chat is not there */ } }
55
+ if (a.kind === 'keys') for (const k of a.value) spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, k], { timeout: 5000 });
56
+ }
57
+ };
58
+ /* Its life is the tool's: started just before the launcher becomes the tool (exec), it ends with it. */
59
+ const tool = process.ppid;
60
+ const alive = () => { try { process.kill(tool, 0); return true; } catch { return false; } };
61
+ if (rules.length) setInterval(() => { if (!alive()) process.exit(0); look(); }, EVERY_MS);
62
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.262-next.1",
3
+ "version": "0.2.264-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.262-next.1",
9
+ "version": "0.2.264-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.262-next.1",
3
+ "version": "0.2.264-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/guide.mjs CHANGED
@@ -121,6 +121,8 @@ export function ownText({ name, tool, workKept, resources = [], chat, online, se
121
121
  if (chat) out.push('- The chat shows Markdown (lists, tables, "> [!IMPORTANT]") and pictures of /work: ![before](/work/a.png).');
122
122
  /* The thread is kept whole: after a restart, its end is read, and further back on demand. */
123
123
  if (chat && reread) out.push(`- After a restart: ${plain(reread, 60)}, the end of the chat; it says how to read further back.`);
124
+ /* 02-11: the one command a tool may ask of the server. */
125
+ if (chat) out.push('- To be restarted (new tools to take up, or anything stuck): finish what runs, then `touch /work/.parley/restart-asked`; the server restarts you once your turn ends, and your work picks up where it was.');
124
126
  /* Its docket (dockets.mjs): what wakes it waits there until it says done or failed. */
125
127
  if (chat) out.push('- What wakes you (a file arrived, the clock, a call) waits in your docket: when told "run docket", run it, do each, then docket done ID or docket failed ID "why". To be reminded later: docket remind --at "2026-10-23 09:00" (or --in 2h, --cron "0 9 * * 1") "what for". docket --help says all.');
126
128
  /* Its lists (binders.mjs): kept on the server, asked for through .binder; a person approves. */
package/server/main.mjs CHANGED
@@ -524,6 +524,20 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
524
524
  try { if (talk.event(name, { kind: 'tools-updated', text: 'Tools updated: restart it to use them all. Its work picks up where it was.', topic: 'Tools', actions: ['restart'] })) toolbox.told(name); } catch { /* its chat is off */ }
525
525
  }
526
526
  });
527
+ /* A TOOL THAT ASKS TO BE RESTARTED (02-11: to take up its tools, after an update): restarted by this server
528
+ once its turn has ended (its pulse no longer busy), said in its chat; once per ten minutes at most. */
529
+ const restartedAt = new Map();
530
+ const restartTimer = setInterval(() => {
531
+ for (const name of all.awake()) {
532
+ if (!talk.restartAsked(name)) continue;
533
+ if (talk.pulse(name)?.busy) continue;
534
+ talk.restartTaken(name);
535
+ if (Date.now() - (restartedAt.get(name) ?? 0) < 10 * 60_000) continue;
536
+ restartedAt.set(name, Date.now());
537
+ try { talk.event(name, { kind: 'restarted', text: 'Restarted as it asked: its work picks up where it was.', topic: 'Restarted' }); } catch { /* its chat is off */ }
538
+ void all.restart(name).catch(() => {});
539
+ }
540
+ }, 15_000); restartTimer.unref?.();
527
541
  /* The health of each machine, and folders that came loose put back: see health.mjs. */
528
542
  const health = new Health({ vms, conversations: all, resources: folders, seen: new Store(`${dataDir}/health-seen.json`), ...(healthSettleMs === undefined ? {} : { settleMs: healthSettleMs }) });
529
543
  const stopHealth = health.start(healthEveryMs);
@@ -625,7 +639,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
625
639
  speak: (text) => speech.speak(text),
626
640
  log: (line) => events.add({ kind: 'server', text: line }) });
627
641
  const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
628
- server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
642
+ server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
629
643
  let closing = false;
630
644
  boxes.attach(server, WebSocketServer);
631
645
  for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name));
package/server/talk.mjs CHANGED
@@ -140,6 +140,8 @@ export const SYSTEM_MAX = 50;
140
140
  branch: the owner allowed each one. The owner may move a kind to another
141
141
  level (Settings); nothing else of a line changes with it. */
142
142
  export const LEVELS = Object.freeze(['needs-you', 'news', 'trace']);
143
+ /* The file a tool puts beside its chat to be restarted (see restartAsked). */
144
+ export const RESTART_ASKED = 'restart-asked';
143
145
  export const EVENT_LEVELS = Object.freeze({
144
146
  sent: 'news',
145
147
  refused: 'needs-you',
@@ -384,6 +386,14 @@ export class Talk {
384
386
  /* Is its chat on? (cheap: the record alone) */
385
387
  isOn(name) { return this.#store.get(name)?.on === true; }
386
388
 
389
+ /* ITS TOOL ASKS TO BE RESTARTED (02-11): a file it puts in its chat's folder (RESTART_ASKED); the server
390
+ restarts it once its turn has ended -- the one command a tool may ask of the server, nothing typed. */
391
+ restartAsked(name) {
392
+ if (this.#store.get(name)?.on !== true) return false;
393
+ try { return lstatSync(join(this.#dir(name), RESTART_ASKED), { throwIfNoEntry: false })?.isFile() === true; } catch { return false; }
394
+ }
395
+ restartTaken(name) { try { rmSync(join(this.#dir(name), RESTART_ASKED), { force: true }); } catch { /* gone already */ } }
396
+
387
397
  /* Its tool's pulse (Parley): { busy, at }, or null. Where the chat is off: null. */
388
398
  pulse(name) {
389
399
  if (this.#store.get(name)?.on !== true) return null;