bonzai-burn 1.0.31 → 1.0.33

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.31",
3
+ "version": "1.0.33",
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",
@@ -2,6 +2,9 @@
2
2
  "customChecks": {
3
3
  "requirements": "Remove unused imports and variables. Remove all console log statements."
4
4
  },
5
+ "autoBurn":{
6
+ "enabled": true
7
+ },
5
8
  "eslint": {
6
9
  "enabled": true,
7
10
  "rules": ["no-unused-vars"]
package/src/bhook.js ADDED
@@ -0,0 +1,180 @@
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 'install':
161
+ installHook();
162
+ break;
163
+ case 'uninstall':
164
+ case 'remove':
165
+ uninstallHook();
166
+ break;
167
+ case 'status':
168
+ default:
169
+ showStatus();
170
+ if (!command) {
171
+ console.log('Commands: bhook install | bhook uninstall | bhook status\n');
172
+ }
173
+ break;
174
+ }
175
+ }
176
+
177
+ main().catch((error) => {
178
+ console.error('Error:', error.message);
179
+ process.exit(1);
180
+ });