clavarium 0.2.503-next.1 → 0.2.505-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.
@@ -31,7 +31,7 @@
31
31
  */
32
32
  import { spawnSync } from 'node:child_process';
33
33
  import { randomUUID } from 'node:crypto';
34
- import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
34
+ import { existsSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
35
35
  import { dirname, join } from 'node:path';
36
36
  import { fileURLToPath } from 'node:url';
37
37
 
@@ -138,6 +138,8 @@ if (main) {
138
138
  if (CODE.test(code)) {
139
139
  spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, '-l', '--', code], { timeout: 5000 });
140
140
  spawnSync('tmux', [...tmux, 'send-keys', '-t', pane, 'Enter'], { timeout: 5000 });
141
+ /* Typed: the ask is over, so the next message that looks like a code is a secret again (#394). */
142
+ try { rmSync(`${chat}/signin-ask.json`, { force: true }); } catch { /* left: it runs out on the server's side */ }
141
143
  awaiting = null; return;
142
144
  }
143
145
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.503-next.1",
3
+ "version": "0.2.505-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.503-next.1",
9
+ "version": "0.2.505-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.503-next.1",
3
+ "version": "0.2.505-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/main.mjs CHANGED
@@ -592,6 +592,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
592
592
  the chat shows as stars; the value reaches the machine as
593
593
  /run/secrets/<name>, and is swept after a few minutes. */
