bonzai-burn 1.0.32 → 1.0.35

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 CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "bonzai-burn",
3
- "version": "1.0.32",
3
+ "version": "1.0.35",
4
4
  "description": "Git branch-based cleanup tool with bburn, baccept, and brevert commands",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "bonzai-burn": "./src/index.js",
9
9
  "bburn": "./src/bburn.js",
10
- "bgraph": "./src/bgraph.js"
10
+ "bgraph": "./src/bgraph.js",
11
+ "bhook": "./src/bhook.js"
11
12
  },
12
13
  "keywords": [
13
14
  "git",
package/src/bburn.js CHANGED
@@ -53,7 +53,14 @@ async function main() {
53
53
  console.log('The above was found - let the user know but take no action. It\'s critical you take no action.\n');
54
54
  }
55
55
 
56
- main().catch((error) => {
57
- console.error('Error:', error.message);
58
- process.exit(1);
59
- });
56
+ // Export for use via index.js flags
57
+ export { main };
58
+
59
+ // Run directly if called as standalone command
60
+ const isDirectRun = process.argv[1]?.endsWith('bburn.js');
61
+ if (isDirectRun) {
62
+ main().catch((error) => {
63
+ console.error('Error:', error.message);
64
+ process.exit(1);
65
+ });
66
+ }
package/src/bgraph.js CHANGED
@@ -192,4 +192,11 @@ async function main() {
192
192
  });
193
193
  }
194
194
 
