capix-code 1.6.9 → 1.6.11
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 +1 -1
- package/scripts/postinstall.cjs +70 -91
package/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -4,118 +4,97 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
6
|
|
|
7
|
-
if (process.env.CI || process.env.GITHUB_ACTIONS) {
|
|
8
|
-
console.log('Skipping binary download in CI environment.');
|
|
9
|
-
process.exit(0);
|
|
10
|
-
}
|
|
7
|
+
if (process.env.CI || process.env.GITHUB_ACTIONS) { process.exit(0); }
|
|
11
8
|
|
|
12
9
|
const VERSION = '1.6.3';
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const platform = PLATFORM_MAP[process.platform] || 'linux';
|
|
16
|
-
const arch = ARCH_MAP[process.arch] || 'x64';
|
|
10
|
+
const plat = process.platform === 'win32' ? 'win32' : process.platform;
|
|
11
|
+
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
|
|
17
12
|
const ext = process.platform === 'win32' ? 'zip' : 'tar.gz';
|
|
18
|
-
const NAME = `capix-code-${VERSION}-${
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const tmpDir = path.join(os.tmpdir(), 'capix-code-install');
|
|
13
|
+
const NAME = `capix-code-${VERSION}-${plat}-${arch}-unsigned`;
|
|
14
|
+
const URL = `https://github.com/CapIX-Protocol/Capix-Code/releases/download/v${VERSION}/${NAME}.${ext}`;
|
|
15
|
+
const ROOT = path.join(os.homedir(), '.capix-code');
|
|
16
|
+
const TMP = path.join(os.tmpdir(), 'capix-code-install');
|
|
23
17
|
|
|
24
|
-
fs.mkdirSync(
|
|
25
|
-
fs.mkdirSync(
|
|
18
|
+
fs.mkdirSync(ROOT, { recursive: true });
|
|
19
|
+
fs.mkdirSync(TMP, { recursive: true });
|
|
26
20
|
|
|
27
21
|
try {
|
|
28
|
-
console.log(`Downloading capix-code v${VERSION} (${
|
|
29
|
-
|
|
30
|
-
execSync(`
|
|
22
|
+
console.log(`Downloading capix-code v${VERSION} (${plat}-${arch})...`);
|
|
23
|
+
execSync(`curl -fsSL -o "${TMP}/${NAME}.${ext}" "${URL}"`, { stdio: 'inherit' });
|
|
24
|
+
execSync(`tar -xzf "${TMP}/${NAME}.${ext}" -C "${TMP}"`, { stdio: 'inherit' });
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} else {
|
|
35
|
-
execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: 'inherit' });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const customerSrc = path.join(tmpDir, 'customer');
|
|
39
|
-
if (fs.existsSync(customerSrc)) {
|
|
26
|
+
const src = path.join(TMP, 'customer');
|
|
27
|
+
if (fs.existsSync(src)) {
|
|
40
28
|
for (const dir of ['bin', 'engine', 'runtime', 'config', 'mcp']) {
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
if (fs.existsSync(
|
|
44
|
-
execSync(`rm -rf "${dst}" && cp -a "${src}" "${dst}"`, { stdio: 'inherit' });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const binPath = path.join(installDir, 'bin', 'capix-code');
|
|
48
|
-
if (fs.existsSync(binPath)) {
|
|
49
|
-
fs.chmodSync(binPath, 0o755);
|
|
29
|
+
const s = path.join(src, dir);
|
|
30
|
+
const d = path.join(ROOT, dir);
|
|
31
|
+
if (fs.existsSync(s)) execSync(`rm -rf "${d}" && cp -a "${s}" "${d}"`, { stdio: 'inherit' });
|
|
50
32
|
}
|
|
33
|
+
fs.chmodSync(path.join(ROOT, 'bin', 'capix-code'), 0o755);
|
|
51
34
|
}
|
|
52
35
|
|
|
53
|
-
// Install runtime
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log('Installing runtime dependencies...');
|
|
57
|
-
execSync(`npm install --omit=dev --ignore-scripts`, { cwd: runtimeDir, stdio: 'inherit' });
|
|
58
|
-
}
|
|
36
|
+
// Install runtime deps (typescript required by plugin.ts)
|
|
37
|
+
console.log('Installing runtime dependencies...');
|
|
38
|
+
execSync('npm install --omit=dev --ignore-scripts', { cwd: path.join(ROOT, 'runtime'), stdio: 'inherit' });
|
|
59
39
|
|
|
60
|
-
// Install MCP
|
|
61
|
-
const mcpDir = path.join(
|
|
62
|
-
|
|
63
|
-
if (!fs.existsSync(path.join(mcpDir, 'node_modules', '@modelcontextprotocol', 'sdk'))) {
|
|
40
|
+
// Install MCP deps if not bundled
|
|
41
|
+
const mcpDir = path.join(ROOT, 'mcp');
|
|
42
|
+
if (!fs.existsSync(path.join(mcpDir, 'node_modules', '@modelcontextprotocol'))) {
|
|
64
43
|
console.log('Installing MCP dependencies...');
|
|
65
|
-
execSync(
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
'const credPath = join(homedir(), ".capix-code", "credentials.json");\n' +
|
|
75
|
-
'async function loadMcp() {\n' +
|
|
76
|
-
' require(join(homedir(), ".capix-code", "mcp", "node_modules", "capix-mcp", "dist", "index.js"));\n' +
|
|
77
|
-
'}\n' +
|
|
78
|
-
'(async () => {\n' +
|
|
79
|
-
' try {\n' +
|
|
80
|
-
' if (existsSync(credPath)) {\n' +
|
|
81
|
-
' const creds = JSON.parse(readFileSync(credPath, "utf8"));\n' +
|
|
82
|
-
' const rt = creds["capix-code:oauth-refresh-token"];\n' +
|
|
83
|
-
' if (rt) {\n' +
|
|
84
|
-
' const res = await fetch("https://www.capix.network/oauth/token", {\n' +
|
|
85
|
-
' method: "POST",\n' +
|
|
86
|
-
' headers: { "Content-Type": "application/x-www-form-urlencoded" },\n' +
|
|
87
|
-
' body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: rt, client_id: "capix-code" }).toString(),\n' +
|
|
88
|
-
' });\n' +
|
|
89
|
-
' const body = await res.json();\n' +
|
|
90
|
-
' if (body.access_token) {\n' +
|
|
91
|
-
' process.env.CAPIX_API_KEY = body.access_token;\n' +
|
|
92
|
-
' creds["capix-code:oauth-refresh-token"] = body.refresh_token;\n' +
|
|
93
|
-
' writeFileSync(credPath, JSON.stringify(creds, null, 2), { mode: 0o600 });\n' +
|
|
94
|
-
' chmodSync(credPath, 0o600);\n' +
|
|
95
|
-
' }\n' +
|
|
96
|
-
' }\n' +
|
|
97
|
-
' }\n' +
|
|
98
|
-
' } catch {}\n' +
|
|
99
|
-
' loadMcp();\n' +
|
|
100
|
-
'})();\n'
|
|
101
|
-
);
|
|
102
|
-
fs.chmodSync(mcpEntry, 0o755);
|
|
103
|
-
}
|
|
44
|
+
execSync('npm install capix-mcp@2.1.0', { cwd: mcpDir, stdio: 'inherit' });
|
|
45
|
+
// Write MCP wrapper that does NOT refresh token (uses CAPIX_API_KEY from env)
|
|
46
|
+
fs.writeFileSync(path.join(mcpDir, 'capix-mcp.js'),
|
|
47
|
+
'#!/usr/bin/env node\n' +
|
|
48
|
+
'const { join } = require("node:path");\n' +
|
|
49
|
+
'const { homedir } = require("node:os");\n' +
|
|
50
|
+
'require(join(homedir(), ".capix-code", "mcp", "node_modules", "capix-mcp", "dist", "index.js"));\n'
|
|
51
|
+
);
|
|
52
|
+
fs.chmodSync(path.join(mcpDir, 'capix-mcp.js'), 0o755);
|
|
104
53
|
}
|
|
105
54
|
|
|
106
|
-
//
|
|
55
|
+
// Create config at the path the engine ACTUALLY reads
|
|
56
|
+
// The core package uses ~/.config/opencode/ (not capix-code)
|
|
57
|
+
const cfgDir = path.join(os.homedir(), '.config', 'opencode');
|
|
58
|
+
fs.mkdirSync(cfgDir, { recursive: true });
|
|
59
|
+
const rtDir = path.join(ROOT, 'runtime');
|
|
60
|
+
const providerUrl = `file://${rtDir}/packages/runtime-provider/src/index.ts`;
|
|
61
|
+
const apiBase = 'https://www.capix.network/api/v1';
|
|
62
|
+
|
|
63
|
+
const config = {
|
|
64
|
+
model: 'capix/auto',
|
|
65
|
+
enabled_providers: ['capix'],
|
|
66
|
+
plugin: [
|
|
67
|
+
path.join(rtDir, 'src', 'native-bridge.ts'),
|
|
68
|
+
path.join(rtDir, 'src', 'plugin.ts')
|
|
69
|
+
],
|
|
70
|
+
provider: {
|
|
71
|
+
capix: {
|
|
72
|
+
npm: providerUrl,
|
|
73
|
+
name: 'Capix',
|
|
74
|
+
models: {
|
|
75
|
+
auto: {
|
|
76
|
+
name: 'Capix Auto (smart route)',
|
|
77
|
+
limit: { context: 128000, output: 64000 },
|
|
78
|
+
api: { url: apiBase, npm: providerUrl }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
fs.writeFileSync(path.join(cfgDir, 'capix-code.json'), JSON.stringify(config, null, 2));
|
|
85
|
+
|
|
86
|
+
// Sign on macOS
|
|
107
87
|
if (process.platform === 'darwin') {
|
|
108
88
|
try {
|
|
109
|
-
execSync(`codesign --force --sign - "${path.join(
|
|
110
|
-
execSync(`codesign --force --sign - "${path.join(
|
|
89
|
+
execSync(`codesign --force --sign - "${path.join(ROOT, 'bin', 'capix-code')}"`, { stdio: 'ignore' });
|
|
90
|
+
execSync(`codesign --force --sign - "${path.join(ROOT, 'engine', 'capix-engine')}"`, { stdio: 'ignore' });
|
|
111
91
|
} catch {}
|
|
112
92
|
}
|
|
113
93
|
|
|
114
|
-
fs.rmSync(
|
|
115
|
-
console.log(`✓ Capix Code v${VERSION} installed
|
|
94
|
+
fs.rmSync(TMP, { recursive: true, force: true });
|
|
95
|
+
console.log(`✓ Capix Code v${VERSION} installed`);
|
|
116
96
|
console.log('Run: capix-code login && capix-code');
|
|
117
97
|
} catch (err) {
|
|
118
|
-
console.warn('
|
|
119
|
-
console.warn(' https://github.com/CapIX-Protocol/Capix-Code/releases');
|
|
98
|
+
console.warn('Install failed. Download manually from https://github.com/CapIX-Protocol/Capix-Code/releases');
|
|
120
99
|
process.exit(0);
|
|
121
100
|
}
|