clavarium 0.2.263-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.263-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.263-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.263-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.",