bashbros 0.1.0

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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +453 -0
  3. package/dist/audit-MCFNGOIM.js +11 -0
  4. package/dist/audit-MCFNGOIM.js.map +1 -0
  5. package/dist/chunk-43W3RVEL.js +2910 -0
  6. package/dist/chunk-43W3RVEL.js.map +1 -0
  7. package/dist/chunk-4R4GV5V2.js +213 -0
  8. package/dist/chunk-4R4GV5V2.js.map +1 -0
  9. package/dist/chunk-7OCVIDC7.js +12 -0
  10. package/dist/chunk-7OCVIDC7.js.map +1 -0
  11. package/dist/chunk-CSRPOGHY.js +354 -0
  12. package/dist/chunk-CSRPOGHY.js.map +1 -0
  13. package/dist/chunk-DEAF6PYM.js +212 -0
  14. package/dist/chunk-DEAF6PYM.js.map +1 -0
  15. package/dist/chunk-DLP2O6PN.js +273 -0
  16. package/dist/chunk-DLP2O6PN.js.map +1 -0
  17. package/dist/chunk-GD5VNHIN.js +519 -0
  18. package/dist/chunk-GD5VNHIN.js.map +1 -0
  19. package/dist/chunk-ID2O2QTI.js +269 -0
  20. package/dist/chunk-ID2O2QTI.js.map +1 -0
  21. package/dist/chunk-J37RHCFJ.js +357 -0
  22. package/dist/chunk-J37RHCFJ.js.map +1 -0
  23. package/dist/chunk-SB4JS3GU.js +456 -0
  24. package/dist/chunk-SB4JS3GU.js.map +1 -0
  25. package/dist/chunk-SG752FZC.js +200 -0
  26. package/dist/chunk-SG752FZC.js.map +1 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +2448 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/config-CZMIGNPF.js +13 -0
  31. package/dist/config-CZMIGNPF.js.map +1 -0
  32. package/dist/config-parser-XHE7BC7H.js +13 -0
  33. package/dist/config-parser-XHE7BC7H.js.map +1 -0
  34. package/dist/db-EHQDB5OL.js +11 -0
  35. package/dist/db-EHQDB5OL.js.map +1 -0
  36. package/dist/display-IN4NRJJS.js +18 -0
  37. package/dist/display-IN4NRJJS.js.map +1 -0
  38. package/dist/engine-PKLXW6OF.js +9 -0
  39. package/dist/engine-PKLXW6OF.js.map +1 -0
  40. package/dist/index.d.ts +1498 -0
  41. package/dist/index.js +552 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/moltbot-DXZFVK3X.js +11 -0
  44. package/dist/moltbot-DXZFVK3X.js.map +1 -0
  45. package/dist/ollama-HY35OHW4.js +9 -0
  46. package/dist/ollama-HY35OHW4.js.map +1 -0
  47. package/dist/risk-scorer-Y6KF2XCZ.js +9 -0
  48. package/dist/risk-scorer-Y6KF2XCZ.js.map +1 -0
  49. package/dist/static/index.html +410 -0
  50. package/package.json +68 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GhostPeony
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,453 @@
1
+ # /BashBros
2
+ ![bashbros](https://github.com/user-attachments/assets/6f674f48-cb63-4cb3-9b26-fdad6ac653b8)
3
+
4
+ ```
5
+ /____ _ ____
6
+ /| __ ) __ _ ___| |__ | __ ) _ __ ___ ___
7
+ / | _ \ / _` / __| '_ \| _ \| '__/ _ \/ __|
8
+ / | |_) | (_| \__ \ | | | |_) | | | (_) \__ \
9
+ / |____/ \__,_|___/_| |_|____/|_| \___/|___/
10
+ 🤝 Your Friendly Bash Agent Helper
11
+ ```
12
+
13
+ BashBros protects CLI agents with security middleware AND supercharges them with an AI sidekick that knows your system.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install -g bashbros
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```bash
24
+ bashbros init # Interactive setup
25
+ bashbros scan # Learn your system
26
+ bashbros watch # Start protection
27
+ ```
28
+
29
+ For Claude Code integration:
30
+ ```bash
31
+ bashbros hook install # Auto-install hooks
32
+ ```
33
+
34
+ ## Features
35
+
36
+ ### Security (9 modules)
37
+ - **Command filter** - Allow/block by pattern
38
+ - **Path sandbox** - Restrict filesystem access
39
+ - **Secrets guard** - Block .env, keys, credentials
40
+ - **Rate limiter** - Prevent runaway agents
41
+ - **Risk scorer** - Score commands 1-10 by danger level
42
+ - **Loop detector** - Detect stuck/repetitive agent behavior
43
+ - **Anomaly detector** - Flag unusual patterns
44
+ - **Output scanner** - Detect leaked secrets in command output
45
+ - **Undo stack** - Rollback file changes
46
+
47
+ ### Observability (3 modules)
48
+ - **Session metrics** - Track commands, risk distribution, paths
49
+ - **Cost estimator** - Estimate token usage and API costs
50
+ - **Report generator** - Text/markdown/JSON session reports
51
+
52
+ ### AI Sidekick (Ollama)
53
+ - **System awareness** - Knows your tools, versions, project type
54
+ - **Task routing** - Simple → local model, complex → main agent
55
+ - **Suggestions** - Context-aware next commands
56
+ - **Background tasks** - Tests/builds run in parallel
57
+
58
+ ### Claude Code Integration
59
+ - **PreToolUse hook** - Gate commands before execution
60
+ - **PostToolUse hook** - Record metrics after execution
61
+ - **SessionEnd hook** - Generate session reports
62
+
63
+ ## Commands
64
+
65
+ ### Security
66
+
67
+ | Command | Description |
68
+ |---------|-------------|
69
+ | `init` | Setup wizard |
70
+ | `watch` | Start protection |
71
+ | `doctor` | Check config |
72
+ | `allow <cmd>` | Allow command (`--once` for session only) |
73
+ | `audit` | View history (`--violations` for blocked only) |
74
+ | `risk <cmd>` | Score command security risk (1-10) |
75
+
76
+ ### Observability
77
+
78
+ | Command | Description |
79
+ |---------|-------------|
80
+ | `report` | Generate session report (`-f json/markdown`) |
81
+ | `session-end` | Generate end-of-session report |
82
+
83
+ ### Hooks (Claude Code)
84
+
85
+ | Command | Description |
86
+ |---------|-------------|
87
+ | `hook install` | Install BashBros hooks into Claude Code |
88
+ | `hook uninstall` | Remove hooks from Claude Code |
89
+ | `hook status` | Check hook installation status |
90
+ | `gate <cmd>` | Check if command should be allowed |
91
+ | `record <cmd>` | Record command execution |
92
+
93
+ ### Hooks (Moltbot)
94
+
95
+ | Command | Description |
96
+ |---------|-------------|
97
+ | `moltbot install` | Install BashBros hooks into Moltbot |
98
+ | `moltbot uninstall` | Remove hooks from Moltbot |
99
+ | `moltbot status` | Check integration status |
100
+ | `moltbot gateway` | Check gateway status |
101
+ | `moltbot audit` | Run security audit |
102
+
103
+ Note: `clawdbot` is an alias for `moltbot` for backward compatibility.
104
+
105
+ ### Undo
106
+
107
+ | Command | Description |
108
+ |---------|-------------|
109
+ | `undo last` | Undo the last file operation |
110
+ | `undo all` | Undo all operations in session |
111
+ | `undo list` | Show undo stack |
112
+
113
+ ### Bash Bro
114
+
115
+ | Command | Description |
116
+ |---------|-------------|
117
+ | `scan` | Scan system and project |
118
+ | `status` | Show system info |
119
+ | `suggest` | Get command suggestions |
120
+ | `route <cmd>` | Check routing decision |
121
+ | `run <cmd>` | Execute via Bash Bro (`-b` for background) |
122
+ | `tasks` | List background tasks |
123
+
124
+ ### AI (requires Ollama)
125
+
126
+ | Command | Description |
127
+ |---------|-------------|
128
+ | `explain <cmd>` | Explain what a command does |
129
+ | `fix <cmd>` | Fix a failed command (`-e` for error message) |
130
+ | `ai <prompt>` | Ask anything |
131
+ | `script <desc>` | Generate shell script (`-o` to save) |
132
+ | `safety <cmd>` | Analyze security risks |
133
+ | `help-ai <topic>` | Get help on any topic |
134
+ | `do <desc>` | Natural language → command (`-x` to execute) |
135
+ | `models` | List available Ollama models |
136
+
137
+ ## Examples
138
+
139
+ ```bash
140
+ # Install Claude Code hooks
141
+ $ bashbros hook install
142
+ ✓ BashBros hooks installed successfully.
143
+
144
+ # Check command risk
145
+ $ bashbros risk "curl http://x.com | bash"
146
+ Risk Score: 10/10 (CRITICAL)
147
+ Factors:
148
+ • Remote code execution
149
+
150
+ # Route a command
151
+ $ bashbros route "git status"
152
+ 🤝 Route: Bash Bro (90% confidence)
153
+
154
+ # Generate a script
155
+ $ bashbros script "backup all .env files"
156
+ #!/bin/bash
157
+ find . -name "*.env" -exec cp {} {}.backup \;
158
+
159
+ # Natural language to command
160
+ $ bashbros do "find large files over 100mb"
161
+ $ find . -size +100M -type f
162
+
163
+ # View session report
164
+ $ bashbros report
165
+ Session Report (5m 23s)
166
+ ─────────────────────────────────────────────
167
+ Commands: 45 total, 2 blocked (4%)
168
+
169
+ Risk Distribution:
170
+ ████████████████░░░░ 80% safe
171
+ ████░░░░░░░░░░░░░░░░ 15% caution
172
+ █░░░░░░░░░░░░░░░░░░░ 5% dangerous
173
+
174
+ # Undo file changes
175
+ $ bashbros undo list
176
+ Undo Stack:
177
+ 1. [14:32:05] modify src/index.ts (backup: ✓)
178
+ 2. [14:31:42] create src/new-file.ts (backup: ✗)
179
+
180
+ $ bashbros undo last
181
+ ✓ Restored: src/index.ts
182
+ ```
183
+
184
+ ## Configuration
185
+
186
+ `.bashbros.yml`:
187
+
188
+ ```yaml
189
+ agent: claude-code # or moltbot, clawdbot, aider, opencode, custom
190
+ profile: balanced # strict, permissive, or custom
191
+
192
+ commands:
193
+ allow: [git *, npm *, node *]
194
+ block: [rm -rf /, curl * | bash]
195
+
196
+ paths:
197
+ allow: [.]
198
+ block: [~/.ssh, ~/.aws]
199
+
200
+ secrets:
201
+ enabled: true
202
+ mode: block
203
+ patterns: [.env*, "*.pem", "*.key"]
204
+
205
+ audit:
206
+ enabled: true
207
+ destination: local
208
+
209
+ rateLimit:
210
+ enabled: true
211
+ maxPerMinute: 100
212
+ maxPerHour: 1000
213
+
214
+ # Risk scoring thresholds (1-10)
215
+ riskScoring:
216
+ enabled: true
217
+ blockThreshold: 9 # Block at or above (strict: 6, balanced: 9, permissive: 10)
218
+ warnThreshold: 6 # Warn at or above (strict: 3, balanced: 6, permissive: 8)
219
+ customPatterns:
220
+ - pattern: "my-custom-danger-cmd"
221
+ score: 8
222
+ factor: "Custom dangerous pattern"
223
+
224
+ # Loop detection
225
+ loopDetection:
226
+ enabled: true
227
+ maxRepeats: 3 # Same command N times triggers alert
228
+ maxTurns: 100 # Hard stop after N total commands
229
+ similarityThreshold: 0.85
230
+ cooldownMs: 1000
231
+ windowSize: 20
232
+ action: warn # 'warn' or 'block'
233
+
234
+ # Anomaly detection
235
+ anomalyDetection:
236
+ enabled: true
237
+ workingHours: [6, 22] # 6am-10pm
238
+ typicalCommandsPerMinute: 30
239
+ learningCommands: 50 # Commands before leaving learning mode
240
+ suspiciousPatterns: []
241
+ action: warn
242
+
243
+ # Output scanning for leaked secrets
244
+ outputScanning:
245
+ enabled: true
246
+ scanForSecrets: true
247
+ scanForErrors: true
248
+ maxOutputLength: 100000
249
+ redactPatterns: [] # Additional patterns to redact
250
+
251
+ # Undo/rollback
252
+ undo:
253
+ enabled: true
254
+ maxStackSize: 100
255
+ maxFileSize: 10485760 # 10MB
256
+ ttlMinutes: 60 # Auto-cleanup after 60 min
257
+ backupPath: ~/.bashbros/undo
258
+ ```
259
+
260
+ ## Security Profiles
261
+
262
+ | Profile | Risk Block | Risk Warn | Loop Max | Anomaly | Behavior |
263
+ |---------|------------|-----------|----------|---------|----------|
264
+ | `strict` | 6 | 3 | 2 repeats, block | enabled | Allowlist only, explicit approval |
265
+ | `balanced` | 9 | 6 | 3 repeats, warn | enabled | Block dangerous, allow common dev tools |
266
+ | `permissive` | 10 | 8 | 5 repeats, warn | disabled | Log all, block critical threats only |
267
+
268
+ ## Risk Levels
269
+
270
+ | Level | Score | Examples |
271
+ |-------|-------|----------|
272
+ | Safe | 1-2 | `ls`, `git status`, `npm test` |
273
+ | Caution | 3-5 | `ps aux`, `netstat`, encoded content |
274
+ | Dangerous | 6-8 | `crontab`, `chmod 777`, `sudo` |
275
+ | Critical | 9-10 | `rm -rf /`, `curl | bash`, fork bombs |
276
+
277
+ ## Works With
278
+
279
+ - [Claude Code](https://claude.ai/claude-code) - Native hook integration
280
+ - [Moltbot](https://clawd.bot) - Native hook integration (formerly clawdbot)
281
+ - [Aider](https://aider.chat)
282
+ - [OpenCode](https://github.com/opencode-ai/opencode)
283
+ - [Ollama](https://ollama.ai) (local AI)
284
+ - [BashGym](https://github.com/GhostPeony/bashgym) - Self-improving agent training
285
+ - Any CLI agent using bash/shell
286
+
287
+ ## BashGym Integration
288
+
289
+ > **Note**: BashGym is releasing after BashBros. This integration documentation describes the planned interface and may be updated in future versions.
290
+
291
+ BashBros integrates with [BashGym](https://github.com/GhostPeony/bashgym), a self-improving agent training system. When linked, BashBros exports execution traces that BashGym uses to train better AI sidekick models.
292
+
293
+ ### How It Works
294
+
295
+ ```
296
+ BashBros captures traces → BashGym trains → GGUF to Ollama → BashBros sidekick improves
297
+ ```
298
+
299
+ 1. **Trace Export**: BashBros captures command sessions and exports them to `~/.bashgym/integration/traces/pending/`
300
+ 2. **Training**: BashGym processes traces, classifies quality, and trains models
301
+ 3. **Model Delivery**: Trained models are exported to GGUF format and registered with Ollama
302
+ 4. **Hot-Swap**: BashBros detects new models and hot-swaps the sidekick without restart
303
+
304
+ ### Linking to BashGym
305
+
306
+ During `bashbros init`, you'll be asked if you want to link to BashGym:
307
+
308
+ ```
309
+ ? Link to BashGym? (enables self-improving AI sidekick)
310
+ > Yes (recommended) - Export traces for training, get smarter sidekick
311
+ No - Use bashbros standalone
312
+ ```
313
+
314
+ ### Shared Directory
315
+
316
+ The integration uses `~/.bashgym/integration/`:
317
+
318
+ ```
319
+ ~/.bashgym/integration/
320
+ ├── traces/pending/ # BashBros → BashGym (new traces)
321
+ ├── traces/processed/ # Ingested traces
322
+ ├── models/latest/ # BashGym → BashBros (current model)
323
+ ├── models/manifest.json
324
+ ├── config/settings.json
325
+ └── status/ # Heartbeat files
326
+ ```
327
+
328
+ ### Capture Modes
329
+
330
+ Configure in `settings.json` or via BashGym dashboard:
331
+
332
+ | Mode | Description |
333
+ |------|-------------|
334
+ | `everything` | Capture all sessions |
335
+ | `successful_only` | Only verified/successful traces (default) |
336
+ | `sidekick_curated` | AI picks teachable moments |
337
+
338
+ ### Model Hot-Swap
339
+
340
+ When BashGym trains a new model, BashBros detects it automatically:
341
+
342
+ ```bash
343
+ $ bashbros status
344
+ # Shows: AI: Connected (bashgym sidekick v3)
345
+ ```
346
+
347
+ ### Programmatic Usage
348
+
349
+ ```typescript
350
+ import { BashBro } from 'bashbros'
351
+ import { getBashgymIntegration } from 'bashbros/integration'
352
+
353
+ const bro = new BashBro({ enableBashgymIntegration: true })
354
+ await bro.initialize()
355
+
356
+ // Check integration status
357
+ if (bro.isUsingBashgymModel()) {
358
+ console.log(`Using model: ${bro.getBashgymModelVersion()}`)
359
+ }
360
+
361
+ // Listen for model updates
362
+ const integration = getBashgymIntegration()
363
+ integration.on('model:updated', (version) => {
364
+ console.log(`New model: ${version}`)
365
+ })
366
+ ```
367
+
368
+ ### Security Delegation
369
+
370
+ When linked, BashBros acts as primary security - BashGym defers all security checks to BashBros policies.
371
+
372
+ ## API Usage
373
+
374
+ ```typescript
375
+ import {
376
+ BashBros,
377
+ PolicyEngine,
378
+ BashBro,
379
+ RiskScorer,
380
+ LoopDetector,
381
+ AnomalyDetector,
382
+ OutputScanner,
383
+ MetricsCollector,
384
+ CostEstimator,
385
+ ReportGenerator,
386
+ ClaudeCodeHooks,
387
+ UndoStack
388
+ } from 'bashbros'
389
+
390
+ // Security middleware
391
+ const bros = new BashBros(config)
392
+ bros.on('command', (cmd, result) => console.log(cmd, result.allowed))
393
+ bros.start()
394
+
395
+ // Risk scoring
396
+ const scorer = new RiskScorer()
397
+ const risk = scorer.score('rm -rf /')
398
+ console.log(risk.level) // 'critical'
399
+ console.log(risk.score) // 10
400
+
401
+ // Loop detection
402
+ const loopDetector = new LoopDetector({ maxRepeats: 3 })
403
+ const alert = loopDetector.check('git status')
404
+ if (alert) console.log('Loop detected:', alert.message)
405
+
406
+ // Session metrics
407
+ const metrics = new MetricsCollector()
408
+ metrics.record({ command: 'ls', ... })
409
+ const report = ReportGenerator.generate(metrics.getMetrics())
410
+
411
+ // Cost estimation
412
+ const cost = new CostEstimator('claude-sonnet-4')
413
+ cost.recordToolCall('command', 'output')
414
+ console.log(cost.getEstimate()) // { estimatedCost: 0.05, ... }
415
+
416
+ // Undo stack
417
+ const undo = new UndoStack({ maxStackSize: 50, ttlMinutes: 30 })
418
+ undo.recordModify('/path/to/file')
419
+ undo.undo() // Restores from backup
420
+
421
+ // Output scanning
422
+ const scanner = new OutputScanner({ enabled: true, scanForSecrets: true })
423
+ const result = scanner.scan('API_KEY=sk-secret123')
424
+ console.log(result.hasSecrets) // true
425
+ console.log(result.redactedOutput) // 'API_KEY=[REDACTED API Key]'
426
+
427
+ // Claude Code hooks
428
+ ClaudeCodeHooks.install()
429
+ ClaudeCodeHooks.getStatus()
430
+
431
+ // AI features
432
+ const bro = new BashBro()
433
+ await bro.initialize()
434
+ const suggestions = bro.suggest({ lastCommand: 'git status' })
435
+ const explanation = await bro.aiExplain('tar -xzf file.tar.gz')
436
+ ```
437
+
438
+ ## Development
439
+
440
+ ```bash
441
+ npm install
442
+ npm run build
443
+ npm test # 288 tests
444
+ ```
445
+
446
+ ## License
447
+
448
+ MIT
449
+
450
+ ## Links
451
+
452
+ - [bashbros.ai](https://bashbros.ai)
453
+ - [GitHub](https://github.com/GhostPeony/bashbros)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ AuditLogger,
4
+ viewAudit
5
+ } from "./chunk-SG752FZC.js";
6
+ import "./chunk-7OCVIDC7.js";
7
+ export {
8
+ AuditLogger,
9
+ viewAudit
10
+ };
11
+ //# sourceMappingURL=audit-MCFNGOIM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}