Skip to content

Commit fb107a3

Browse files
author
anshmajumdar121
committed
fix: self-contained bin/cli.js, bump to 1.0.1
1 parent c6478ec commit fb107a3

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

bin/cli.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
11
#!/usr/bin/env node
2-
require("../scripts/npx-init.js");
2+
'use strict';
3+
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const EDITORS = {
8+
cursor: '.cursor/rules/context-optimizer.mdc',
9+
windsurf: '.windsurf/rules/context-optimizer.md',
10+
cline: '.clinerules/context-optimizer.md',
11+
claude: 'CLAUDE.md',
12+
};
13+
14+
const EDITOR_NAMES = {
15+
cursor: 'Cursor',
16+
windsurf: 'Windsurf',
17+
cline: 'Cline',
18+
claude: 'Claude Code',
19+
};
20+
21+
function detect(dir) {
22+
if (fs.existsSync(path.join(dir, '.cursor'))) return 'cursor';
23+
if (fs.existsSync(path.join(dir, '.windsurf'))) return 'windsurf';
24+
if (fs.existsSync(path.join(dir, '.clinerules'))) return 'cline';
25+
return 'claude';
26+
}
27+
28+
const projectPath = process.argv[2] || ".";
29+
const resolvedPath = path.resolve(projectPath);
30+
31+
if (!fs.existsSync(resolvedPath)) {
32+
console.error('Error: path not found:', resolvedPath);
33+
process.exit(1);
34+
}
35+
36+
const editor = detect(resolvedPath);
37+
const dest = path.join(resolvedPath, EDITORS[editor]);
38+
const skillSrc = path.join(__dirname, '..', 'skill', 'claude-custom-instructions.md');
39+
40+
if (!fs.existsSync(skillSrc)) {
41+
console.error('Error: skill file not found at', skillSrc);
42+
process.exit(1);
43+
}
44+
45+
const skill = fs.readFileSync(skillSrc, "utf8");
46+
fs.mkdirSync(path.dirname(dest), { recursive: true });
47+
48+
if (editor === "claude" && fs.existsSync(dest)) {
49+
const existing = fs.readFileSync(dest, "utf8");
50+
if (existing.includes("CONTEXT_MANIFEST.md")) {
51+
console.log('
52+
Already installed in', path.relative(resolvedPath, dest));
53+
} else {
54+
fs.appendFileSync(dest, "
55+
56+
" + skill);
57+
console.log('
58+
Appended to', path.relative(resolvedPath, dest));
59+
}
60+
} else {
61+
fs.writeFileSync(dest, skill);
62+
console.log('
63+
Written to', path.relative(resolvedPath, dest));
64+
}
65+
66+
console.log(' Editor: ', EDITOR_NAMES[editor]);
67+
console.log(' Project: ', resolvedPath);
68+
console.log('
69+
Next generate your manifest:
70+
');
71+
console.log(' python3 tools/context_mapper.py', resolvedPath);
72+
console.log('
73+
Then upload CONTEXT_MANIFEST.md to your Claude Project or paste into chat.
74+
');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@anshmaj121/context-optimizer",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Zero-install context discipline for Claude. 5-27x fewer tokens.",
55
"bin": {
66
"context-optimizer": "./bin/cli.js"

0 commit comments

Comments
 (0)