capix-code 1.4.5 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capix-code",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "Capix Code — decentralized AI coding agent with GPU marketplace",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -4,7 +4,6 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const os = require('os');
6
6
 
7
- // Skip in CI environments
8
7
  if (process.env.CI || process.env.GITHUB_ACTIONS) {
9
8
  console.log('Skipping binary download in CI environment.');
10
9
  process.exit(0);
@@ -38,38 +37,74 @@ try {
38
37
 
39
38
  const customerSrc = path.join(tmpDir, 'customer');
40
39
  if (fs.existsSync(customerSrc)) {
41
- // Copy bin/ and engine/ and runtime/ to ~/.capix-code
42
- for (const dir of ['bin', 'engine', 'runtime', 'config', 'mcp']) {
40
+ for (const dir of ['bin', 'engine', 'runtime', 'config']) {
43
41
  const src = path.join(customerSrc, dir);
44
42
  const dst = path.join(installDir, dir);
45
43
  if (fs.existsSync(src)) {
46
44
  execSync(`cp -a "${src}" "${dst}"`, { stdio: 'inherit' });
47
45
  }
48
46
  }
49
- // Ensure bin is executable
50
47
  const binPath = path.join(installDir, 'bin', 'capix-code');
51
48
  if (fs.existsSync(binPath)) {
52
49
  fs.chmodSync(binPath, 0o755);
53
50
  }
54
51
  }
55
52
 
56
- // Ensure MCP is available — download from npm if not in the tarball
53
+ // Install MCP server from npm
57
54
  const mcpDir = path.join(installDir, 'mcp');
58
55
  const mcpEntry = path.join(mcpDir, 'capix-mcp.js');
59
56
  if (!fs.existsSync(mcpEntry)) {
60
- console.log('Installing capix-mcp server...');
61
- try {
62
- execSync(`npm install capix-mcp@2.1.0 --prefix "${mcpDir}" 2>&1`, { stdio: 'inherit' });
63
- // Create a wrapper entry point
64
- fs.writeFileSync(mcpEntry, `#!/usr/bin/env node\nimport('${path.join(mcpDir, 'node_modules', 'capix-mcp', 'dist', 'index.js')}');\n`);
65
- fs.chmodSync(mcpEntry, 0o755);
66
- } catch (e) {
67
- console.warn(' capix-mcp install failed. Install manually: npm install -g capix-mcp');
68
- }
57
+ console.log('Installing capix-mcp server from npm...');
58
+ fs.mkdirSync(mcpDir, { recursive: true });
59
+ execSync(`npm install capix-mcp@2.1.0`, { cwd: mcpDir, stdio: 'inherit' });
60
+ // Create entry point wrapper that shares credentials with capix-code
61
+ const mcpPkgPath = path.join(mcpDir, 'node_modules', 'capix-mcp', 'dist', 'index.js');
62
+ fs.writeFileSync(mcpEntry,
63
+ '#!/usr/bin/env node\n' +
64
+ 'const { readFileSync, writeFileSync, chmodSync, existsSync } = require("node:fs");\n' +
65
+ 'const { join } = require("node:path");\n' +
66
+ 'const { homedir } = require("node:os");\n' +
67
+ 'const credPath = join(homedir(), ".capix-code", "credentials.json");\n' +
68
+ 'async function loadMcp() {\n' +
69
+ ' const mcpPath = join(homedir(), ".capix-code", "mcp", "node_modules", "capix-mcp", "dist", "index.js");\n' +
70
+ ` require('${mcpPkgPath}');\n` +
71
+ '}\n' +
72
+ '(async () => {\n' +
73
+ ' try {\n' +
74
+ ' if (existsSync(credPath)) {\n' +
75
+ ' const creds = JSON.parse(readFileSync(credPath, "utf8"));\n' +
76
+ ' const rt = creds["capix-code:oauth-refresh-token"];\n' +
77
+ ' if (rt) {\n' +
78
+ ' const res = await fetch("https://www.capix.network/oauth/token", {\n' +
79
+ ' method: "POST",\n' +
80
+ ' headers: { "Content-Type": "application/x-www-form-urlencoded" },\n' +
81
+ ' body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: rt, client_id: "capix-code" }).toString(),\n' +
82
+ ' });\n' +
83
+ ' const body = await res.json();\n' +
84
+ ' if (body.access_token) {\n' +
85
+ ' process.env.CAPIX_API_KEY = body.access_token;\n' +
86
+ ' creds["capix-code:oauth-refresh-token"] = body.refresh_token;\n' +
87
+ ' writeFileSync(credPath, JSON.stringify(creds, null, 2), { mode: 0o600 });\n' +
88
+ ' chmodSync(credPath, 0o600);\n' +
89
+ ' }\n' +
90
+ ' }\n' +
91
+ ' }\n' +
92
+ ' } catch {}\n' +
93
+ ' loadMcp();\n' +
94
+ '})();\n'
95
+ );
96
+ fs.chmodSync(mcpEntry, 0o755);
97
+ console.log('✓ capix-mcp installed with shared credentials');
69
98
  }
70
99
 
71
- fs.rmSync(tmpDir, { recursive: true, force: true });
100
+ // Always update the MCP wrapper (in case credentials path changed)
101
+ const existingMcp = path.join(mcpDir, 'capix-mcp.js');
102
+ if (fs.existsSync(existingMcp) && !fs.existsSync(path.join(mcpDir, 'node_modules', 'capix-mcp'))) {
103
+ // Reinstall if node_modules is missing
104
+ execSync(`npm install capix-mcp@2.1.0`, { cwd: mcpDir, stdio: 'inherit' });
105
+ }
72
106
 
107
+ fs.rmSync(tmpDir, { recursive: true, force: true });
73
108
  console.log(`✓ Capix Code v${VERSION} installed to ${installDir}`);
74
109
  console.log('Run: capix-code --version');
75
110
  } catch (err) {