@vortex-os/computer-use 0.1.0 → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vortex-os/computer-use",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Add-on — read-only screen perception (structured UIA tree + pixel fallback + change watch) exposed as an MCP server, layered on @vortex-os/base. Windows-first. Control (mouse/keyboard) is intentionally out of scope.",
5
5
  "license": "MIT",
6
6
  "author": "vortex-os-project",
@@ -24,6 +24,14 @@
24
24
  "bin": {
25
25
  "vortex-mcp-computer-use": "scripts/mcp-stdio.mjs"
26
26
  },
27
+ "vortex": {
28
+ "mcpServers": {
29
+ "vortex-computer-use": {
30
+ "command": "node",
31
+ "args": ["node_modules/@vortex-os/computer-use/scripts/mcp-stdio.mjs"]
32
+ }
33
+ }
34
+ },
27
35
  "scripts": {
28
36
  "verify": "node scripts/verify.mjs"
29
37
  },
@@ -1,15 +1,19 @@
1
1
  #!/usr/bin/env node
2
- // computer-use — MCP stdio server (PoC). Exposes the CLI dispatcher (action-ext.mjs) as MCP tools.
3
- // Same backend logic (OS-native). Tools: probe · read_ui · capture_screen.
4
- // Depends on: @modelcontextprotocol/sdk (pulled in by memory-extended, present in the instance node_modules).
5
- // In the real add-on this ships packaged as scripts/mcp-stdio.mjs + bin vortex-mcp-action (design §21).
2
+ // @vortex-os/computer-use — read-only screen-perception MCP stdio server (Windows-first).
3
+ // Tools: probe · read_ui · capture_screen · watch_capture · poll_change · beep. Control is out of scope.
4
+ // Two modes (bin `vortex-mcp-computer-use`):
5
+ // - default: run the stdio server (what an MCP host launches).
6
+ // - `install`: self-register into the project `.mcp.json` under the non-reserved key
7
+ // `vortex-computer-use` (merge-safe). e.g. `npx vortex-mcp-computer-use install`.
8
+ // Optional dep: @modelcontextprotocol/sdk (declared optional; imported by this entry — `install`
9
+ // just registers and exits without connecting a transport).
6
10
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
11
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
12
  import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
9
13
  import { spawnSync, spawn } from 'node:child_process';
10
14
  import { fileURLToPath } from 'node:url';
11
15
  import { dirname, join } from 'node:path';
12
- import { readFileSync, unlinkSync, statSync, mkdtempSync, rmSync, existsSync, mkdirSync, writeFileSync, appendFileSync } from 'node:fs';
16
+ import { readFileSync, unlinkSync, statSync, mkdtempSync, rmSync, existsSync, mkdirSync, writeFileSync, renameSync, appendFileSync } from 'node:fs';
13
17
  import { tmpdir, homedir } from 'node:os';
14
18
  import { createHmac, randomBytes } from 'node:crypto';
15
19
 
@@ -541,6 +545,73 @@ process.on('exit', () => workerMgr.dispose());
541
545
  process.on('SIGINT', () => process.exit(0));
542
546
  process.on('SIGTERM', () => process.exit(0));
543
547
 
