@campfire-net/campfire-mcp 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/index.js +59 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const { execFileSync } = require('child_process');
4
+ const { execFileSync, execSync } = require('child_process');
5
5
  const path = require('path');
6
+ const fs = require('fs');
6
7
  const os = require('os');
7
8
 
8
9
  function getBinaryPath() {
9
- const platform = os.platform(); // 'linux', 'darwin', 'win32'
10
- const arch = os.arch(); // 'x64', 'arm64'
10
+ const platform = os.platform();
11
+ const arch = os.arch();
11
12
 
12
13
  const pkgMap = {
13
14
  'linux-x64': '@campfire-net/campfire-mcp-linux-x64',
@@ -23,18 +24,67 @@ function getBinaryPath() {
23
24
  throw new Error(`campfire-mcp: unsupported platform ${key}`);
24
25
  }
25
26
 
27
+ // Try platform package first
26
28
  try {
27
29
  const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`));
28
30
  const bin = platform === 'win32'
29
31
  ? path.join(pkgDir, 'cf-mcp.exe')
30
32
  : path.join(pkgDir, 'cf-mcp');
31
- return bin;
32
- } catch {
33
- throw new Error(
34
- `campfire-mcp: platform package ${pkgName} is not installed.\n` +
35
- `Run: npm install ${pkgName}`
36
- );
33
+ if (fs.existsSync(bin)) return bin;
34
+ } catch {}
35
+
36
+ // Fallback: check cache
37
+ const cacheDir = path.join(os.homedir(), '.cache', 'campfire-mcp');
38
+ const cachedBin = path.join(cacheDir, platform === 'win32' ? 'cf-mcp.exe' : 'cf-mcp');
39
+ if (fs.existsSync(cachedBin)) return cachedBin;
40
+
41
+ // Download from GitHub Releases with checksum verification
42
+ const crypto = require('crypto');
43
+ const goArch = arch === 'x64' ? 'amd64' : arch;
44
+ const goPlatform = platform;
45
+ const ext = platform === 'win32' ? 'zip' : 'tar.gz';
46
+ const archiveName = `cf_${goPlatform}_${goArch}.${ext}`;
47
+ const baseUrl = 'https://github.com/campfire-net/campfire/releases/latest/download';
48
+ const archiveUrl = `${baseUrl}/${archiveName}`;
49
+ const checksumsUrl = `${baseUrl}/checksums.txt`;
50
+ const archivePath = path.join(cacheDir, archiveName);
51
+
52
+ process.stderr.write(`campfire-mcp: downloading ${archiveName}\n`);
53
+ fs.mkdirSync(cacheDir, { recursive: true });
54
+
55
+ try {
56
+ // Download archive and checksums
57
+ execSync(`curl -sL "${archiveUrl}" -o "${archivePath}"`, { stdio: 'pipe' });
58
+ const checksums = execSync(`curl -sL "${checksumsUrl}"`, { encoding: 'utf8' });
59
+
60
+ // Verify SHA256
61
+ const archiveData = fs.readFileSync(archivePath);
62
+ const actualHash = crypto.createHash('sha256').update(archiveData).digest('hex');
63
+ const expectedLine = checksums.split('\n').find(l => l.includes(archiveName));
64
+ if (!expectedLine) {
65
+ throw new Error(`checksum not found for ${archiveName}`);
66
+ }
67
+ const expectedHash = expectedLine.trim().split(/\s+/)[0];
68
+ if (actualHash !== expectedHash) {
69
+ fs.unlinkSync(archivePath);
70
+ throw new Error(`checksum mismatch: expected ${expectedHash}, got ${actualHash}`);
71
+ }
72
+ process.stderr.write(`campfire-mcp: checksum verified\n`);
73
+
74
+ // Extract
75
+ if (platform === 'win32') {
76
+ execSync(`cd "${cacheDir}" && tar -xf "${archivePath}" --strip-components=1 --include='*/cf-mcp.exe'`, { stdio: 'pipe' });
77
+ } else {
78
+ execSync(`tar xzf "${archivePath}" -C "${cacheDir}" --strip-components=1 --wildcards '*/cf-mcp'`, { stdio: 'pipe' });
79
+ }
80
+ fs.unlinkSync(archivePath);
81
+ fs.chmodSync(cachedBin, 0o755);
82
+ if (fs.existsSync(cachedBin)) return cachedBin;
83
+ } catch (e) {
84
+ throw new Error(`campfire-mcp: failed to download/verify binary: ${e.message}\nInstall manually: curl -fsSL https://getcampfire.dev/install.sh | sh`);
37
85
  }
86
+
87
+ throw new Error('campfire-mcp: could not find or download binary');
38
88
  }
39
89
 
40
90
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campfire-net/campfire-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Campfire MCP server — decentralized coordination protocol for AI agents",
5
5
  "bin": {
6
6
  "campfire-mcp": "index.js"