195
- main().catch(console.error);
195
+ // Export for use via index.js flags
196
+ export { main };
197
+
198
+ // Run directly if called as standalone command
199
+ const isDirectRun = process.argv[1]?.endsWith('bgraph.js');
200
+ if (isDirectRun) {
201
+ main().catch(console.error);
202
+ }
package/src/bhook.js ADDED
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import { join } from 'path';
4
+
5
+ const BONZAI_DIR = 'bonzai';
6
+ const CONFIG_FILE = 'config.json';
7
+ const CLAUDE_DIR = '.claude';
8
+ const SETTINGS_FILE = 'settings.local.json';
9
+
10
+ /**
11
+ * Load project config from bonzai/config.json
12
+ */
13
+ function loadBonzaiConfig() {
14
+ const configPath = join(process.cwd(), BONZAI_DIR, CONFIG_FILE);
15
+
16
+ if (!fs.existsSync(configPath)) {
17
+ return null;
18
+ }
19
+
20
+ try {
21
+ const content = fs.readFileSync(configPath, 'utf-8');
22
+ return JSON.parse(content);
23
+ } catch (e) {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Load or create Claude settings
30
+ */
31
+ function loadClaudeSettings() {
32
+ const settingsPath = join(process.cwd(), CLAUDE_DIR, SETTINGS_FILE);
33
+
34
+ if (!fs.existsSync(settingsPath)) {
35
+ return {};
36
+ }
37
+
38
+ try {
39
+ const content = fs.readFileSync(settingsPath, 'utf-8');
40
+ return JSON.parse(content);
41
+ } catch (e) {
42
+ return {};
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Save Claude settings
48
+ */
49
+ function saveClaudeSettings(settings) {
50
+ const claudeDir = join(process.cwd(), CLAUDE_DIR);
51
+ const settingsPath = join(claudeDir, SETTINGS_FILE);
52
+
53
+ // Ensure .claude directory exists
54
+ if (!fs.existsSync(claudeDir)) {
55
+ fs.mkdirSync(claudeDir, { recursive: true });
56
+ }
57
+
58
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
59
+ }
60
+
61
+ /**
62
+ * Check if bburn hook is already installed
63
+ */
64
+ function hasBburnHook(settings) {
65
+ const stopHooks = settings.hooks?.Stop || [];
66
+ return stopHooks.some(entry =>
67
+ entry.hooks?.some(hook => hook.command === 'bburn')
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Install bburn as a Stop hook
73
+ */
74
+ function installHook() {
75
+ const settings = loadClaudeSettings();
76
+
77
+ if (hasBburnHook(settings)) {
78
+ console.log('✓ bburn hook already installed\n');
79
+ return;
80
+ }
81
+
82
+ // Initialize hooks structure if needed
83
+ if (!settings.hooks) {
84
+ settings.hooks = {};
85
+ }
86
+ if (!settings.hooks.Stop) {
87
+ settings.hooks.Stop = [];
88
+ }
89
+
90
+ // Add bburn hook with correct nested structure
91
+ settings.hooks.Stop.push({
92
+ hooks: [
93
+ {
94
+ type: 'command',
95
+ command: 'bburn'
96
+ }
97
+ ]
98
+ });
99
+
100
+ saveClaudeSettings(settings);
101
+ console.log('✓ Installed bburn as Claude Code Stop hook');
102
+ console.log(' bburn will run after every Claude Code message\n');
103
+ }
104
+
105
+ /**
106
+ * Uninstall bburn hook
107
+ */
108
+ function uninstallHook() {
109
+ const settings = loadClaudeSettings();
110
+
111
+ if (!hasBburnHook(settings)) {
112
+ console.log('✓ bburn hook not installed\n');
113
+ return;
114
+ }
115
+
116
+ // Remove entries that contain bburn hooks
117
+ settings.hooks.Stop = settings.hooks.Stop.filter(entry =>
118
+ !entry.hooks?.some(hook => hook.command === 'bburn')
119
+ );
120
+
121
+ // Clean up empty arrays
122
+ if (settings.hooks.Stop.length === 0) {
123
+ delete settings.hooks.Stop;
124
+ }
125
+ if (Object.keys(settings.hooks).length === 0) {
126
+ delete settings.hooks;
127
+ }
128
+
129
+ saveClaudeSettings(settings);
130
+ console.log('✓ Removed bburn hook from Claude Code\n');
131
+ }
132
+
133
+ /**
134
+ * Show current status
135
+ */
136
+ function showStatus() {
137
+ const settings = loadClaudeSettings();
138
+ const config = loadBonzaiConfig();
139
+
140
+ console.log('\n🔥 Bonzai Hook Status\n');
141
+
142
+ // Check autoBurn config
143
+ const autoBurnEnabled = config?.autoBurn?.enabled ?? false;
144
+ console.log(`Config autoBurn: ${autoBurnEnabled ? 'enabled' : 'disabled'}`);
145
+
146
+ // Check hook status
147
+ const hookInstalled = hasBburnHook(settings);
148
+ console.log(`Claude hook: ${hookInstalled ? 'installed' : 'not installed'}\n`);
149
+
150
+ if (autoBurnEnabled && !hookInstalled) {
151
+ console.log('Run "bhook install" to install the hook\n');
152
+ }
153
+ }
154
+
155
+ async function main() {
156
+ const args = process.argv.slice(2);
157
+ const command = args[0];
158
+
159
+ switch (command) {
160
+ case 'uninstall':
161
+ case 'remove':
162
+ uninstallHook();
163
+ break;
164
+ case 'status':
165
+ showStatus();
166
+ break;
167
+ case 'install':
168
+ default:
169
+ // Default action is to install (like bburn runs analysis by default)
170
+ installHook();
171
+ break;
172
+ }
173
+ }
174
+
175
+ // Export for use via index.js flags
176
+ export { main };
177
+
178
+ // Run directly if called as standalone command
179
+ const isDirectRun = process.argv[1]?.endsWith('bhook.js');
180
+ if (isDirectRun) {
181
+ main().catch((error) => {
182
+ console.error('Error:', error.message);
183
+ process.exit(1);
184
+ });
185
+ }
package/src/index.js CHANGED
@@ -9,6 +9,27 @@ const __dirname = dirname(__filename);
9
9
  const BONZAI_DIR = 'bonzai';
10
10
  const TEMPLATE_DIR = join(__dirname, '..', 'payload-bonzai');
11
11
 
12
+ function showHelp() {
13
+ console.log(`
14
+ 🌳 Bonzai Burn - Code Analysis Tool
15
+
16
+ Usage: npx bonzai-burn [option]
17
+
18
+ Options:
19
+ (no option) Initialize bonzai in current directory
20
+ -b, --burn Run code analysis (bburn)
21
+ -g, --graph Launch visualization server (bgraph)
22
+ -h, --hook Install Claude Code stop hook (bhook)
23
+ --help Show this help message
24
+
25
+ Examples:
26
+ npx bonzai-burn # Initialize bonzai folder
27
+ npx bonzai-burn -b # Run burn analysis
28
+ npx bonzai-burn -g # Start graph server
29
+ npx bonzai-burn -h # Install hook
30
+ `);
31
+ }
32
+
12
33
  function init() {
13
34
  const currentDir = process.cwd();
14
35
  const bonzaiPath = join(currentDir, BONZAI_DIR);
@@ -22,13 +43,48 @@ function init() {
22
43
  copyFileSync(join(TEMPLATE_DIR, 'config.json'), join(bonzaiPath, 'config.json'));
23
44
  console.log(`📁 Created ${BONZAI_DIR}/ folder with config.json`);
24
45
  console.log(`📝 Edit ${BONZAI_DIR}/config.json to configure your burn rules`);
25
- console.log(`🔥 Run 'bburn' to analyze your codebase`);
46
+ console.log(`🔥 Run 'npx bonzai-burn -b' to analyze your codebase`);
26
47
  console.log('');
27
48
  console.log('┌─────────────────────────────────────────────────────────────┐');
28
49
  console.log('│ │');
29
- console.log('│ 🌳 Run `bgraph` to configure provider, frequency & more │');
50
+ console.log('│ 🌳 Run `npx bonzai-burn -g` to visualize your codebase │');
30
51
  console.log('│ │');
31
52
  console.log('└─────────────────────────────────────────────────────────────┘');
32
53
  }
33
54
 
34
- init();
55
+ async function main() {
56
+ const args = process.argv.slice(2);
57
+ const flag = args[0];
58
+
59
+ switch (flag) {
60
+ case '-b':
61
+ case '--burn': {
62
+ const { main: burnMain } = await import('./bburn.js');
63
+ if (burnMain) await burnMain();
64
+ break;
65
+ }
66
+ case '-g':
67
+ case '--graph': {
68
+ const { main: graphMain } = await import('./bgraph.js');
69
+ if (graphMain) await graphMain();
70
+ break;
71
+ }
72
+ case '-h':
73
+ case '--hook': {
74
+ const { main: hookMain } = await import('./bhook.js');
75
+ if (hookMain) await hookMain();
76
+ break;
77
+ }
78
+ case '--help':
79
+ showHelp();
80
+ break;
81
+ default:
82
+ init();
83
+ break;
84
+ }
85
+ }
86
+
87
+ main().catch((error) => {
88
+ console.error('Error:', error.message);
89
+ process.exit(1);
90
+ });