@variantree/watcher 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@variantree/watcher",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Passive session file watcher and CLI for Variantree",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,8 @@
9
9
  "variantree": "./dist/cli.js"
10
10
  },
11
11
  "files": [
12
- "dist"
12
+ "dist",
13
+ "scripts"
13
14
  ],
14
15
  "scripts": {
15
16
  "build": "tsc",
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall script — registers the Variantree MCP server in all supported
4
+ * AI tool global configs (OpenCode, Claude Code).
5
+ *
6
+ * Runs automatically after `npm install -g @variantree/watcher`.
7
+ * Each registration is idempotent — skips if already configured.
8
+ */
9
+
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import os from 'node:os';
13
+
14
+ const MCP_COMMAND_NPXARGS = ['-y', '@variantree/mcp'];
15
+ const MCP_ENV = { VARIANTREE_DIR: '.' };
16
+
17
+ // ─── OpenCode ────────────────────────────────────────────────────────────────
18
+
19
+ function registerOpenCode() {
20
+ const configDir = process.env.XDG_CONFIG_HOME
21
+ ?? path.join(os.homedir(), '.config');
22
+ const configPath = path.join(configDir, 'opencode', 'opencode.json');
23
+
24
+ let config = {};
25
+ try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
26
+
27
+ if (!config.mcp) config.mcp = {};
28
+ if (config.mcp.variantree) return;
29
+
30
+ config.mcp.variantree = {
31
+ type: 'local',
32
+ command: ['npx', ...MCP_COMMAND_NPXARGS],
33
+ environment: MCP_ENV,
34
+ };
35
+
36
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
37
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', 'utf8');
38
+ console.log('[variantree] OpenCode: MCP server registered in', configPath);
39
+ }
40
+
41
+ // ─── Claude Code ─────────────────────────────────────────────────────────────
42
+
43
+ function registerClaudeCode() {
44
+ const configPath = path.join(os.homedir(), '.claude.json');
45
+
46
+ let config = {};
47
+ try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
48
+
49
+ if (!config.mcpServers) config.mcpServers = {};
50
+ if (config.mcpServers.variantree) return;
51
+
52
+ config.mcpServers.variantree = {
53
+ command: 'npx',
54
+ args: MCP_COMMAND_NPXARGS,
55
+ env: MCP_ENV,
56
+ };
57
+
58
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', 'utf8');
59
+ console.log('[variantree] Claude Code: MCP server registered in', configPath);
60
+ }
61
+
62
+ // ─── Run ─────────────────────────────────────────────────────────────────────
63
+
64
+ try { registerOpenCode(); } catch {}
65
+ try { registerClaudeCode(); } catch {}