544
- const transport = new StdioServerTransport();
545
- await server.connect(transport);
546
- process.stderr.write(`[computer-use MCP] ready on stdio (worker=${plat === 'win32' ? 'on' : 'off'}; tools: probe, read_ui, capture_screen, watch_capture, poll_change, beep)\n`);
548
+ // ── install mode: self-register into the project .mcp.json (stage 1) ─────────
549
+ // `vortex-mcp-computer-use install [--path <file>]` — merge-safe registration. ALWAYS uses the
550
+ // non-reserved key "vortex-computer-use" (the host reserves "computer-use" and silently won't load
551
+ // it), preserves every other server + top-level field, and refuses to overwrite a malformed file.
552
+ const SERVER_KEY = 'vortex-computer-use';
553
+ const SERVER_ENTRY = { command: 'node', args: ['node_modules/@vortex-os/computer-use/scripts/mcp-stdio.mjs'] };
554
+
555
+ const isObjLit = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
556
+ const refuse = (msg) => { process.stderr.write(`[install] ${msg}\n`); process.exit(1); };
557
+
558
+ function runInstall(argv) {
559
+ const i = argv.indexOf('--path');
560
+ let target;
561
+ if (i >= 0) {
562
+ const v = argv[i + 1];
563
+ if (!v || v.startsWith('--')) refuse('--path requires a file path argument.');
564
+ target = v;
565
+ } else {
566
+ target = join(process.cwd(), '.mcp.json');
567
+ }
568
+ let existing = {};
569
+ if (existsSync(target)) {
570
+ let txt;
571
+ try { txt = readFileSync(target, 'utf8').trim(); }
572
+ catch (e) { refuse(`${target} could not be read — left untouched: ${e.message}`); }
573
+ if (txt) {
574
+ let parsed;
575
+ try { parsed = JSON.parse(txt); }
576
+ catch (e) { refuse(`${target} is not valid JSON — refusing to overwrite (fix it first): ${e.message}`); }
577
+ if (!isObjLit(parsed)) refuse(`${target} is not a JSON object — refusing to overwrite.`);
578
+ if (parsed.mcpServers !== undefined && !isObjLit(parsed.mcpServers)) refuse(`${target} has a non-object "mcpServers" — refusing to overwrite.`);
579
+ existing = parsed;
580
+ }
581
+ }
582
+ const servers = isObjLit(existing.mcpServers) ? existing.mcpServers : {};
583
+ // ADD-ONLY: never clobber an existing "vortex-computer-use" entry (the user may have customized it).
584
+ if (Object.prototype.hasOwnProperty.call(servers, SERVER_KEY)) {
585
+ process.stdout.write(JSON.stringify({ ok: true, action: 'already-present', path: target, serverKey: SERVER_KEY }, null, 2) + '\n');
586
+ process.stderr.write(`[install] "${SERVER_KEY}" already registered in ${target} — left unchanged.\n`);
587
+ return;
588
+ }
589
+ const preserved = Object.keys(servers);
590
+ const merged = { ...existing, mcpServers: { ...servers, [SERVER_KEY]: SERVER_ENTRY } };
591
+ // Atomic write via a PRIVATE temp dir (random name, not a guessable sibling): write inside with
592
+ // exclusive-create, rename onto the target, then remove the dir. Avoids following a pre-placed
593
+ // temp symlink and leaves no stray temp on failure (codex r2 MEDIUM).
594
+ try { mkdirSync(dirname(target), { recursive: true }); } catch {}
595
+ const tmpDir = mkdtempSync(join(dirname(target), '.mcp-cu-'));
596
+ const tmp = join(tmpDir, 'mcp.json');
597
+ try {
598
+ writeFileSync(tmp, JSON.stringify(merged, null, 2) + '\n', { encoding: 'utf8', flag: 'wx' });
599
+ renameSync(tmp, target);
600
+ } finally {
601
+ try { rmSync(tmpDir, { recursive: true, force: true }); } catch {}
602
+ }
603
+ process.stdout.write(JSON.stringify({ ok: true, action: 'added', path: target, serverKey: SERVER_KEY, preservedServers: preserved }, null, 2) + '\n');
604
+ process.stderr.write(
605
+ `[install] added "${SERVER_KEY}" in ${target}` +
606
+ (preserved.length ? ` (kept: ${preserved.join(', ')})` : '') + '\n' +
607
+ `[install] Restart the agent — or approve the new MCP server when prompted — to load the computer-use tools.\n`,
608
+ );
609
+ }
610
+
611
+ if (process.argv.slice(2).includes('install')) {
612
+ runInstall(process.argv.slice(2));
613
+ } else {
614
+ const transport = new StdioServerTransport();
615
+ await server.connect(transport);
616
+ process.stderr.write(`[computer-use MCP] ready on stdio (worker=${plat === 'win32' ? 'on' : 'off'}; tools: probe, read_ui, capture_screen, watch_capture, poll_change, beep)\n`);
617
+ }