594
594
  screen: async (conversation, text) => {
595
+ /* A sign-in code its tool waits for (#394): left whole, screen-watch types it in. */
596
+ if (signinHelp?.awaitsCode(conversation, text)) return text;
595
597
  const hits = scan(text);
596
598
  if (!hits.length) return text;
597
599
  let out = ''; let last = 0; let any = false;
package/server/mcpx.mjs CHANGED
@@ -68,6 +68,17 @@ export async function mcpAdd({ tethers, secrets }, body = {}) {
68
68
  return scrub(shown(r.data), key);
69
69
  }
70
70
 
71
+ /* Where a pasted block keeps its servers (20-11, the owner: not all say "mcpServers"): "mcpServers" (Claude, Cursor,
72
+ Windsurf), "servers" (VS Code's mcp.json), "mcp": { "servers" } (VS Code's settings), "mcp" (OpenCode),
73
+ "context_servers" (Zed), or one server by itself ({ "url": ... }). */
74
+ const OBJ = (x) => (x && typeof x === 'object' && !Array.isArray(x) ? x : null);
75
+ export function serversOf(j) {
76
+ if (!OBJ(j)) return null;
77
+ const one = j.url || j.serverUrl || j.httpUrl;
78
+ return OBJ(j.mcpServers) ?? OBJ(j.servers) ?? OBJ(OBJ(j.mcp)?.servers) ?? (OBJ(j.mcp) && !OBJ(j.mcp).servers ? j.mcp : null) ?? OBJ(j.context_servers) ?? (one ? { [j.name || 'mcp']: j } : null);
79
+ }
80
+ /* A program to start, whatever its tool calls it (OpenCode: "type": "local", its command a list). */
81
+ const isProgram = (s) => s.command !== undefined || s.args !== undefined || s.type === 'stdio' || s.type === 'local';
71
82
  /* IMPORT a pasted { "mcpServers": { name: { url, headers: { Authorization: "Bearer ${NAME}" } } } }: each key a
72
83
  reference to a secret of the vault (none written in it), no program to start. -> the targets made. */
73
84
  export async function mcpImport({ tethers, secrets }, body = {}) {
@@ -75,13 +86,13 @@ export async function mcpImport({ tethers, secrets }, body = {}) {
75
86
  if (typeof config === 'string') {
76
87
  try { config = JSON.parse(config); } catch { throw new Refusal(400, 'That is not JSON: paste the whole { "mcpServers": ... } block.'); }
77
88
  }
78
- const all = config && typeof config === 'object' ? (config.mcpServers ?? config.servers) : null;
89
+ const all = serversOf(config);
79
90
  if (!all || typeof all !== 'object' || Array.isArray(all) || !Object.keys(all).length) throw new Refusal(400, 'Paste a block like { "mcpServers": { "name": { "url": "https://...", "headers": { "Authorization": "Bearer ${SECRET}" } } } }.');
80
91
  const servers = {};
81
92
  for (const [name, s] of Object.entries(all)) {
82
93
  const label = String(name).slice(0, 60);
83
94
  if (!s || typeof s !== 'object' || Array.isArray(s)) throw new Refusal(400, `${label}: not a server.`);
84
- if (s.command !== undefined || s.args !== undefined || s.type === 'stdio') throw new Refusal(400, `${label}: a program to start (stdio) is not run here. Only a server reached by its address.`);
95
+ if (isProgram(s)) throw new Refusal(400, `${label}: a program to start (stdio) is not run here. Only a server reached by its address.`);
85
96
  const heads = s.headers && typeof s.headers === 'object' && !Array.isArray(s.headers) ? Object.entries(s.headers) : [];
86
97
  if (heads.length > 1) throw new Refusal(400, `${label}: one header for the key at most.`);
87
98
  for (const [h, v] of heads) {
@@ -91,7 +102,7 @@ export async function mcpImport({ tethers, secrets }, body = {}) {
91
102
  if (!REF.test(m[2]) || !known(secrets, m[2])) throw new Refusal(400, `${label}: no secret named ${m[2].slice(0, 60)} here. Add it in Secrets first.`);
92
103
  }
93
104
  if (s.env && typeof s.env === 'object' && Object.keys(s.env).length) throw new Refusal(400, `${label}: "env" is for a program to start. Only a server reached by its address.`);
94
- servers[name] = { url: s.url ?? s.serverUrl, ...(heads.length ? { headers: Object.fromEntries(heads) } : {}), ...(s.allowHttp === true ? { allowHttp: true } : {}) };
105
+ servers[name] = { url: s.url ?? s.serverUrl ?? s.httpUrl, ...(heads.length ? { headers: Object.fromEntries(heads) } : {}), ...(s.allowHttp === true ? { allowHttp: true } : {}) };
95
106
  }
96
107
  const r = await tethers.act('mcp-import', { config: { mcpServers: servers } }, '');
97
108
  if (!r.ok) throw new Refusal(400, r.text);
@@ -40,6 +40,8 @@ export const ROUTE = 'signin-route.json';
40
40
  export const CHAT = '.parley';
41
41
  export const DOCKET = '.docket';
42
42
  export const WAIT_MS = 10 * 60_000;
43
+ /* How long after its tool asked a code pasted by the person is taken as that code (and not as a secret). */
44
+ export const CODE_WAIT_MS = 30 * 60_000;
43
45
  export const TICK_MS = 3000;
44
46
  export const NONE = 'none';
45
47
  const ASK_BYTES = 16_384;
@@ -143,6 +145,18 @@ export class SigninHelp {
143
145
  if (!this.#own(dir)) return;
144
146
  try { writeFileSync(join(dir, `.${ROUTE}.new`), JSON.stringify(route)); renameSync(join(dir, `.${ROUTE}.new`), join(dir, ROUTE)); } catch { /* its chat folder cannot be written: screen-watch tells the person itself */ }
145
147
  }
148
+ /* A CODE AWAITED FROM THE PERSON (20-11, #394): its tool asked to sign in, the link was told to the person (not
149
+ handed to a companion), a short while ago. Then a message that is nothing but a code is that code: typed into
150
+ the tool by screen-watch, never lifted out as a secret (19-11: « code#state » kept as two secrets, the tool
151
+ never got it). */
152
+ awaitsCode(name, text) {
153
+ if (!CODE.test(String(text ?? '').trim())) return false;
154
+ const ask = this.#readAsk(name); if (!ask) return false;
155
+ const at = Date.parse(ask.at); if (!Number.isFinite(at) || this.#now() - at > CODE_WAIT_MS || at > this.#now() + 60_000) return false;
156
+ if (ask.told === true) return true;
157
+ const route = this.#readRoute(name);
158
+ return route?.id === ask.id && route.route === 'person';
159
+ }
146
160
  #readRoute(name) { try { return JSON.parse(readFileSync(join(this.#chat(name), ROUTE), 'utf8')); } catch { return null; } }
147
161
  #line(name, line) { try { this.#event(name, line); } catch { /* its chat may be off */ } }
148
162
  #tool(name) { const id = this.#conversations().find((c) => c.name === name)?.tool; return this.#tools().find((t) => t.id === id); }
package/web/app.js CHANGED
@@ -10905,15 +10905,27 @@
10905
10905
  naming its keys as secrets (${NAME}) is imported as it is; a program to start (stdio) is not run here. */
10906
10906
  const mcpWord = (k, en, v) => uiSaid(k, en, v);
10907
10907
  const mcpMask = (k) => (k.length <= 8 ? '••••' : `${k.slice(0, 4)}••••${k.slice(-3)}`);
10908
+ /* Where a pasted block keeps its servers (20-11, the owner: not all say "mcpServers"): "mcpServers" (Claude, Cursor,
10909
+ Windsurf), "servers" (VS Code's mcp.json), "mcp": { "servers" } (VS Code's settings), "mcp" (OpenCode),
10910
+ "context_servers" (Zed), or one server by itself ({ "url": ... }). */
10911
+ const OBJ = (x) => (x && typeof x === 'object' && !Array.isArray(x) ? x : null);
10912
+ function serversOf(j) {
10913
+ if (!OBJ(j)) return null;
10914
+ const one = j.url || j.serverUrl || j.httpUrl;
10915
+ return OBJ(j.mcpServers) ?? OBJ(j.servers) ?? OBJ(OBJ(j.mcp)?.servers) ?? (OBJ(j.mcp) && !OBJ(j.mcp).servers ? j.mcp : null) ?? OBJ(j.context_servers) ?? (one ? { [j.name || 'mcp']: j } : null);
10916
+ }
10917
+ /* A program to start, whatever its tool calls it (OpenCode: "type": "local", its command a list). */
10918
+ const isProgram = (s) => s.command !== undefined || s.args !== undefined || s.type === 'stdio' || s.type === 'local';
10919
+
10908
10920
  function mcpRead(text) {
10909
10921
  let j;
10910
10922
  try { j = JSON.parse(text); } catch { return { error: mcpWord('set-mcp-notjson', 'Not JSON: paste the whole block.') }; }
10911
- const all = j && typeof j === 'object' ? (j.mcpServers ?? j.servers ?? (j.url || j.serverUrl ? { [j.name || 'mcp']: j } : null)) : null;
10923
+ const all = serversOf(j);
10912
10924
  if (!all || typeof all !== 'object' || Array.isArray(all) || !Object.keys(all).length) return { error: mcpWord('set-mcp-noserver', 'No server in this block.') };
10913
10925
  const servers = []; let refs = false;
10914
10926
  for (const [name, s] of Object.entries(all)) {
10915
10927
  if (!s || typeof s !== 'object') return { error: mcpWord('set-mcp-noserver', 'No server in this block.') };
10916
- if (s.command !== undefined || s.args !== undefined || s.type === 'stdio') return { error: mcpWord('set-mcp-program', '« {name} »: a program to start, refused here.', { name }) };
10928
+ if (isProgram(s)) return { error: mcpWord('set-mcp-program', '« {name} »: a program to start, refused here.', { name }) };
10917
10929
  const heads = s.headers && typeof s.headers === 'object' ? Object.entries(s.headers) : [];
10918
10930
  if (heads.length > 1) return { error: mcpWord('set-mcp-heads', '« {name} »: one header for its key at most.', { name }) };
10919
10931
  let key = '', header = '';
@@ -10924,7 +10936,7 @@
10924
10936
  if (h.toLowerCase() === 'authorization') { if (!bearer) return { error: mcpWord('set-mcp-basic', '« {name} »: not a « Bearer » key, fill in by hand.', { name }) }; key = bearer[1].trim(); }
10925
10937
  else { key = value; header = h; }
10926
10938
  }
10927
- servers.push({ name: String(name).slice(0, 120), url: String(s.url ?? s.serverUrl ?? ''), key, header });
10939
+ servers.push({ name: String(name).slice(0, 120), url: String(s.url ?? s.serverUrl ?? s.httpUrl ?? ''), key, header });
10928
10940
  }
10929
10941
  return { servers, refs };
10930
10942
  }