clavarium 0.2.1-next.2 → 0.2.2-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 +20 -0
- package/config/launch/json-set.mjs +29 -0
- package/config/tools.json +2 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +11 -1
- package/server/main.mjs +2 -0
- package/server/toolbox.mjs +32 -4
- package/server/tools.mjs +5 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# THE LAUNCHER OF CLAUDE CODE, run by Clavarium in its machine at each start
|
|
3
|
+
# (config/tools.json, "launch"), from the read-only /tools: the agent cannot
|
|
4
|
+
# change it. Arguments: the rights chosen by the owner (full: acts without
|
|
5
|
+
# asking; ask: asks first), then the command to run, as Clavarium made it.
|
|
6
|
+
#
|
|
7
|
+
# Claude Code trusts skipDangerousModePermissionPrompt only in its settings
|
|
8
|
+
# FILE: on its command line it is ignored, and so is
|
|
9
|
+
# --dangerously-skip-permissions ("Bypass permissions was requested at launch
|
|
10
|
+
# and ignored"). So the file says it, for the rights of this start.
|
|
11
|
+
mode="$1"; shift
|
|
12
|
+
case "$mode" in
|
|
13
|
+
full) keys='{"skipDangerousModePermissionPrompt": true}' ;;
|
|
14
|
+
ask) keys='{"skipDangerousModePermissionPrompt": null}' ;;
|
|
15
|
+
*) echo "launch: the first argument is full or ask" >&2; exit 64 ;;
|
|
16
|
+
esac
|
|
17
|
+
[ $# -gt 0 ] || { echo "launch: no command to run" >&2; exit 64; }
|
|
18
|
+
node "$(dirname "$0")/json-set.mjs" .claude/settings.json "$keys" \
|
|
19
|
+
|| echo "launch: the settings of Claude Code were not changed: it may ask before acting" >&2
|
|
20
|
+
exec "$@"
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
3
|
+
* changes, readable by its owner alone. A file that is not a JSON object is
|
|
4
|
+
* not touched (exit 3): a person's settings are never overwritten by a guess.
|
|
5
|
+
*
|
|
6
|
+
* Generic: any launcher of /tools/launch may use it for its tool's settings.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync, writeFileSync, mkdirSync, renameSync } from 'node:fs';
|
|
9
|
+
import { dirname, join, isAbsolute } from 'node:path';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
|
|
12
|
+
const [file, given] = process.argv.slice(2);
|
|
13
|
+
if (!file || !given || isAbsolute(file) || file.split('/').includes('..')) { console.error('usage: json-set <file in the home> <keys as JSON>'); process.exit(64); }
|
|
14
|
+
let keys;
|
|
15
|
+
try { keys = JSON.parse(given); } catch { console.error('json-set: the keys are not JSON'); process.exit(64); }
|
|
16
|
+
if (!keys || typeof keys !== 'object' || Array.isArray(keys)) { console.error('json-set: the keys are a JSON object'); process.exit(64); }
|
|
17
|
+
const at = join(homedir(), file);
|
|
18
|
+
let data = {};
|
|
19
|
+
try { data = JSON.parse(readFileSync(at, 'utf8')); } catch (error) {
|
|
20
|
+
if (error.code !== 'ENOENT') { console.error(`json-set: ${file} is not JSON: left as it is`); process.exit(3); }
|
|
21
|
+
}
|
|
22
|
+
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
|
+
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
|
+
if (JSON.stringify(data) !== was) {
|
|
26
|
+
mkdirSync(dirname(at), { recursive: true, mode: 0o700 });
|
|
27
|
+
writeFileSync(`${at}.new`, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
|
|
28
|
+
renameSync(`${at}.new`, at);
|
|
29
|
+
}
|
package/config/tools.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"id": "claude-code",
|
|
4
4
|
"instructions": ".claude/CLAUDE.md",
|
|
5
5
|
"label": "Claude Code",
|
|
6
|
+
"launch": "claude-code.sh",
|
|
6
7
|
"command": [
|
|
7
8
|
"claude"
|
|
8
9
|
],
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
"full": [
|
|
16
17
|
"--dangerously-skip-permissions",
|
|
17
18
|
"--settings",
|
|
18
|
-
"{\"
|
|
19
|
+
"{\"permissions\":{\"allow\":[\"Bash(parley:*)\"]}}"
|
|
19
20
|
],
|
|
20
21
|
"ask": [
|
|
21
22
|
"--settings",
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2-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.2-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { JsonFile } from './store.mjs';
|
|
|
11
11
|
import { attachCommand, SOCKET } from './tmux.mjs';
|
|
12
12
|
import { WORK, VM_USER, SHARING_STEP } from './vm.mjs';
|
|
13
13
|
import { resumeOrFresh } from './tools.mjs';
|
|
14
|
+
import { TOOLS_PATH, LAUNCH } from './toolbox.mjs';
|
|
14
15
|
|
|
15
16
|
export const SESSION = 'main';
|
|
16
17
|
export const STOP_DELAY_MS = 60_000;
|
|
@@ -67,6 +68,8 @@ export class Conversations {
|
|
|
67
68
|
/* Set by the server: prepares the VM before the tool is attached, and
|
|
68
69
|
names the program the tool is started through. See secrets.mjs. */
|
|
69
70
|
prepare = async () => {};
|
|
71
|
+
/* (name, file) -> '' when the launcher of its tool is in its machine (toolbox.mjs, launcherIn). */
|
|
72
|
+
launcherReady = async () => '';
|
|
70
73
|
through = [];
|
|
71
74
|
/* Set by the server: closes at once a terminal kept open for a screen
|
|
72
75
|
that might come back. Called before a machine is slept, stopped or deleted. */
|
|
@@ -453,6 +456,11 @@ export class Conversations {
|
|
|
453
456
|
/* A machine built before a repair was part of the recipe gets it
|
|
454
457
|
once, beside the opening, not in its way. */
|
|
455
458
|
if ((c.fixed ?? 0) < FIXES && tool.fixups.length > 0) void this.#fixup(name, tool);
|
|
459
|
+
/* Its launcher, in /tools: repaired if missing; not there, the tool does not start. */
|
|
460
|
+
if (tool.launch) {
|
|
461
|
+
const why = await this.launcherReady(name, tool.launch).catch((error) => error.message || 'not there');
|
|
462
|
+
if (why) { this.left(name); throw new Refusal(503, `Its tool cannot start: ${why}. Try again.`, { retry: true }); }
|
|
463
|
+
}
|
|
456
464
|
const argv = this.#vms.execArgv(name, attachCommand(SESSION, [...this.through, ...this.#command(name, tool)], WORK));
|
|
457
465
|
for (const id of ['resume', 'fresh', 'first']) this.#reach(name, id);
|
|
458
466
|
tell();
|
|
@@ -472,7 +480,9 @@ export class Conversations {
|
|
|
472
480
|
first: added at EVERY start, a resume included (a tool does not
|
|
473
481
|
keep it from its last session). */
|
|
474
482
|
const rights = tool.rights ? (c.askFirst === true ? tool.rights.ask : tool.rights.full) : [];
|
|
475
|
-
|
|
483
|
+
const run = resume ? resumeOrFresh([...tool.resume, ...rights], [...tool.command, ...rights]) : [...tool.command, ...rights];
|
|
484
|
+
/* Through its launcher: told the rights chosen, it sets what the tool needs, then runs it. */
|
|
485
|
+
return tool.launch ? ['sh', `${TOOLS_PATH}/${LAUNCH}/${tool.launch}`, c.askFirst === true ? 'ask' : 'full', ...run] : run;
|
|
476
486
|
}
|
|
477
487
|
|
|
478
488
|
/* Whether its tool asks before acting (true), or acts without asking in
|
package/server/main.mjs
CHANGED
|
@@ -298,6 +298,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
298
298
|
await Promise.race([toolbox.installIn(name).then((why) => { if (why && parleySaid.get(name) !== why) console.error(`${name}: Parley not installed: ${why}`); parleySaid.set(name, why); }), new Promise((r) => { setTimeout(r, PARLEY_WAIT_MS).unref?.(); })]);
|
|
299
299
|
await rules;
|
|
300
300
|
};
|
|
301
|
+
/* The launcher of its tool, in /tools, before it starts: repaired when missing. */
|
|
302
|
+
all.launcherReady = (name, file) => toolbox.launcherIn(name, file);
|
|
301
303
|
all.through = [RUNNER];
|
|
302
304
|
/* Mailboxes kept as folders: brought up to date now and then, never
|
|
303
305
|
because a tool asked. */
|
package/server/toolbox.mjs
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* /tools/index.json { tools: [{ name, version, file, sha256, usage }] }
|
|
13
13
|
* /tools/clavarium-parley-0.9.0.tgz Parley, the first of them, as the registry
|
|
14
14
|
* served it (checked: parley.mjs)
|
|
15
|
+
* /tools/launch/<tool>.sh how each tool is started (config/tools.json,
|
|
16
|
+
* "launch"), and json-set.mjs for their settings
|
|
15
17
|
* /tools/CLAVARIUM.md where a tool is, the same for every
|
|
16
18
|
* machine (see guide.mjs): `notes`
|
|
17
19
|
*
|
|
@@ -26,10 +28,14 @@
|
|
|
26
28
|
import { createHash } from 'node:crypto';
|
|
27
29
|
import { readFileSync, writeFileSync, readdirSync, renameSync, rmSync, existsSync, mkdirSync } from 'node:fs';
|
|
28
30
|
import { join } from 'node:path';
|
|
31
|
+
import { fileURLToPath } from 'node:url';
|
|
29
32
|
import { APP, ARCHIVES, PARLEY, archiveName, locked, parleyDir, parleyVersion } from './parley.mjs';
|
|
30
33
|
|
|
31
34
|
export const TOOLS_PATH = '/tools';
|
|
32
35
|
export const NOTES = 'CLAVARIUM.md';
|
|
36
|
+
/* THE LAUNCHERS of the tools (config/launch of this code: config/ is in every release, also one made by an older updater): copied as they are into /tools/launch. */
|
|
37
|
+
export const LAUNCH = 'launch';
|
|
38
|
+
export const LAUNCHERS = fileURLToPath(new URL('../config/launch', import.meta.url));
|
|
33
39
|
/* What is put there: { name, archive (a path here), integrity, usage(file) }.
|
|
34
40
|
Parley's archive as the registry served it, next to the code (see
|
|
35
41
|
parley.mjs), with the integrity npm recorded for the version installed:
|
|
@@ -51,7 +57,7 @@ export const integrityOf = (bytes) => `sha512-${createHash('sha512').update(byte
|
|
|
51
57
|
const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) ?? '';
|
|
52
58
|
|
|
53
59
|
export class Toolbox {
|
|
54
|
-
#host; #vms; #mnt; #uid; #gid; #sources; #notes; #index = null;
|
|
60
|
+
#host; #vms; #mnt; #uid; #gid; #sources; #notes; #launchers; #index = null;
|
|
55
61
|
/* What is known of Parley in each machine, as the index is now:
|
|
56
62
|
conversation -> { sha256, why } (why: '' installed, or why it cannot be,
|
|
57
63
|
such as a machine without npm: not asked again at each opening). */
|
|
@@ -61,8 +67,8 @@ export class Toolbox {
|
|
|
61
67
|
`notes(find)`: the text of /tools/CLAVARIUM.md, given how to find a
|
|
62
68
|
tool of the index; none when not given. Nothing of one conversation
|
|
63
69
|
may be in it: every machine reads it. */
|
|
64
|
-
constructor({ host, vms, mntDir, uid = process.getuid(), gid = process.getgid(), sources = parleySource(), notes = null }) {
|
|
65
|
-
this.#host = host; this.#vms = vms; this.#mnt = mntDir; this.#uid = uid; this.#gid = gid; this.#sources = sources; this.#notes = notes;
|
|
70
|
+
constructor({ host, vms, mntDir, uid = process.getuid(), gid = process.getgid(), sources = parleySource(), notes = null, launchers = LAUNCHERS }) {
|
|
71
|
+
this.#host = host; this.#vms = vms; this.#mnt = mntDir; this.#uid = uid; this.#gid = gid; this.#sources = sources; this.#notes = notes; this.#launchers = launchers;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
folder() { return `${this.#mnt}/toolbox/files`; }
|
|
@@ -92,7 +98,17 @@ export class Toolbox {
|
|
|
92
98
|
const version = /-(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)\.tgz$/.exec(file)?.[1] ?? '';
|
|
93
99
|
tools.push({ name: source.name, version, file, sha256, usage: source.usage(`${TOOLS_PATH}/${file}`) });
|
|
94
100
|
}
|
|
95
|
-
|
|
101
|
+
/* The launchers, each copied when it differs; one no longer here taken away. */
|
|
102
|
+
const launch = `${dir}/${LAUNCH}`;
|
|
103
|
+
mkdirSync(launch, { recursive: true });
|
|
104
|
+
const wanted = existsSync(this.#launchers) ? readdirSync(this.#launchers).filter((n) => /^[a-z][a-z0-9-]*\.(sh|mjs)$/.test(n)) : [];
|
|
105
|
+
for (const n of wanted) {
|
|
106
|
+
const bytes = readFileSync(join(this.#launchers, n));
|
|
107
|
+
const there = existsSync(`${launch}/${n}`) ? readFileSync(`${launch}/${n}`) : null;
|
|
108
|
+
if (!there || !there.equals(bytes)) { writeFileSync(`${launch}/.${n}.new`, bytes, { mode: 0o755 }); renameSync(`${launch}/.${n}.new`, `${launch}/${n}`); }
|
|
109
|
+
}
|
|
110
|
+
for (const n of readdirSync(launch)) if (!wanted.includes(n)) rmSync(`${launch}/${n}`, { recursive: true, force: true });
|
|
111
|
+
const kept = new Set([...tools.map((t) => t.file), 'index.json', LAUNCH, ...(this.#notes ? [NOTES] : [])]);
|
|
96
112
|
for (const name of readdirSync(dir)) if (!kept.has(name)) rmSync(`${dir}/${name}`, { recursive: true, force: true });
|
|
97
113
|
const index = { tools };
|
|
98
114
|
writeFileSync(`${dir}/.index.json.new`, `${JSON.stringify(index, null, 2)}\n`);
|
|
@@ -155,6 +171,18 @@ export class Toolbox {
|
|
|
155
171
|
return '';
|
|
156
172
|
}
|
|
157
173
|
|
|
174
|
+
/* THE LAUNCHER OF A TOOL, there in its machine before the tool starts: when /tools is
|
|
175
|
+
missing or came loose, it is repaired (below) and looked at again. '' or why not --
|
|
176
|
+
then the tool does not start: never a start in a half-made state. */
|
|
177
|
+
async launcherIn(conversation, file) {
|
|
178
|
+
const at = `${TOOLS_PATH}/${LAUNCH}/${file}`;
|
|
179
|
+
const there = async () => (await this.#vms.exec(conversation, ['test', '-r', at], { timeoutMs: 15_000 }).catch(() => ({ code: 1 }))).code === 0;
|
|
180
|
+
if (await there()) return '';
|
|
181
|
+
const why = await this.repair(conversation);
|
|
182
|
+
if (await there()) return '';
|
|
183
|
+
return why ? `/tools could not be put in place: ${why}` : `${at} is not in its machine, even after /tools was mounted again`;
|
|
184
|
+
}
|
|
185
|
+
|
|
158
186
|
/* It came loose: unmounted whatever the VM manager believes, its view
|
|
159
187
|
made again if it went, and mounted again. */
|
|
160
188
|
async repair(conversation) {
|
package/server/tools.mjs
CHANGED
|
@@ -98,9 +98,13 @@ export function readTools(text) {
|
|
|
98
98
|
machine's user (".claude/CLAUDE.md"): a marked block in it points
|
|
99
99
|
the tool to its guide (see guide.mjs). A plain relative path. */
|
|
100
100
|
if (t.instructions !== undefined && !INSTRUCTIONS.test(t.instructions)) throw new Error(`${t.id}: instructions is a relative path in the home, without ".."`);
|
|
101
|
+
/* Optional: ITS LAUNCHER, a script of config/launch shown at /tools/launch: run at each start,
|
|
102
|
+
given the rights chosen (full, ask) then the command; it sets what the tool needs,
|
|
103
|
+
then runs it. Clavarium knows nothing more of the tool. */
|
|
104
|
+
if (t.launch !== undefined && !/^[a-z][a-z0-9-]{0,40}\.sh$/.test(t.launch)) throw new Error(`${t.id}: launch is the name of a script of config/launch, such as "${t.id}.sh"`);
|
|
101
105
|
/* Repairs an existing machine is given once (see FIXES in conversations.mjs). */
|
|
102
106
|
const fixups = t.install.includes('npm-writable') ? NPM_WRITABLE : [];
|
|
103
|
-
return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), command: Object.freeze([...t.command]), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
|
|
107
|
+
return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), command: Object.freeze([...t.command]), ...(t.launch ? { launch: t.launch } : {}), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
|
|
104
108
|
});
|
|
105
109
|
}
|
|
106
110
|
|