clavarium 0.2.261-next.1 → 0.2.262-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.
- package/config/launch/claude-code.sh +21 -19
- package/config/launch/mcp-relay.mjs +98 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -17,29 +17,31 @@ 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
|
-
# in its settings first, since asking Claude Code takes seconds. Nothing stops the start.
|
|
20
|
+
# ITS TOOLS (MCP), EACH THROUGH THE RELAY (02-11): a tool updated on the machine is taken up between two of
|
|
21
|
+
# its requests -- whatever the tool, the session never restarted, nothing for the agent to do. Declared
|
|
22
|
+
# once, by Claude Code itself (its other servers kept); an older declaration without the relay is replaced.
|
|
23
|
+
# Looked for in its settings first, since asking Claude Code takes seconds. Nothing stops the start.
|
|
24
|
+
relay="$(dirname "$0")/mcp-relay.mjs"
|
|
25
|
+
tool() { # NAME FOLDER COMMAND ARGS...
|
|
26
|
+
name="$1"; folder="$2"; shift 2
|
|
27
|
+
if grep -q "\"$folder\"" "$HOME/.claude.json" 2>/dev/null && grep -q "mcp-relay.mjs" "$HOME/.claude.json" 2>/dev/null \
|
|
28
|
+
&& 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
|
|
29
|
+
claude mcp remove --scope user "$name" >/dev/null 2>&1
|
|
30
|
+
claude mcp add --scope user "$name" -- node "$relay" "$@" >/dev/null 2>&1 \
|
|
31
|
+
|| echo "launch: $name was not given to Claude Code as tools: the command $name still works" >&2
|
|
32
|
+
}
|
|
33
|
+
# Parley, the chat of the conversation, when it has one: the version installed on the machine (parley-mcp),
|
|
34
|
+
# else the copy beside the chat.
|
|
24
35
|
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
|
|
36
|
+
if [ -f "$chat/server.mjs" ]; then
|
|
37
|
+
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
38
|
fi
|
|
29
|
-
#
|
|
30
|
-
# reminders it sets itself. The same as the command "docket", installed in every machine.
|
|
39
|
+
# Its docket, with its chat: what woke it, to say done or failed; the reminders it sets itself.
|
|
31
40
|
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.
|
|
41
|
+
if [ -f "$chat/server.mjs" ] && command -v docket-mcp >/dev/null 2>&1; then tool docket "$docket" docket-mcp --dir "$docket"; fi
|
|
42
|
+
# Its tether: the accesses it was given (a mailbox, a calendar, a folder, a machine over SSH).
|
|
38
43
|
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
|
|
44
|
+
if command -v tether-mcp >/dev/null 2>&1; then tool tether "$tether" tether-mcp --dir "$tether"; fi
|
|
43
45
|
# ITS PULSE: Claude Code's own hooks say to the chat that it acts, and when its turn ends, so that
|
|
44
46
|
# the person sees "Working..." while it works without a word (parley pulse; nothing posted).
|
|
45
47
|
if [ -f "$chat/server.mjs" ]; then
|
|
@@ -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
|
+
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.262-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.262-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|