telos-framework 0.2.0 → 0.3.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 (103) hide show
  1. package/.claude/agents/behavioral-transformation-agent.md +144 -0
  2. package/.claude/agents/command-system-agent.md +335 -0
  3. package/.claude/agents/completion-gate.md +71 -0
  4. package/.claude/agents/component-implementation-agent.md +174 -0
  5. package/.claude/agents/devops-agent.md +128 -0
  6. package/.claude/agents/dynamic-agent-creator.md +103 -0
  7. package/.claude/agents/enhanced-project-manager-agent.md +145 -0
  8. package/.claude/agents/enhanced-quality-gate.md +54 -0
  9. package/.claude/agents/feature-implementation-agent.md +148 -0
  10. package/.claude/agents/functional-testing-agent.md +51 -0
  11. package/.claude/agents/hook-integration-agent.md +204 -0
  12. package/.claude/agents/infrastructure-implementation-agent.md +175 -0
  13. package/.claude/agents/lib/research-analyzer.js +470 -0
  14. package/.claude/agents/metrics-collection-agent.md +374 -0
  15. package/.claude/agents/npx-package-agent.md +246 -0
  16. package/.claude/agents/polish-implementation-agent.md +151 -0
  17. package/.claude/agents/prd-agent.md +76 -0
  18. package/.claude/agents/prd-mvp.md +101 -0
  19. package/.claude/agents/prd-research-agent.md +482 -0
  20. package/.claude/agents/quality-agent.md +128 -0
  21. package/.claude/agents/readiness-gate.md +104 -0
  22. package/.claude/agents/research-agent.md +173 -0
  23. package/.claude/agents/routing-agent.md +108 -0
  24. package/.claude/agents/task-checker.md +163 -0
  25. package/.claude/agents/task-executor.md +107 -0
  26. package/.claude/agents/task-orchestrator.md +343 -0
  27. package/.claude/agents/tdd-validation-agent.md +187 -0
  28. package/.claude/agents/testing-implementation-agent.md +151 -0
  29. package/.claude/agents/van-maintenance-agent.md +64 -0
  30. package/.claude/agents/workflow-agent.md +87 -0
  31. package/.claude/commands/autocompact.md +41 -0
  32. package/.claude/commands/continue-handoff.md +98 -0
  33. package/.claude/commands/mock.md +45 -0
  34. package/.claude/commands/reset-handoff.md +59 -0
  35. package/.claude/commands/telos/init.md +326 -0
  36. package/.claude/commands/telos/quick.md +90 -0
  37. package/.claude/commands/telos/reset.md +100 -0
  38. package/.claude/commands/telos/status.md +170 -0
  39. package/.claude/commands/telos/validate.md +143 -0
  40. package/.claude/commands/tm/add-dependency/add-dependency.md +55 -0
  41. package/.claude/commands/tm/add-subtask/add-subtask.md +76 -0
  42. package/.claude/commands/tm/add-subtask/convert-task-to-subtask.md +71 -0
  43. package/.claude/commands/tm/add-task/add-task.md +78 -0
  44. package/.claude/commands/tm/analyze-complexity/analyze-complexity.md +121 -0
  45. package/.claude/commands/tm/clear-subtasks/clear-all-subtasks.md +93 -0
  46. package/.claude/commands/tm/clear-subtasks/clear-subtasks.md +86 -0
  47. package/.claude/commands/tm/complexity-report/complexity-report.md +117 -0
  48. package/.claude/commands/tm/expand/expand-all-tasks.md +51 -0
  49. package/.claude/commands/tm/expand/expand-task.md +49 -0
  50. package/.claude/commands/tm/fix-dependencies/fix-dependencies.md +81 -0
  51. package/.claude/commands/tm/generate/generate-tasks.md +121 -0
  52. package/.claude/commands/tm/help.md +81 -0
  53. package/.claude/commands/tm/init/init-project-quick.md +46 -0
  54. package/.claude/commands/tm/init/init-project.md +50 -0
  55. package/.claude/commands/tm/learn.md +103 -0
  56. package/.claude/commands/tm/list/list-tasks-by-status.md +39 -0
  57. package/.claude/commands/tm/list/list-tasks-with-subtasks.md +29 -0
  58. package/.claude/commands/tm/list/list-tasks.md +43 -0
  59. package/.claude/commands/tm/models/setup-models.md +51 -0
  60. package/.claude/commands/tm/models/view-models.md +51 -0
  61. package/.claude/commands/tm/next/next-task.md +66 -0
  62. package/.claude/commands/tm/parse-prd/parse-prd-with-research.md +48 -0
  63. package/.claude/commands/tm/parse-prd/parse-prd.md +49 -0
  64. package/.claude/commands/tm/remove-dependency/remove-dependency.md +62 -0
  65. package/.claude/commands/tm/remove-subtask/remove-subtask.md +84 -0
  66. package/.claude/commands/tm/remove-task/remove-task.md +107 -0
  67. package/.claude/commands/tm/set-status/to-cancelled.md +55 -0
  68. package/.claude/commands/tm/set-status/to-deferred.md +47 -0
  69. package/.claude/commands/tm/set-status/to-done.md +44 -0
  70. package/.claude/commands/tm/set-status/to-in-progress.md +36 -0
  71. package/.claude/commands/tm/set-status/to-pending.md +32 -0
  72. package/.claude/commands/tm/set-status/to-review.md +40 -0
  73. package/.claude/commands/tm/setup/install-taskmaster.md +117 -0
  74. package/.claude/commands/tm/setup/quick-install-taskmaster.md +22 -0
  75. package/.claude/commands/tm/show/show-task.md +82 -0
  76. package/.claude/commands/tm/status/project-status.md +64 -0
  77. package/.claude/commands/tm/sync-readme/sync-readme.md +117 -0
  78. package/.claude/commands/tm/tm-main.md +146 -0
  79. package/.claude/commands/tm/update/update-single-task.md +119 -0
  80. package/.claude/commands/tm/update/update-task.md +72 -0
  81. package/.claude/commands/tm/update/update-tasks-from-id.md +108 -0
  82. package/.claude/commands/tm/utils/analyze-project.md +97 -0
  83. package/.claude/commands/tm/validate-dependencies/validate-dependencies.md +71 -0
  84. package/.claude/commands/tm/workflows/auto-implement-tasks.md +97 -0
  85. package/.claude/commands/tm/workflows/command-pipeline.md +77 -0
  86. package/.claude/commands/tm/workflows/smart-workflow.md +55 -0
  87. package/.claude/commands/van.md +150 -0
  88. package/.claude/docs/README.md +214 -0
  89. package/.claude/docs/TROUBLESHOOTING.md +126 -0
  90. package/.claude/hooks/block-destructive-commands.sh +243 -0
  91. package/.claude/hooks/collective-metrics.sh +291 -0
  92. package/.claude/hooks/directive-enforcer.sh +117 -0
  93. package/.claude/hooks/load-behavioral-system.sh +49 -0
  94. package/.claude/hooks/routing-executor.sh +4 -0
  95. package/.claude/hooks/test-driven-handoff.sh +653 -0
  96. package/.claude/settings.json +125 -0
  97. package/README.md +39 -15
  98. package/lib/commands/init.js +52 -157
  99. package/lib/installers/memory-files.js +77 -0
  100. package/lib/installers/slash-commands.js +77 -0
  101. package/package.json +7 -2
  102. package/templates/AGENTS.md +79 -0
  103. package/templates/CLAUDE.md +54 -0
