@runuai/host 0.8.6 → 0.8.7

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.
@@ -212,6 +212,7 @@ export class CursorSession implements AgentSession {
212
212
  "--stream-partial-output",
213
213
  "--force", // container is the sandbox — auto-run tools
214
214
  "--trust", // skip the workspace-trust prompt in headless
215
+ "--approve-mcps", // load the gateway MCP servers from ~/.cursor/mcp.json (ADR-057)
215
216
  );
216
217
  if (this.model && this.model !== "auto") args.push("-m", this.model);
217
218
  if (this.sessionId) args.push("--resume", this.sessionId);
@@ -270,16 +270,20 @@ export function startMcpGateway(): void {
270
270
 
271
271
  // --- task container wiring (ADR-057 task-up writers) -------------------------
272
272
 
273
- /** Idempotent node -e merge of entries into /workspace/.mcp.json. */
273
+ /** Idempotent node -e merge of entries (argv[2]) into an mcpServers file
274
+ * (argv[1]) — reused for Claude's /workspace/.mcp.json and Cursor's
275
+ * ~/.cursor/mcp.json. Creates the parent dir when missing. */
274
276
  const MERGE_MCP_JSON = `
275
277
  const fs = require("fs");
276
- const p = "/workspace/.mcp.json";
278
+ const path = require("path");
279
+ const p = process.argv[1];
280
+ try { fs.mkdirSync(path.dirname(p), { recursive: true }); } catch {}
277
281
  let j = {};
278
282
  let existed = true;
279
283
  try { j = JSON.parse(fs.readFileSync(p, "utf8")); } catch { existed = false; }
280
284
  j.mcpServers = j.mcpServers || {};
281
285
  let changed = false;
282
- for (const [k, v] of Object.entries(JSON.parse(process.argv[1]))) {
286
+ for (const [k, v] of Object.entries(JSON.parse(process.argv[2]))) {
283
287
  if (JSON.stringify(j.mcpServers[k]) !== JSON.stringify(v)) { j.mcpServers[k] = v; changed = true; }
284
288
  }
285
289
  if (changed || !existed) fs.writeFileSync(p, JSON.stringify(j, null, 2) + "\\n");
@@ -290,16 +294,21 @@ function shellQuote(value: string): string {
290
294
  }
291
295
 
292
296
  /**
293
- * Write the task's MCP configs inside the container: gateway-URL entries per
294
- * connection for Claude (/workspace/.mcp.json, merged coexists with the
295
- * ADR-053 browser server) and mcp-remote shims for Codex (config.toml,
296
- * append-once per slug). Safe to re-run every ensure.
297
+ * Write the task's MCP configs inside the container, one shape per engine on
298
+ * the roster all pointing at the same host gateway URLs:
299
+ * - Claude /workspace/.mcp.json (merged; coexists with the ADR-053 browser
300
+ * server). Written unconditionally: the adapter passes `--mcp-config`.
301
+ * - Codex — mcp-remote shims appended once per slug to config.toml.
302
+ * - Cursor — ~/.cursor/mcp.json ({ url } form; the adapter passes
303
+ * `--approve-mcps`).
304
+ * - Grok — `grok mcp add` writes ~/.grok/config.toml (idempotent per slug).
305
+ * Safe to re-run every ensure. `engineKinds` is the roster's agent kinds.
297
306
  */
298
307
  export async function setupMcpTaskConfig(
299
308
  taskId: string,
300
309
  containerName: string,
301
310
  connections: TaskMcpConnection[],
302
- hasCodex: boolean,
311
+ engineKinds: string[],
303
312
  ): Promise<void> {
304
313
  // No early return on empty: the claude adapter passes
305
314
  // `--mcp-config /workspace/.mcp.json` unconditionally (ADR-057), so the
@@ -308,18 +317,25 @@ export async function setupMcpTaskConfig(
308
317
  const acl = ensureTaskGatewayAcl(taskId, connections);
309
318
  const urlFor = (slug: string): string =>
310
319
  `http://host.docker.internal:${MCP_GATEWAY_PORT}/t/${acl.token}/${slug}`;
320
+ const has = (kind: string): boolean => engineKinds.includes(kind);
311
321
 
312
322
  const claudeEntries: Record<string, unknown> = {};
323
+ const cursorEntries: Record<string, unknown> = {};
313
324
  for (const c of connections) {
314
325
  claudeEntries[c.slug] = { type: "http", url: urlFor(c.slug) };
326
+ // Cursor's mcp.json wants a bare { url } for remote (http/sse) servers.
327
+ cursorEntries[c.slug] = { url: urlFor(c.slug) };
315
328
  }
316
329
  const steps = [
317
330
  "mkdir -p /workspace/.claude",
318
331
  `[ -f /workspace/.claude/settings.json ] || printf '%s\\n' ${shellQuote(
319
332
  JSON.stringify({ enableAllProjectMcpServers: true }, null, 2),
320
333
  )} > /workspace/.claude/settings.json`,
321
- `node -e ${shellQuote(MERGE_MCP_JSON)} ${shellQuote(JSON.stringify(claudeEntries))}`,
322
- ...(hasCodex
334
+ `node -e ${shellQuote(MERGE_MCP_JSON)} /workspace/.mcp.json ${shellQuote(
335
+ JSON.stringify(claudeEntries),
336
+ )}`,
337
+ // Codex: stdio-only, so each connection is an mcp-remote shim.
338
+ ...(has("codex")
323
339
  ? connections.map(
324
340
  (c) =>
325
341
  `grep -q "mcp_servers.${c.slug}]" /home/node/.codex/config.toml 2>/dev/null || printf '%s' ${shellQuote(
@@ -327,6 +343,23 @@ export async function setupMcpTaskConfig(
327
343
  )} >> /home/node/.codex/config.toml`,
328
344
  )
329
345
  : []),
346
+ // Cursor: reads ~/.cursor/mcp.json (the adapter passes --approve-mcps).
347
+ ...(has("cursor") && connections.length > 0
348
+ ? [
349
+ `node -e ${shellQuote(MERGE_MCP_JSON)} /home/node/.cursor/mcp.json ${shellQuote(
350
+ JSON.stringify(cursorEntries),
351
+ )}`,
352
+ ]
353
+ : []),
354
+ // Grok: `grok mcp add` writes ~/.grok/config.toml. Idempotent + tolerant.
355
+ ...(has("grok")
356
+ ? connections.map(
357
+ (c) =>
358
+ `/home/node/.local/bin/grok mcp add ${shellQuote(c.slug)} ${shellQuote(
359
+ urlFor(c.slug),
360
+ )} -t http -s user >/dev/null 2>&1 || true`,
361
+ )
362
+ : []),
330
363
  ].join(" && ");
331
364
  const result = await dockerCli(
332
365
  ["exec", containerName, "sh", "-lc", steps],
@@ -172,6 +172,14 @@ class Orchestrator {
172
172
  /** Fold a fresh channel spec into a live channel (ADR-049). */
173
173
  private refreshChannel(channel: Channel, spec: ChannelEnsureInput): void {
174
174
  const known = new Set(channel.roster.map((a) => a.id));
175
+ // Replace EXISTING agents' data with the fresh spec — a mid-task roster edit
176
+ // can change permissions, model, brief, role or skills, and without this the
177
+ // stale snapshot persists (e.g. granting `uai` CLI permissions mid-task never
178
+ // took effect: writeAgentCli kept seeing the old empty list). Swapping the
179
+ // object (not merging) also drops fields that were removed. The token/model a
180
+ // LIVE session already carries only changes on its next respawn.
181
+ const bySpecId = new Map(spec.agents.map((a) => [a.id, a]));
182
+ channel.roster = channel.roster.map((a) => bySpecId.get(a.id) ?? a);
175
183
  for (const agent of spec.agents) {
176
184
  if (!known.has(agent.id)) {
177
185
  channel.roster.push(agent);
@@ -321,7 +329,7 @@ class Orchestrator {
321
329
  channel.taskId,
322
330
  channel.containerName,
323
331
  channel.mcpConnections,
324
- channel.roster.some((a) => a.kind === "codex"),
332
+ channel.roster.map((a) => a.kind),
325
333
  );
326
334
  // Agent CLIs read MCP servers once, at process start — and durable
327
335
  // sessions (ADR-061) make processes long-lived, so without this a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runuai/host",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "Uai host — runs ephemeral AI coding tasks in Docker on a machine you control.",
5
5
  "license": "MIT",
6
6
  "author": "Diogo Perillo <diogo.perillo@gmail.com>",
@@ -75,10 +75,10 @@
75
75
  "zod": "^3.23.8"
76
76
  },
77
77
  "devDependencies": {
78
- "@typescript-eslint/eslint-plugin": "^8.59.4",
79
- "@typescript-eslint/parser": "^8.59.4",
80
78
  "@types/node": "^22.9.0",
81
79
  "@types/ws": "^8.18.1",
80
+ "@typescript-eslint/eslint-plugin": "^8.59.4",
81
+ "@typescript-eslint/parser": "^8.59.4",
82
82
  "eslint": "^9.14.0",
83
83
  "typescript": "^5.6.3",
84
84
  "vitest": "^2.1.4"
package/src/ui/server.ts CHANGED
@@ -365,6 +365,8 @@ const STATIC_FILES: Record<string, string> = {
365
365
  "/index.html": "index.html",
366
366
  "/style.css": "style.css",
367
367
  "/app.js": "app.js",
368
+ "/uai-wheel.svg": "uai-wheel.svg",
369
+ "/uai-favicon.svg": "uai-favicon.svg",
368
370
  "/uai-logo-black.svg": "uai-logo-black.svg",
369
371
  };
370
372
 
package/ui/index.html CHANGED
@@ -5,14 +5,14 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Uai host</title>
7
7
  <!-- Local monitor UI (ADR-028). Served from 127.0.0.1 by the host service. -->
8
- <link rel="icon" type="image/svg+xml" href="/uai-logo-black.svg" />
8
+ <link rel="icon" type="image/svg+xml" href="/uai-favicon.svg" />
9
9
  <link rel="stylesheet" href="/style.css" />
10
10
  </head>
11
11
  <body>
12
12
  <main>
13
13
  <header class="topbar">
14
14
  <div class="brand">
15
- <img class="logo" src="/uai-logo-black.svg" alt="Uai" />
15
+ <img class="logo" src="/uai-wheel.svg" alt="Uai" />
16
16
  <div class="brand-text">
17
17
  <div class="host-name" id="host-name">…</div>
18
18
  <div class="host-sub" id="host-sub">host monitor</div>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 341.02 341.02">
3
+ <defs>
4
+ <style>
5
+ .cls-1 {
6
+ fill: #231f20;
7
+ }
8
+
9
+ .cls-2 {
10
+ fill: #fff;
11
+ }
12
+ </style>
13
+ </defs>
14
+ <g id="Layer_1-2" data-name="Layer 1">
15
+ <rect class="cls-1" x="0" width="341.02" height="341.02"/>
16
+ <g>
17
+ <path class="cls-2" d="M170.51,43.13c-70.35,0-127.37,57.03-127.37,127.37s57.03,127.37,127.37,127.37,127.37-57.03,127.37-127.37-57.03-127.37-127.37-127.37ZM170.51,269.54c-54.69,0-99.03-44.34-99.03-99.03s44.34-99.03,99.03-99.03,99.03,44.34,99.03,99.03-44.34,99.03-99.03,99.03Z"/>
18
+ <path class="cls-2" d="M170.59,99.55c-4.31,0-8.53.4-12.63,1.14l-53.93,95.15c3.15,8.33,7.81,15.91,13.65,22.41h105.8c5.74-6.39,10.34-13.82,13.48-21.98l-54.22-95.67c-3.96-.68-8.02-1.06-12.17-1.06ZM194.08,169.79c0,13.02-10.55,23.57-23.57,23.57s-23.57-10.55-23.57-23.57,10.55-23.57,23.57-23.57,23.57,10.55,23.57,23.57Z"/>
19
+ </g>
20
+ </g>
21
+ </svg>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Uai "wheel" mark (brand 8a5db40). Dark fill on transparent bg so the
3
+ header's dark-mode `filter: invert(1)` renders it white on dark. -->
4
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 341.02 341.02">
5
+ <g fill="#231f20">
6
+ <path d="M170.51,43.13c-70.35,0-127.37,57.03-127.37,127.37s57.03,127.37,127.37,127.37,127.37-57.03,127.37-127.37-57.03-127.37-127.37-127.37ZM170.51,269.54c-54.69,0-99.03-44.34-99.03-99.03s44.34-99.03,99.03-99.03,99.03,44.34,99.03,99.03-44.34,99.03-99.03,99.03Z"/>
7
+ <path d="M170.59,99.55c-4.31,0-8.53.4-12.63,1.14l-53.93,95.15c3.15,8.33,7.81,15.91,13.65,22.41h105.8c5.74-6.39,10.34-13.82,13.48-21.98l-54.22-95.67c-3.96-.68-8.02-1.06-12.17-1.06ZM194.08,169.79c0,13.02-10.55,23.57-23.57,23.57s-23.57-10.55-23.57-23.57,10.55-23.57,23.57-23.57,23.57,10.55,23.57,23.57Z"/>
8
+ </g>
9
+ </svg>