@senoldogann/context-manager 0.1.2
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/bin/ccm.js +105 -0
- package/package.json +29 -0
package/bin/ccm.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
|
|
9
|
+
const VERSION = '0.1.2';
|
|
10
|
+
const REPO = 'senoldogann/LLM-Context-Manager';
|
|
11
|
+
const BIN_DIR = path.join(os.homedir(), '.ccm', 'bin');
|
|
12
|
+
|
|
13
|
+
async function getBinary() {
|
|
14
|
+
const platform = os.platform(); // darwin, linux, win32
|
|
15
|
+
const arch = os.arch(); // x64, arm64
|
|
16
|
+
|
|
17
|
+
let target = '';
|
|
18
|
+
if (platform === 'darwin') {
|
|
19
|
+
target = arch === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin';
|
|
20
|
+
} else if (platform === 'linux') {
|
|
21
|
+
target = 'x86_64-unknown-linux-gnu';
|
|
22
|
+
} else if (platform === 'win32') {
|
|
23
|
+
target = 'x86_64-pc-windows-msvc.exe';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Detect which tool to run
|
|
27
|
+
let commandName = 'ccm-cli'; // Default
|
|
28
|
+
const binName = path.basename(process.argv[1]);
|
|
29
|
+
|
|
30
|
+
if (binName.includes('mcp')) {
|
|
31
|
+
commandName = 'ccm-mcp';
|
|
32
|
+
} else if (process.argv[2] === 'mcp') {
|
|
33
|
+
// Handle: npx @ccm/context-manager mcp
|
|
34
|
+
commandName = 'ccm-mcp';
|
|
35
|
+
process.argv.splice(2, 1); // Remove 'mcp' from args to be passed to binary
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const binFilename = `${commandName}-${target}`;
|
|
39
|
+
const binPath = path.join(BIN_DIR, binFilename);
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(binPath)) {
|
|
42
|
+
return binPath;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(`[CCM] Binary not found. Downloading ${commandName} for ${target}...`);
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(BIN_DIR)) {
|
|
48
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${commandName}-${target}`;
|
|
52
|
+
|
|
53
|
+
await downloadFile(url, binPath);
|
|
54
|
+
fs.chmodSync(binPath, '755');
|
|
55
|
+
|
|
56
|
+
return binPath;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function downloadFile(url, dest) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const file = fs.createWriteStream(dest);
|
|
62
|
+
https.get(url, (response) => {
|
|
63
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
64
|
+
downloadFile(response.headers.location, dest).then(resolve).catch(reject);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (response.statusCode !== 200) {
|
|
68
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
response.pipe(file);
|
|
72
|
+
file.on('finish', () => {
|
|
73
|
+
file.close(resolve);
|
|
74
|
+
});
|
|
75
|
+
}).on('error', (err) => {
|
|
76
|
+
fs.unlink(dest, () => { });
|
|
77
|
+
reject(err);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function main() {
|
|
83
|
+
try {
|
|
84
|
+
const binPath = await getBinary();
|
|
85
|
+
const args = process.argv.slice(2);
|
|
86
|
+
|
|
87
|
+
const child = spawn(binPath, args, {
|
|
88
|
+
stdio: 'inherit',
|
|
89
|
+
env: {
|
|
90
|
+
...process.env,
|
|
91
|
+
// Ensure MCP knows its project root if it can
|
|
92
|
+
CCM_PROJECT_ROOT: process.env.CCM_PROJECT_ROOT || process.cwd()
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
child.on('exit', (code) => {
|
|
97
|
+
process.exit(code);
|
|
98
|
+
});
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error(`[CCM Error] ${err.message}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@senoldogann/context-manager",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "LLM Context Manager MCP Server & CLI wrapper using npx",
|
|
5
|
+
"main": "bin/ccm.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ccm-cli": "bin/ccm.js",
|
|
8
|
+
"ccm-mcp": "bin/ccm.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"mcp",
|
|
15
|
+
"context-manager",
|
|
16
|
+
"ai",
|
|
17
|
+
"llm",
|
|
18
|
+
"rust",
|
|
19
|
+
"npx"
|
|
20
|
+
],
|
|
21
|
+
"author": "dogan",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"node-fetch": "^3.3.1"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|