@@ -0,0 +1,214 @@
1
+ # Claude Code Sub-Agent Collective
2
+
3
+ ## 📖 System Overview
4
+
5
+ Welcome to your Claude Code Sub-Agent Collective installation! This system implements a research framework for reliable multi-agent coordination using hub-and-spoke architecture.
6
+
7
+ ### What Just Happened?
8
+
9
+ The collective has been installed in your project with the following components:
10
+
11
+ #### 🧠 Behavioral Operating System (`CLAUDE.md`)
12
+ This file contains the core behavioral directives that govern how the collective operates:
13
+ - **Directive 1**: Never implement directly - all work flows through agents
14
+ - **Directive 2**: Hub-and-spoke routing - all requests go through @routing-agent
15
+ - **Directive 3**: Test-driven validation - handoffs include contract validation
16
+
17
+ #### 🤖 Agent Definitions (`.claude/agents/`)
18
+ Each agent has specific capabilities and responsibilities:
19
+ - **@routing-agent**: Central hub for semantic request analysis and routing
20
+ - **@testing-implementation-agent**: Handles test frameworks and validation
21
+ - **@behavioral-transformation-agent**: Manages behavioral system changes
22
+ - **@hook-integration-agent**: Implements and manages hook systems
23
+
24
+ #### 🪝 Hook Scripts (`.claude/hooks/`)
25
+ Enforcement mechanisms that ensure directive compliance:
26
+ - **directive-enforcer.sh**: Validates behavioral directives before tool execution
27
+ - **collective-metrics.sh**: Collects performance and research metrics
28
+ - **test-driven-handoff.sh**: Validates handoff contracts during transitions
29
+ - **routing-executor.sh**: Executes routing decisions and agent handoffs
30
+
31
+ #### 🧪 Testing Framework (`.claude-collective/`)
32
+ Complete testing system for validating collective behavior:
33
+ - **Jest configuration**: Set up for contract validation testing
34
+ - **Test contracts**: Templates for handoff validation
35
+ - **Metrics collection**: Research data gathering
36
+
37
+ ## 🚀 Getting Started
38
+
39
+ ### 1. Restart Claude Code
40
+ **IMPORTANT**: Restart Claude Code to activate the hook system and agents.
41
+
42
+ ### 2. Test the Installation
43
+ Try these commands to verify everything works:
44
+
45
+ ```bash
46
+ # Check status
47
+ npx claude-code-collective status
48
+
49
+ # Validate installation
50
+ npx claude-code-collective validate
51
+ ```
52
+
53
+ ### 3. Try Agent Routing
54
+ In Claude Code, try a request like:
55
+ > "Route this through @routing-agent to create a login component with validation"
56
+
57
+ ## 🎯 How to Use the Collective
58
+
59
+ ### Making Requests
60
+ Instead of asking Claude directly, route requests through agents:
61
+
62
+ **❌ Old Way (Direct):**
63
+ > "Create a login form component"
64
+
65
+ **✅ New Way (Agent Routed):**
66
+ > "Route to @routing-agent: Create a login form component with React hooks"
67
+
68
+ ### Understanding Agent Routing
69
+ The @routing-agent will analyze your request and select the best agent:
70
+ - **Implementation tasks** → @implementation-agent
71
+ - **Testing tasks** → @testing-implementation-agent
72
+ - **Research tasks** → @research-agent
73
+ - **Hook/behavioral tasks** → @hook-integration-agent
74
+
75
+ ### Monitoring Activity
76
+ - **Metrics**: Check `.claude-collective/metrics/` for performance data
77
+ - **Logs**: Review `/tmp/collective-*.log` for detailed activity
78
+ - **Status**: Run `npx claude-code-collective status` for health check
79
+
80
+ ## 📊 Research Framework
81
+
82
+ This collective is designed to prove three key hypotheses:
83
+
84
+ ### H1: JIT Context Loading
85
+ **Theory**: Loading context on-demand is more efficient than pre-loading
86
+ **Measurement**: Context size, token reduction, load times
87
+ **Goal**: >30% reduction in token usage
88
+
89
+ ### H2: Hub-and-Spoke Coordination
90
+ **Theory**: Central routing outperforms peer-to-peer communication
91
+ **Measurement**: Routing accuracy, coordination overhead, violations
92
+ **Goal**: >95% routing compliance
93
+
94
+ ### H3: Test-Driven Handoffs
95
+ **Theory**: Contract-based handoffs improve quality
96
+ **Measurement**: Handoff success rates, test pass rates, retry counts
97
+ **Goal**: >98% handoff success rate
98
+
99
+ ## 🛡️ Behavioral Directives
100
+
101
+ The collective enforces three prime directives through hooks:
102
+
103
+ ### Directive 1: Never Implement Directly
104
+ - All implementation must flow through specialized agents
105
+ - Direct coding by the hub controller is blocked
106
+ - Violations trigger re-routing to @routing-agent
107
+
108
+ ### Directive 2: Collective Routing Protocol
109
+ - All requests enter through @routing-agent
110
+ - No direct agent-to-agent communication allowed
111
+ - Hub-and-spoke pattern strictly maintained
112
+
113
+ ### Directive 3: Test-Driven Validation
114
+ - Handoffs require test contracts with pre/post conditions
115
+ - Failed validation triggers automatic re-routing
116
+ - Quality gates ensure delivery standards
117
+
118
+ ## 🔧 Configuration
119
+
120
+ ### Hook Configuration (`.claude/settings.json`)
121
+ Controls when and how hooks execute:
122
+ - **PreToolUse**: Validates directives before tool execution
123
+ - **PostToolUse**: Collects metrics and validates results
124
+ - **SubagentStop**: Ensures proper handoff validation
125
+
126
+ ### Agent Configuration (`.claude/agents/*.json`)
127
+ Each agent definition includes:
128
+ - **Capabilities**: What the agent can do
129
+ - **Tools**: Which Claude Code tools they can access
130
+ - **Specialization**: Their primary focus area
131
+ - **Fallbacks**: Alternative agents if unavailable
132
+
133
+ ### Testing Configuration (`.claude-collective/`)
134
+ Jest-based testing framework:
135
+ - **Contract templates**: Pre-built validation patterns
136
+ - **Test suites**: Handoff, directive, and contract tests
137
+ - **Coverage reporting**: Quality metrics and reporting
138
+
139
+ ## 🚨 Important Notes
140
+
141
+ ### System Behavior Changes
142
+ With the collective active, Claude Code will behave differently:
143
+ - **Routing Required**: Direct implementation requests may be blocked
144
+ - **Hook Validation**: Actions are validated before execution
145
+ - **Metrics Collection**: Performance data is automatically gathered
146
+ - **Quality Gates**: Failed handoffs trigger retries or escalation
147
+
148
+ ### Troubleshooting
149
+ If something isn't working:
150
+ 1. **Restart Claude Code** - Hooks need to be reloaded
151
+ 2. **Check Status** - Run `npx claude-code-collective status`
152
+ 3. **Validate Installation** - Run `npx claude-code-collective validate`
153
+ 4. **Review Logs** - Check `/tmp/collective-*.log` files
154
+ 5. **Repair Installation** - Run `npx claude-code-collective repair`
155
+
156
+ ### Getting Help
157
+ - **Status Command**: `npx claude-code-collective status`
158
+ - **Validation**: `npx claude-code-collective validate`
159
+ - **Repair**: `npx claude-code-collective repair`
160
+ - **Documentation**: Review the files in `.claude/docs/`
161
+
162
+ ## 🔬 Research Participation
163
+
164
+ By using this collective, you're participating in research on:
165
+ - **Multi-agent coordination patterns**
166
+ - **Context engineering efficiency**
167
+ - **Test-driven development practices**
168
+ - **Behavioral enforcement systems**
169
+
170
+ Metrics are collected automatically (no personal data) to validate the research hypotheses.
171
+
172
+ ## 🎯 Quick Reference
173
+
174
+ ### Essential Commands
175
+ ```bash
176
+ # Check collective health
177
+ npx claude-code-collective status
178
+
179
+ # Validate everything is working
180
+ npx claude-code-collective validate
181
+
182
+ # Fix problems
183
+ npx claude-code-collective repair
184
+
185
+ # Remove collective
186
+ npx claude-code-collective clean
187
+ ```
188
+
189
+ ### Agent Routing Examples
190
+ ```
191
+ "@routing-agent please create a user authentication system"
192
+ "Route to appropriate agent: implement API endpoint for user login"
193
+ "@routing-agent analyze the current codebase structure"
194
+ ```
195
+
196
+ ### File Structure
197
+ ```
198
+ .claude/
199
+ ├── settings.json # Hook configuration
200
+ ├── agents/ # Agent definitions
201
+ ├── hooks/ # Enforcement scripts
202
+ └── docs/ # This documentation
203
+
204
+ .claude-collective/
205
+ ├── tests/ # Contract validation
206
+ ├── metrics/ # Research data
207
+ └── package.json # Testing framework
208
+ ```
209
+
210
+ ---
211
+
212
+ **Welcome to the future of AI-assisted development!** 🚀
213
+
214
+ The collective is now active and ready to coordinate your development work through intelligent agent routing and quality assurance.
@@ -0,0 +1,126 @@
1
+ # Claude Code Sub-Agent Collective - Troubleshooting Guide
2
+
3
+ ## Common Installation Issues
4
+
5
+ ### Template Files Not Found
6
+ **Problem**: Warning messages about missing template files during installation.
7
+ **Solution**:
8
+ 1. Ensure you're using the latest version: `npx claude-code-collective@latest`
9
+ 2. Clear npm cache: `npm cache clean --force`
10
+ 3. Try installing with `--force` flag: `npx claude-code-collective --force`
11
+
12
+ ### Permission Errors
13
+ **Problem**: EACCES errors when installing hooks or files.
14
+ **Solution**:
15
+ 1. Run with appropriate permissions
16
+ 2. Check directory ownership: `ls -la .claude/`
17
+ 3. Fix permissions: `chmod +x .claude/hooks/*.sh`
18
+
19
+ ### Hook Execution Failures
20
+ **Problem**: Hooks fail to execute or show permission denied.
21
+ **Solution**:
22
+ 1. Make hooks executable: `chmod +x .claude/hooks/*.sh`
23
+ 2. Check shell compatibility (bash required)
24
+ 3. Verify hook syntax: `bash -n .claude/hooks/directive-enforcer.sh`
25
+
26
+ ## Agent System Issues
27
+
28
+ ### Agent Not Found
29
+ **Problem**: Agent files exist but system doesn't recognize them.
30
+ **Solution**:
31
+ 1. Check file extension (should be `.md`)
32
+ 2. Verify agent metadata format
33
+ 3. Restart Claude Code to refresh agent registry
34
+
35
+ ### Routing Failures
36
+ **Problem**: Requests don't route to expected agents.
37
+ **Solution**:
38
+ 1. Check CLAUDE.md routing patterns
39
+ 2. Verify agent capabilities in metadata
40
+ 3. Enable debug logging: add `--verbose` to commands
41
+
42
+ ### Test Failures
43
+ **Problem**: TDD handoff tests fail unexpectedly.
44
+ **Solution**:
45
+ 1. Run tests individually: `npm test -- --testNamePattern="specific test"`
46
+ 2. Check contract definitions in test files
47
+ 3. Verify agent implementations match contracts
48
+
49
+ ## Configuration Issues
50
+
51
+ ### Settings Not Applied
52
+ **Problem**: Changes to `.claude/settings.json` don't take effect.
53
+ **Solution**:
54
+ 1. Restart Claude Code completely
55
+ 2. Check JSON syntax: `node -e "JSON.parse(require('fs').readFileSync('.claude/settings.json'))"`
56
+ 3. Verify hook configuration syntax
57
+
58
+ ### Metrics Collection Disabled
59
+ **Problem**: Research metrics aren't being collected.
60
+ **Solution**:
61
+ 1. Enable in research.config.json: `"enabled": true`
62
+ 2. Check storage permissions in metrics directory
63
+ 3. Verify MetricsCollector initialization
64
+
65
+ ## Performance Issues
66
+
67
+ ### Slow Agent Spawning
68
+ **Problem**: Agent creation takes longer than expected.
69
+ **Solution**:
70
+ 1. Check JIT loading configuration
71
+ 2. Reduce template complexity
72
+ 3. Monitor resource usage during spawning
73
+
74
+ ### High Memory Usage
75
+ **Problem**: System uses excessive memory during operations.
76
+ **Solution**:
77
+ 1. Adjust cleanup thresholds in AgentRegistry
78
+ 2. Enable periodic garbage collection
79
+ 3. Limit concurrent agent operations
80
+
81
+ ## Debug Mode
82
+
83
+ Enable verbose logging for detailed troubleshooting:
84
+
85
+ ```bash
86
+ # Set debug environment
87
+ export DEBUG=claude-collective:*
88
+
89
+ # Run with verbose output
90
+ npx claude-code-collective --verbose --debug
91
+ ```
92
+
93
+ ## Getting Help
94
+
95
+ 1. **Documentation**: Check `.claude/docs/README.md` for system overview
96
+ 2. **Test Results**: Run `npm test` in `.claude-collective/` for system health
97
+ 3. **Log Files**: Check `.claude-collective/logs/` for detailed error logs
98
+ 4. **GitHub Issues**: Report bugs at the project repository
99
+
100
+ ## System Validation
101
+
102
+ Run the built-in validation to check system health:
103
+
104
+ ```bash
105
+ cd .claude-collective
106
+ npm test
107
+ npm run validate
108
+ ```
109
+
110
+ Expected output: All tests passing, no validation errors.
111
+
112
+ ## Reset Instructions
113
+
114
+ To completely reset the collective system:
115
+
116
+ ```bash
117
+ # Remove all collective files
118
+ rm -rf .claude/agents/*
119
+ rm -rf .claude/hooks/*
120
+ rm -rf .claude-collective/
121
+
122
+ # Reinstall
123
+ npx claude-code-collective --force
124
+ ```
125
+
126
+ **Warning**: This will remove all customizations and configurations.
@@ -0,0 +1,243 @@
1
+ #!/bin/sh
2
+ # block-destructive-commands.sh
3
+ # PreToolUse Hook - Block destructive commands before execution
4
+ # Exit code 2 = BLOCK execution, Exit code 0 = ALLOW execution
5
+
6
+ # Set up logging
7
+ LOG_FILE="/tmp/blocked-commands.log"
8
+ timestamp() { date '+%Y-%m-%d %H:%M:%S'; }
9
+
10
+ log() {
11
+ echo "[$(timestamp)] $1" >> "$LOG_FILE"
12
+ }
13
+
14
+ # Read JSON input from stdin
15
+ INPUT_JSON=$(cat)
16
+
17
+ # Parse JSON using robust extraction (similar to test-driven-handoff.sh pattern)
18
+ TOOL_NAME=""
19
+ COMMAND=""
20
+
21
+ # Try direct jq extraction first
22
+ if command -v jq >/dev/null 2>&1; then
23
+ TOOL_NAME=$(echo "$INPUT_JSON" | jq -r '.tool_name' 2>/dev/null)
24
+ COMMAND=$(echo "$INPUT_JSON" | jq -r '.tool_input.command // ""' 2>/dev/null)
25
+ fi
26
+
27
+ # Fallback to grep/sed if jq fails or returns null
28
+ if [ -z "$TOOL_NAME" ] || [ "$TOOL_NAME" = "null" ]; then
29
+ TOOL_NAME=$(echo "$INPUT_JSON" | grep -o '"tool_name":"[^"]*"' | cut -d'"' -f4)
30
+ fi
31
+
32
+ if [ -z "$COMMAND" ] || [ "$COMMAND" = "null" ]; then
33
+ COMMAND=$(echo "$INPUT_JSON" | grep -o '"command":"[^"]*"' | sed 's/.*"command":"\([^"]*\)".*/\1/')
34
+ fi
35
+
36
+ # Only check Bash tool commands
37
+ if [ "$TOOL_NAME" != "Bash" ]; then
38
+ log "Skipping non-Bash tool: $TOOL_NAME"
39
+ exit 0
40
+ fi
41
+
42
+ log "Checking command for destructive patterns: $COMMAND"
43
+
44
+ # Function to block command with reason
45
+ block_command() {
46
+ local reason="$1"
47
+ local command="$2"
48
+
49
+ echo "🚫 BLOCKED: $reason" >&2
50
+ echo "Command: $command" >&2
51
+ echo "Use manual approval or sandbox environment for dangerous operations" >&2
52
+
53
+ log "BLOCKED: $reason - Command: $command"
54
+ exit 2 # Claude Code convention for blocking
55
+ }
56
+
57
+ # Check for filesystem destruction patterns
58
+ check_filesystem_destruction() {
59
+ local cmd="$1"
60
+
61
+ # Recursive force deletion
62
+ if echo "$cmd" | grep -qiE "rm\s+.*-.*r.*f|rm\s+.*-.*f.*r"; then
63
+ block_command "recursive force deletion (rm -rf)" "$cmd"
64
+ fi
65
+
66
+ # Recursive deletion without confirmation
67
+ if echo "$cmd" | grep -qiE "rm\s+.*-r\s+"; then
68
+ block_command "recursive deletion without confirmation" "$cmd"
69
+ fi
70
+
71
+ # Format commands
72
+ if echo "$cmd" | grep -qiE "mkfs\.|format\s+"; then
73
+ block_command "filesystem formatting command" "$cmd"
74
+ fi
75
+
76
+ # Direct device writing
77
+ if echo "$cmd" | grep -qiE "dd\s+.*of=/dev/"; then
78
+ block_command "direct device writing with dd" "$cmd"
79
+ fi
80
+
81
+ # System directory modifications
82
+ if echo "$cmd" | grep -qE ">\s*/etc/|>\s*/boot/|>\s*/sys/|>\s*/proc/"; then
83
+ block_command "writing to critical system directories" "$cmd"
84
+ fi
85
+ }
86
+
87
+ # Check for git destructive operations
88
+ check_git_destruction() {
89
+ local cmd="$1"
90
+
91
+ # Hard reset (loses uncommitted changes)
92
+ if echo "$cmd" | grep -qiE "git\s+reset\s+--hard"; then
93
+ block_command "git hard reset loses uncommitted changes" "$cmd"
94
+ fi
95
+
96
+ # Force clean working directory
97
+ if echo "$cmd" | grep -qiE "git\s+clean\s+.*-.*f.*d|git\s+clean\s+.*-.*d.*f"; then
98
+ block_command "git force clean removes untracked files" "$cmd"
99
+ fi
100
+
101
+ # Force push (can overwrite remote history)
102
+ if echo "$cmd" | grep -qiE "git\s+push\s+.*--force"; then
103
+ block_command "git force push can overwrite remote history" "$cmd"
104
+ fi
105
+
106
+ # Rebase with force
107
+ if echo "$cmd" | grep -qiE "git\s+rebase\s+.*--force"; then
108
+ block_command "git force rebase can lose commits" "$cmd"
109
+ fi
110
+ }
111
+
112
+ # Check for package manager destructive operations
113
+ check_package_manager_destruction() {
114
+ local cmd="$1"
115
+
116
+ # npm create commands (can overwrite directories)
117
+ if echo "$cmd" | grep -qiE "npm\s+create\s+"; then
118
+ block_command "npm create can overwrite existing directories" "$cmd"
119
+ fi
120
+
121
+ # npx create commands
122
+ if echo "$cmd" | grep -qiE "npx\s+create-"; then
123
+ block_command "npx create commands can overwrite files" "$cmd"
124
+ fi
125
+
126
+ # yarn create commands
127
+ if echo "$cmd" | grep -qiE "yarn\s+create\s+"; then
128
+ block_command "yarn create can overwrite directories" "$cmd"
129
+ fi
130
+
131
+ # pnpm create commands
132
+ if echo "$cmd" | grep -qiE "pnpm\s+create\s+"; then
133
+ block_command "pnpm create can overwrite directories" "$cmd"
134
+ fi
135
+
136
+ # Force package installations (can break dependencies)
137
+ if echo "$cmd" | grep -qiE "npm\s+install\s+.*--force"; then
138
+ block_command "npm install --force can break dependencies" "$cmd"
139
+ fi
140
+
141
+ # pip force reinstall
142
+ if echo "$cmd" | grep -qiE "pip\s+install\s+.*--force-reinstall"; then
143
+ block_command "pip force reinstall can break dependencies" "$cmd"
144
+ fi
145
+ }
146
+
147
+ # Check for database destruction
148
+ check_database_destruction() {
149
+ local cmd="$1"
150
+
151
+ # Drop database/table commands
152
+ if echo "$cmd" | grep -qiE "drop\s+(database|table|schema)"; then
153
+ block_command "database/table/schema drop command" "$cmd"
154
+ fi
155
+
156
+ # Truncate table commands
157
+ if echo "$cmd" | grep -qiE "truncate\s+table"; then
158
+ block_command "table truncation command" "$cmd"
159
+ fi
160
+
161
+ # Dangerous DELETE statements
162
+ if echo "$cmd" | grep -qiE "delete\s+from.*where\s+1\s*=\s*1"; then
163
+ block_command "delete all rows statement" "$cmd"
164
+ fi
165
+ }
166
+
167
+ # Check for docker/container destruction
168
+ check_container_destruction() {
169
+ local cmd="$1"
170
+
171
+ # Docker system prune
172
+ if echo "$cmd" | grep -qiE "docker\s+system\s+prune\s+.*-f"; then
173
+ block_command "docker force system prune removes all unused data" "$cmd"
174
+ fi
175
+
176
+ # Docker remove all containers
177
+ if echo "$cmd" | grep -qiE "docker\s+rm\s+.*\$\(docker\s+ps"; then
178
+ block_command "docker remove all containers command" "$cmd"
179
+ fi
180
+
181
+ # Kubernetes force delete
182
+ if echo "$cmd" | grep -qiE "kubectl\s+delete\s+.*--force"; then
183
+ block_command "kubectl force delete can cause data loss" "$cmd"
184
+ fi
185
+ }
186
+
187
+ # Check for network/download risks (Anthropic recommends blocking curl/wget)
188
+ check_network_risks() {
189
+ local cmd="$1"
190
+
191
+ # curl downloads to sensitive locations
192
+ if echo "$cmd" | grep -qiE "curl\s+.*>\s*/etc/|curl\s+.*>\s*/usr/|curl\s+.*>\s*/bin/"; then
193
+ block_command "curl download to system directories" "$cmd"
194
+ fi
195
+
196
+ # wget downloads to sensitive locations
197
+ if echo "$cmd" | grep -qiE "wget\s+.*-O\s*/etc/|wget\s+.*-O\s*/usr/|wget\s+.*-O\s*/bin/"; then
198
+ block_command "wget download to system directories" "$cmd"
199
+ fi
200
+
201
+ # Piping untrusted content directly (Anthropic warns against this)
202
+ if echo "$cmd" | grep -qiE "curl\s+.*\|\s*(sh|bash|zsh)|wget\s+.*\|\s*(sh|bash|zsh)"; then
203
+ block_command "piping downloaded content to shell is dangerous" "$cmd"
204
+ fi
205
+ }
206
+
207
+ # Check for process/system destruction
208
+ check_system_destruction() {
209
+ local cmd="$1"
210
+
211
+ # Kill all processes
212
+ if echo "$cmd" | grep -qiE "killall\s+.*-9"; then
213
+ block_command "killall with SIGKILL can cause data loss" "$cmd"
214
+ fi
215
+
216
+ # System shutdown/reboot
217
+ if echo "$cmd" | grep -qiE "shutdown\s+|reboot\s+|halt\s+"; then
218
+ block_command "system shutdown/reboot command" "$cmd"
219
+ fi
220
+
221
+ # chmod 777 on system directories
222
+ if echo "$cmd" | grep -qE "chmod\s+777\s+/"; then
223
+ block_command "chmod 777 on system directories is dangerous" "$cmd"
224
+ fi
225
+
226
+ # Suspicious bash with encoded content
227
+ if echo "$cmd" | grep -qiE "bash\s+-c\s+.*base64|sh\s+-c\s+.*base64"; then
228
+ block_command "suspicious encoded bash execution" "$cmd"
229
+ fi
230
+ }
231
+
232
+ # Run all destructive command checks
233
+ check_filesystem_destruction "$COMMAND"
234
+ check_git_destruction "$COMMAND"
235
+ check_package_manager_destruction "$COMMAND"
236
+ check_database_destruction "$COMMAND"
237
+ check_container_destruction "$COMMAND"
238
+ check_network_risks "$COMMAND"
239
+ check_system_destruction "$COMMAND"
240
+
241
+ # If we get here, command is safe to execute
242
+ log "ALLOWED: $COMMAND"
243
+ exit 0