clavarium 0.2.397-next.1 → 0.2.399-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/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/apikeys.mjs +4 -0
- package/server/main.mjs +4 -2
- package/server/vm.mjs +44 -30
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.399-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.399-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clavarium-binder": "0.1.62-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
16
|
"clavarium-parley": "0.17.91-next.1",
|
|
17
|
-
"clavarium-tether": "0.1.0-next.
|
|
17
|
+
"clavarium-tether": "0.1.0-next.66",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
20
20
|
"node-pty": "^1.1.0",
|
|
@@ -800,9 +800,9 @@
|
|
|
800
800
|
}
|
|
801
801
|
},
|
|
802
802
|
"node_modules/clavarium-tether": {
|
|
803
|
-
"version": "0.1.0-next.
|
|
804
|
-
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.
|
|
805
|
-
"integrity": "sha512-
|
|
803
|
+
"version": "0.1.0-next.66",
|
|
804
|
+
"resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.66.tgz",
|
|
805
|
+
"integrity": "sha512-Q1XPq+wVlZEOPuFNsHm9cATbAsVbr1QObIPa9u6e9V1KhMb1tGPpFsuU15jIflRa6tD/XaZo4VCrUtd1o8iz/w==",
|
|
806
806
|
"license": "MIT",
|
|
807
807
|
"bin": {
|
|
808
808
|
"tether": "bin/cli.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.399-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.",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"clavarium-binder": "0.1.62-next.1",
|
|
49
49
|
"clavarium-docket": "0.1.2-next.2",
|
|
50
50
|
"clavarium-parley": "0.17.91-next.1",
|
|
51
|
-
"clavarium-tether": "0.1.0-next.
|
|
51
|
+
"clavarium-tether": "0.1.0-next.66",
|
|
52
52
|
"mammoth": "1.13.0",
|
|
53
53
|
"mermaid": "11.17.2",
|
|
54
54
|
"node-pty": "^1.1.0",
|
package/server/apikeys.mjs
CHANGED
|
@@ -1097,6 +1097,9 @@ export async function handleExternal(request, response, { keys, status, chats =
|
|
|
1097
1097
|
try { id = keys.check(request.headers.authorization); } catch (error) { return refused(error, '/mcp'); }
|
|
1098
1098
|
let text = '';
|
|
1099
1099
|
for await (const piece of request) { text += piece; if (text.length > MCP_BODY_MAX) { note(id, 413, '/mcp'); return send(413, { error: 'Too long.' }); } }
|
|
1100
|
+
/* A protocol version said in the header, and none spoken here: refused, as the spec asks (none said: the oldest assumed). */
|
|
1101
|
+
const said = request.headers['mcp-protocol-version'];
|
|
1102
|
+
if (typeof said === 'string' && said && !MCP_VERSIONS.includes(said)) { note(id, 400, '/mcp'); return send(400, { jsonrpc: '2.0', id: null, error: { code: -32600, message: `Unsupported MCP-Protocol-Version: ${said.slice(0, 20)} (spoken: ${MCP_VERSIONS.join(', ')})` } }); }
|
|
1100
1103
|
let msg;
|
|
1101
1104
|
try { msg = JSON.parse(text); } catch { note(id, 400, '/mcp'); return send(400, { jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } }); }
|
|
1102
1105
|
if (!msg || typeof msg !== 'object' || Array.isArray(msg) || msg.jsonrpc !== '2.0' || typeof msg.method !== 'string') {
|
|
@@ -1174,6 +1177,7 @@ export async function handleExternal(request, response, { keys, status, chats =
|
|
|
1174
1177
|
if (!(error instanceof Refusal)) throw error;
|
|
1175
1178
|
/* Not given: refused as the API refuses it (too many, too). Anything else is the tool's own failure, said to the caller. */
|
|
1176
1179
|
if (error.status === 429) { note(id, 429, what); return send(429, { jsonrpc: '2.0', id: msg.id, error: { code: -32002, message: error.message } }, { 'retry-after': String(error.retry ?? 60) }); }
|
|
1180
|
+
/* (An HTTP 403 for a scope not given is what the MCP authorization spec says: kept, MCP review 11-11.) */
|
|
1177
1181
|
if (error.status === 403) { note(id, 403, what); return send(403, { jsonrpc: '2.0', id: msg.id, error: { code: -32001, message: error.message } }); }
|
|
1178
1182
|
note(id, error.status, what);
|
|
1179
1183
|
return send(200, { jsonrpc: '2.0', id: msg.id, result: { content: [{ type: 'text', text: error.message }], isError: true } });
|
package/server/main.mjs
CHANGED
|
@@ -310,8 +310,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
310
310
|
const instance = new Instance({ file: new JsonFile(`${dataDir}/instance.json`, {}), origin: publicOrigin, given: appName });
|
|
311
311
|
let repairTerminal = async () => { throw new Error('not ready'); };
|
|
312
312
|
const asHost = runner(host);
|
|
313
|
-
|
|
314
|
-
const
|
|
313
|
+
/* A conversation in a shared machine (#221) says which: the machine its VM operations reach. */
|
|
314
|
+
const conversationStore = new Store(`${dataDir}/conversations.json`);
|
|
315
|
+
const vms = new Vms(asHost, host, { machineOf: (name) => { const m = conversationStore.get(name)?.machine; return typeof m === 'string' && m ? m : undefined; } });
|
|
316
|
+
const all = conversations ?? new Conversations({ store: conversationStore, layout: new JsonFile(`${dataDir}/layout.json`, {}), vms, tools, ...(stopDelayMs === undefined ? {} : { stopDelayMs }) });
|
|
315
317
|
/* Who may do what with what: ONE table, shared by everything below. */
|
|
316
318
|
const grants = new Grants(new Store(`${dataDir}/grants.json`));
|
|
317
319
|
/* Folder-style boxes the owner drops assets into, to tidy the views and hand a whole box at once (groups.mjs). */
|
package/server/vm.mjs
CHANGED
|
@@ -84,10 +84,11 @@ export class VmUnknown extends Error {
|
|
|
84
84
|
export class Vms {
|
|
85
85
|
/* `run(argv, options)` reaches the host program; `prefix` is the same
|
|
86
86
|
route as an argument vector, for the one caller that needs a terminal. */
|
|
87
|
-
#ask; #snapshot = null; #asking = null; #now; #freshMs;
|
|
87
|
+
#ask; #snapshot = null; #asking = null; #now; #freshMs; #machineOf;
|
|
88
88
|
/* `freshMs`: how long one answer serves every caller (0: only those asking meanwhile). */
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
/* `machineOf(conversation)`: the shared machine it lives in (#221), or nothing -- its own, `clv-<conversation>`. */
|
|
90
|
+
constructor(run, prefix, { now = () => Date.now(), freshMs = STATES_FRESH_MS, machineOf = () => undefined } = {}) {
|
|
91
|
+
this.#ask = run; this.prefix = prefix; this.#now = now; this.#freshMs = freshMs; this.#machineOf = machineOf;
|
|
91
92
|
/* What changes a machine makes the states asked again (not taken from before it). */
|
|
92
93
|
this.run = async (argv, options) => {
|
|
93
94
|
const changes = argv[0] === 'vm' && CHANGES.has(argv[1]);
|
|
@@ -115,25 +116,38 @@ export class Vms {
|
|
|
115
116
|
return this.#asking;
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
/* ITS MACHINE (#221): a conversation's own (`clv-<name>`, as always), or the shared one it lives in. */
|
|
120
|
+
vmOf(conversation) {
|
|
121
|
+
const shared = this.#machineOf(conversation);
|
|
122
|
+
if (shared === undefined) return vmName(conversation);
|
|
123
|
+
vmName(conversation); /* its own name checked all the same */
|
|
124
|
+
return vmName(shared);
|
|
125
|
+
}
|
|
126
|
+
/* In a shared machine, everything run for a conversation goes through its door (clavarium-enter, as root):
|
|
127
|
+
its own /work, its own home and user, its limits -- each tool sees what it sees in a machine of its own. */
|
|
128
|
+
#door(conversation, argv) {
|
|
129
|
+
return this.#machineOf(conversation) === undefined ? argv : ['sudo', '-n', 'clavarium-enter', conversation, '--', ...argv];
|
|
130
|
+
}
|
|
131
|
+
|
|
118
132
|
launch(conversation, memoryMb, diskGb, cpus) {
|
|
119
133
|
/* The disk and cores go with the memory only when they are the chosen size, not the defaults. */
|
|
120
134
|
const size = diskGb && cpus ? [String(diskGb), String(cpus)] : [];
|
|
121
|
-
return this.run(['vm', 'launch',
|
|
135
|
+
return this.run(['vm', 'launch', this.vmOf(conversation), String(memoryMb), ...size], { timeoutMs: (LAUNCH_SECONDS + 60) * 1000 });
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
/* The machine of a conversation as a COPY of the ready-made one (see
|
|
125
139
|
shelf.mjs), with its own memory. Left stopped: started by the caller. */
|
|
126
140
|
clone(conversation, shelf, memoryMb) {
|
|
127
|
-
return this.run(['vm', 'clone', shelf,
|
|
141
|
+
return this.run(['vm', 'clone', shelf, this.vmOf(conversation), String(memoryMb)], { timeoutMs: CLONE_MS });
|
|
128
142
|
}
|
|
129
143
|
|
|
130
144
|
exec(conversation, argv, options) {
|
|
131
|
-
return this.run(['vm', 'exec',
|
|
145
|
+
return this.run(['vm', 'exec', this.vmOf(conversation), '--', ...this.#door(conversation, argv)], options);
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
/* What a terminal attaches to: the same `exec`, as an argument vector. */
|
|
135
149
|
execArgv(conversation, argv) {
|
|
136
|
-
return [...this.prefix, 'vm', 'exec',
|
|
150
|
+
return [...this.prefix, 'vm', 'exec', this.vmOf(conversation), '--', ...this.#door(conversation, argv)];
|
|
137
151
|
}
|
|
138
152
|
|
|
139
153
|
/* Every machine's state, by VM name (a Map); throws VmUnknown when the VM manager did not answer. */
|
|
@@ -150,7 +164,7 @@ export class Vms {
|
|
|
150
164
|
frozen inside had "multipass info" fail, read as "no longer exists"). */
|
|
151
165
|
/* `fresh`: asked now (an owner opening it, building it again), not taken from a few seconds ago. */
|
|
152
166
|
async state(conversation, { fresh = false } = {}) {
|
|
153
|
-
const name =
|
|
167
|
+
const name = this.vmOf(conversation);
|
|
154
168
|
const snap = await this.#states(fresh);
|
|
155
169
|
if (!snap.states) throw new VmUnknown(snap.why);
|
|
156
170
|
return snap.states.get(name);
|
|
@@ -162,57 +176,57 @@ export class Vms {
|
|
|
162
176
|
is on the host is decided by the host program, not here. `uid`/`gid`:
|
|
163
177
|
files written in the VM belong, on the host, to this account. */
|
|
164
178
|
mount(conversation, kind, name, uid, gid) {
|
|
165
|
-
return this.run(['vm', 'mount',
|
|
179
|
+
return this.run(['vm', 'mount', this.vmOf(conversation), kind, name, String(uid), String(gid)], { timeoutMs: 600_000 });
|
|
166
180
|
}
|
|
167
181
|
|
|
168
182
|
/* The work folder of a conversation: kept on the host, shown in its
|
|
169
183
|
machine at /work. Made (or found again) before it is mounted. */
|
|
170
|
-
workMake(conversation) {
|
|
184
|
+
workMake(conversation) { this.vmOf(conversation); return this.run(['work', 'make', conversation]); }
|
|
171
185
|
workMount(conversation, uid, gid) {
|
|
172
|
-
return this.run(['vm', 'mount',
|
|
186
|
+
return this.run(['vm', 'mount', this.vmOf(conversation), 'work', conversation, String(uid), String(gid)], { timeoutMs: 600_000 });
|
|
173
187
|
}
|
|
174
|
-
workUnmount(conversation) { return this.run(['vm', 'unwork',
|
|
188
|
+
workUnmount(conversation) { return this.run(['vm', 'unwork', this.vmOf(conversation)], { timeoutMs: 120_000 }); }
|
|
175
189
|
/* Megabytes left: { disk, host }, or undefined if it cannot be told. */
|
|
176
190
|
async workRoom(conversation) {
|
|
177
|
-
|
|
191
|
+
this.vmOf(conversation);
|
|
178
192
|
const r = await this.run(['work', 'room', conversation]);
|
|
179
193
|
const m = /^disk (\d+) host (\d+)$/m.exec(r.stdout ?? '');
|
|
180
194
|
return r.code === 0 && m ? { disk: Number(m[1]), host: Number(m[2]) } : undefined;
|
|
181
195
|
}
|
|
182
|
-
workAside(conversation) {
|
|
196
|
+
workAside(conversation) { this.vmOf(conversation); return this.run(['work', 'aside', conversation]); }
|
|
183
197
|
/* Deleted for good, or reset, by its owner: its work disk erased, not put aside. */
|
|
184
|
-
workErase(conversation) {
|
|
198
|
+
workErase(conversation) { this.vmOf(conversation); return this.run(['work', 'erase', conversation]); }
|
|
185
199
|
|
|
186
200
|
/* The tools folder (see toolbox.mjs), shown read-only at /tools. */
|
|
187
201
|
mountTools(conversation, uid, gid) {
|
|
188
|
-
return this.run(['vm', 'mount',
|
|
202
|
+
return this.run(['vm', 'mount', this.vmOf(conversation), 'tools', 'tools', String(uid), String(gid)], { timeoutMs: 600_000 });
|
|
189
203
|
}
|
|
190
|
-
unmountTools(conversation) { return this.run(['vm', 'untools',
|
|
204
|
+
unmountTools(conversation) { return this.run(['vm', 'untools', this.vmOf(conversation)], { timeoutMs: 120_000 }); }
|
|
191
205
|
|
|
192
206
|
umount(conversation, name) {
|
|
193
|
-
return this.run(['vm', 'umount',
|
|
207
|
+
return this.run(['vm', 'umount', this.vmOf(conversation), name], { timeoutMs: 120_000 });
|
|
194
208
|
}
|
|
195
209
|
|
|
196
210
|
/* `signal`: a start given up (Force stop asked meanwhile). */
|
|
197
|
-
start(conversation, { signal } = {}) { return this.run(['vm', 'start',
|
|
198
|
-
stop(conversation, timeoutMs = 300_000) { return this.run(['vm', 'stop',
|
|
211
|
+
start(conversation, { signal } = {}) { return this.run(['vm', 'start', this.vmOf(conversation)], { timeoutMs: 300_000, ...(signal ? { signal } : {}) }); }
|
|
212
|
+
stop(conversation, timeoutMs = 300_000) { return this.run(['vm', 'stop', this.vmOf(conversation)], { timeoutMs }); }
|
|
199
213
|
/* Stopped without waiting for the system inside: after a clean stop hung. */
|
|
200
|
-
kill(conversation) { return this.run(['vm', 'kill',
|
|
214
|
+
kill(conversation) { return this.run(['vm', 'kill', this.vmOf(conversation)], { timeoutMs: 300_000 }); }
|
|
201
215
|
/* STOPPED FOR SURE, step by step (the host program's `vm halt`): a polite stop, a stop by force,
|
|
202
216
|
then its own qemu ended (SIGTERM, SIGKILL), then checked. `from`/`until`: the first and last
|
|
203
217
|
step (polite|force|term|kill; until force|kill). Each `step ...` line is told to `onLine`. */
|
|
204
218
|
halt(conversation, { from = 'polite', until = 'kill', onLine, signal } = {}) {
|
|
205
|
-
return this.run(['vm', 'halt',
|
|
219
|
+
return this.run(['vm', 'halt', this.vmOf(conversation), from, until], { timeoutMs: HALT_MS, onLine, signal });
|
|
206
220
|
}
|
|
207
221
|
/* "Force stop", as a power cut: its qemu ended, nothing asked of the VM manager (`vm hardstop`). */
|
|
208
|
-
hardstop(conversation, { onLine, signal } = {}) { return this.run(['vm', 'hardstop',
|
|
222
|
+
hardstop(conversation, { onLine, signal } = {}) { return this.run(['vm', 'hardstop', this.vmOf(conversation)], { timeoutMs: HARDSTOP_MS, onLine, signal }); }
|
|
209
223
|
/* Memory in megabytes, disk in gigabytes: only on a stopped machine. */
|
|
210
|
-
setMemory(conversation, mb) { return this.run(['vm', 'set',
|
|
211
|
-
setCpus(conversation, n) { return this.run(['vm', 'set',
|
|
212
|
-
setDisk(conversation, gb) { return this.run(['vm', 'set',
|
|
224
|
+
setMemory(conversation, mb) { return this.run(['vm', 'set', this.vmOf(conversation), 'memory', String(mb)], { timeoutMs: 120_000 }); }
|
|
225
|
+
setCpus(conversation, n) { return this.run(['vm', 'set', this.vmOf(conversation), 'cpus', String(n)], { timeoutMs: 120_000 }); }
|
|
226
|
+
setDisk(conversation, gb) { return this.run(['vm', 'set', this.vmOf(conversation), 'disk', String(gb)], { timeoutMs: 600_000 }); }
|
|
213
227
|
/* What the machine really has: { memoryMb, diskGb }, each undefined when it cannot be told. */
|
|
214
228
|
async size(conversation) {
|
|
215
|
-
const r = await this.run(['vm', 'size',
|
|
229
|
+
const r = await this.run(['vm', 'size', this.vmOf(conversation)], { timeoutMs: 60_000 });
|
|
216
230
|
if (r.code !== 0) return { memoryMb: undefined, diskGb: undefined };
|
|
217
231
|
const line = (key) => new RegExp(`^${key} (\\S+)$`, 'm').exec(r.stdout ?? '')?.[1];
|
|
218
232
|
const mb = megabytes(line('memory'));
|
|
@@ -221,9 +235,9 @@ export class Vms {
|
|
|
221
235
|
return { memoryMb: mb === undefined ? undefined : Math.round(mb), diskGb: disk === undefined ? undefined : Math.round(disk / 1024), cpus };
|
|
222
236
|
}
|
|
223
237
|
/* Its steps (`step suspend ...`, then a wake and sleep again, then a clean stop) told to `onLine`. */
|
|
224
|
-
suspend(conversation, { signal, onLine } = {}) { return this.run(['vm', 'suspend',
|
|
238
|
+
suspend(conversation, { signal, onLine } = {}) { return this.run(['vm', 'suspend', this.vmOf(conversation)], { timeoutMs: 600_000, ...(signal ? { signal } : {}), ...(onLine ? { onLine } : {}) }); }
|
|
225
239
|
/* Free the RAM of a machine that is asleep but whose qemu still holds it (a
|
|
226
240
|
suspend that did not end the process): wake+resleep, then a clean stop. */
|
|
227
|
-
reclaim(conversation) { return this.run(['vm', 'reclaim',
|
|
228
|
-
remove(conversation) { return this.run(['vm', 'delete',
|
|
241
|
+
reclaim(conversation) { return this.run(['vm', 'reclaim', this.vmOf(conversation)], { timeoutMs: 300_000 }); }
|
|
242
|
+
remove(conversation) { return this.run(['vm', 'delete', this.vmOf(conversation)], { timeoutMs: 300_000 }); }
|
|
229
243
|
}
|