-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbug-hunter
More file actions
executable file
·232 lines (205 loc) · 7.06 KB
/
Copy pathbug-hunter
File metadata and controls
executable file
·232 lines (205 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env node
/**
* bug-hunter CLI — installs the bug-hunter skill into your agent's skill directory.
*
* Usage:
* bug-hunter install # Auto-detect agent and install skill
* bug-hunter install --agent claude-code
* bug-hunter install --path ~/.custom/skills
* bug-hunter doctor # Check environment (node, chub, context7)
* bug-hunter info # Show skill metadata
*/
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
const SKILL_SRC = path.resolve(__dirname, '..');
const SKILL_NAME = 'bug-hunter';
// Agent skill directories in priority order
const homedir = require('os').homedir();
const AGENT_DIRS = [
{ agent: 'claude-code', dir: path.join(homedir, '.claude', 'skills', SKILL_NAME) },
{ agent: 'codex', dir: path.join(homedir, '.codex', 'skills', SKILL_NAME) },
{ agent: 'agents', dir: path.join(homedir, '.agents', 'skills', SKILL_NAME) },
{ agent: 'cursor', dir: path.join(homedir, '.cursor', 'skills', SKILL_NAME) },
{ agent: 'kiro', dir: path.join(homedir, '.kiro', 'skills', SKILL_NAME) },
{ agent: 'copilot', dir: path.join(homedir, '.copilot', 'skills', SKILL_NAME) },
{ agent: 'windsurf', dir: path.join(homedir, '.windsurf', 'skills', SKILL_NAME) },
{ agent: 'opencode', dir: path.join(homedir, '.opencode', 'skills', SKILL_NAME) },
];
function usage() {
console.log(`
bug-hunter - Adversarial AI bug hunting skill
Commands:
install [--agent <name>] [--path <dir>] Install skill into agent directory
doctor Check environment readiness
info Show skill metadata
Options:
--agent <name> Target agent: claude-code, codex, cursor, kiro, copilot, windsurf, opencode, agents
--path <dir> Custom install directory (overrides --agent)
Examples:
bug-hunter install # Auto-detect agent
bug-hunter install --agent claude-code # Specific agent
bug-hunter install --path ~/my-skills/bug-hunter
bug-hunter doctor # Check node, chub, context7
`.trim());
}
function copyRecursive(src, dest) {
const stat = fs.statSync(src);
if (stat.isDirectory()) {
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src)) {
// Skip git, node_modules, tmp, .bug-hunter output
if (['.git', 'node_modules', 'tmp', '.bug-hunter'].includes(entry)) continue;
copyRecursive(path.join(src, entry), path.join(dest, entry));
}
} else {
fs.copyFileSync(src, dest);
}
}
function install(args) {
let targetDir = null;
let agentName = null;
// Parse args
for (let i = 0; i < args.length; i++) {
if (args[i] === '--path' && args[i + 1]) {
targetDir = path.resolve(args[++i]);
} else if (args[i] === '--agent' && args[i + 1]) {
agentName = args[++i];
}
}
// Resolve target directory
if (!targetDir) {
if (agentName) {
const match = AGENT_DIRS.find(a => a.agent === agentName);
if (!match) {
console.error(`Unknown agent: ${agentName}`);
console.error(`Available: ${AGENT_DIRS.map(a => a.agent).join(', ')}`);
process.exit(1);
}
targetDir = match.dir;
} else {
// Auto-detect: use first agent whose parent dir exists
for (const { agent, dir } of AGENT_DIRS) {
const parent = path.dirname(path.dirname(dir)); // e.g. ~/.claude
if (fs.existsSync(parent)) {
targetDir = dir;
agentName = agent;
break;
}
}
if (!targetDir) {
// Default to ~/.agents/skills/bug-hunter
targetDir = AGENT_DIRS.find(a => a.agent === 'agents').dir;
agentName = 'agents';
}
}
}
console.log(`Installing bug-hunter skill...`);
console.log(` Source: ${SKILL_SRC}`);
console.log(` Target: ${targetDir}`);
if (agentName) console.log(` Agent: ${agentName}`);
// Copy skill files
copyRecursive(SKILL_SRC, targetDir);
console.log(`\n Installed successfully.\n`);
console.log(` Usage: /bug-hunter src/`);
console.log(` Docs: https://github.com/codexstar69/bug-hunter`);
// Run doctor automatically after install
console.log('');
doctor();
}
function doctor() {
console.log('Environment check:\n');
let issues = 0;
// Node.js
try {
const nodeVersion = execFileSync('node', ['--version'], { encoding: 'utf8' }).trim();
console.log(` [ok] Node.js ${nodeVersion}`);
} catch {
console.error(' [!!] Node.js not found — required for doc verification');
issues++;
}
// Context Hub (chub)
try {
execFileSync('chub', ['--help'], { stdio: 'ignore', timeout: 3000 });
console.log(' [ok] Context Hub (chub) installed — curated docs available');
} catch {
console.log(' [--] Context Hub (chub) not installed — will fall back to Context7');
console.log(' Install for better doc verification: npm install -g @aisuite/chub');
console.log(' More info: https://github.com/andrewyng/context-hub');
}
// Context7 API
try {
const c7Script = path.join(SKILL_SRC, 'scripts', 'context7-api.cjs');
if (fs.existsSync(c7Script)) {
console.log(' [ok] Context7 fallback available');
} else {
console.log(' [--] Context7 script not found (non-critical)');
}
} catch {
console.log(' [--] Context7 check skipped');
}
// Git
try {
const gitVersion = execFileSync('git', ['--version'], { encoding: 'utf8' }).trim();
console.log(` [ok] ${gitVersion}`);
} catch {
console.error(' [!!] Git not found — required for fix pipeline');
issues++;
}
console.log('');
if (issues === 0) {
console.log(' Ready to hunt bugs.\n');
} else {
console.log(` ${issues} issue(s) found. Fix them for full functionality.\n`);
process.exit(1);
}
}
function info() {
const skillMd = path.join(SKILL_SRC, 'SKILL.md');
if (!fs.existsSync(skillMd)) {
console.error('SKILL.md not found');
process.exit(1);
}
const content = fs.readFileSync(skillMd, 'utf8');
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
if (frontmatterMatch) {
const lines = frontmatterMatch[1].split('\n');
console.log('\nbug-hunter skill metadata:\n');
for (const line of lines) {
console.log(` ${line}`);
}
console.log('');
}
console.log(` Install: npx skills add codexstar69/bug-hunter`);
console.log(` Or: npm install -g @codexstar/bug-hunter && bug-hunter install`);
console.log(` Repo: https://github.com/codexstar69/bug-hunter`);
console.log('');
}
// Main
const args = process.argv.slice(2);
const command = args[0];
switch (command) {
case 'install':
install(args.slice(1));
break;
case 'doctor':
doctor();
break;
case 'info':
info();
break;
case '--version':
case '-v': {
const version = require('../package.json').version;
console.log(`bug-hunter ${version}`);
break;
}
case '--help':
case '-h':
case undefined:
usage();
break;
default:
console.error(`Unknown command: ${command}`);
process.exit(1);
}