@paulduvall/claude-dev-toolkit 0.0.1-alpha.2 → 0.0.1-alpha.21
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/LICENSE +21 -0
- package/README.md +88 -37
- package/bin/claude-commands +307 -65
- package/commands/active/xarchitecture.md +393 -0
- package/commands/active/xconfig.md +127 -0
- package/commands/active/xcontinue.md +92 -0
- package/commands/active/xdebug.md +130 -0
- package/commands/active/xdocs.md +178 -0
- package/commands/active/xexplore.md +94 -0
- package/commands/active/xgit.md +149 -0
- package/commands/active/xpipeline.md +152 -0
- package/commands/active/xquality.md +96 -0
- package/commands/active/xrefactor.md +198 -0
- package/commands/active/xrelease.md +142 -0
- package/commands/active/xsecurity.md +92 -0
- package/commands/active/xspec.md +174 -0
- package/commands/active/xtdd.md +151 -0
- package/commands/active/xtest.md +89 -0
- package/commands/active/xverify.md +80 -0
- package/commands/experiments/xact.md +742 -0
- package/commands/experiments/xanalytics.md +113 -0
- package/commands/experiments/xanalyze.md +70 -0
- package/commands/experiments/xapi.md +161 -0
- package/commands/experiments/xatomic.md +112 -0
- package/commands/experiments/xaws.md +85 -0
- package/commands/experiments/xcicd.md +337 -0
- package/commands/experiments/xcommit.md +122 -0
- package/commands/experiments/xcompliance.md +182 -0
- package/commands/experiments/xconstraints.md +89 -0
- package/commands/experiments/xcoverage.md +90 -0
- package/commands/experiments/xdb.md +102 -0
- package/commands/experiments/xdesign.md +121 -0
- package/commands/experiments/xdevcontainer.md +238 -0
- package/commands/experiments/xevaluate.md +111 -0
- package/commands/experiments/xfootnote.md +12 -0
- package/commands/experiments/xgenerate.md +117 -0
- package/commands/experiments/xgovernance.md +149 -0
- package/commands/experiments/xgreen.md +66 -0
- package/commands/experiments/xiac.md +118 -0
- package/commands/experiments/xincident.md +137 -0
- package/commands/experiments/xinfra.md +115 -0
- package/commands/experiments/xknowledge.md +115 -0
- package/commands/experiments/xmaturity.md +120 -0
- package/commands/experiments/xmetrics.md +118 -0
- package/commands/experiments/xmonitoring.md +128 -0
- package/commands/experiments/xnew.md +903 -0
- package/commands/experiments/xobservable.md +114 -0
- package/commands/experiments/xoidc.md +165 -0
- package/commands/experiments/xoptimize.md +115 -0
- package/commands/experiments/xperformance.md +112 -0
- package/commands/experiments/xplanning.md +131 -0
- package/commands/experiments/xpolicy.md +115 -0
- package/commands/experiments/xproduct.md +98 -0
- package/commands/experiments/xreadiness.md +75 -0
- package/commands/experiments/xred.md +55 -0
- package/commands/experiments/xrisk.md +128 -0
- package/commands/experiments/xrules.md +124 -0
- package/commands/experiments/xsandbox.md +120 -0
- package/commands/experiments/xscan.md +102 -0
- package/commands/experiments/xsetup.md +123 -0
- package/commands/experiments/xtemplate.md +116 -0
- package/commands/experiments/xtrace.md +212 -0
- package/commands/experiments/xux.md +171 -0
- package/commands/experiments/xvalidate.md +104 -0
- package/commands/experiments/xworkflow.md +113 -0
- package/hooks/.smellrc.example.json +19 -0
- package/hooks/README.md +263 -0
- package/hooks/check-commit-signing.py +127 -0
- package/hooks/check-complexity.py +38 -0
- package/hooks/check-security.py +37 -0
- package/hooks/claude-wrapper.sh +29 -0
- package/hooks/config.py +110 -0
- package/hooks/file-logger.sh +100 -0
- package/hooks/lib/argument-parser.sh +427 -0
- package/hooks/lib/config-constants.sh +230 -0
- package/hooks/lib/context-manager.sh +560 -0
- package/hooks/lib/error-handler.sh +423 -0
- package/hooks/lib/execution-engine.sh +444 -0
- package/hooks/lib/execution-results.sh +113 -0
- package/hooks/lib/execution-simulation.sh +114 -0
- package/hooks/lib/field-validators.sh +104 -0
- package/hooks/lib/file-utils.sh +398 -0
- package/hooks/lib/subagent-discovery.sh +468 -0
- package/hooks/lib/subagent-validator.sh +407 -0
- package/hooks/lib/validation-reporter.sh +134 -0
- package/hooks/on-error-debug.sh +226 -0
- package/hooks/pre-commit-quality.sh +204 -0
- package/hooks/pre-commit-test-runner.sh +132 -0
- package/hooks/pre-write-security.sh +115 -0
- package/hooks/prevent-credential-exposure.sh +279 -0
- package/hooks/security_bandit.py +177 -0
- package/hooks/security_checks.py +97 -0
- package/hooks/security_secrets.py +81 -0
- package/hooks/security_trojan.py +61 -0
- package/hooks/settings.example.json +52 -0
- package/hooks/smell_checks.py +238 -0
- package/hooks/smell_javascript.py +231 -0
- package/hooks/smell_python.py +110 -0
- package/hooks/smell_ruff.py +70 -0
- package/hooks/smell_types.py +72 -0
- package/hooks/subagent-trigger-simple.sh +202 -0
- package/hooks/subagent-trigger.sh +253 -0
- package/hooks/suppression.py +82 -0
- package/hooks/tab-color.sh +70 -0
- package/hooks/verify-before-edit.sh +135 -0
- package/lib/backup-restore-command.js +140 -0
- package/lib/base/base-command.js +252 -0
- package/lib/base/command-result.js +184 -0
- package/lib/config/constants.js +255 -0
- package/lib/config.js +48 -6
- package/lib/configure-command.js +428 -0
- package/lib/dependency-validator.js +64 -5
- package/lib/hook-installer-core.js +2 -2
- package/lib/installation-instruction-generator.js +213 -495
- package/lib/installer.js +134 -56
- package/lib/oidc-command.js +740 -0
- package/lib/services/backup-list-service.js +226 -0
- package/lib/services/backup-service.js +230 -0
- package/lib/services/command-installer-service.js +217 -0
- package/lib/services/logger-service.js +201 -0
- package/lib/services/package-manager-service.js +319 -0
- package/lib/services/platform-instruction-service.js +294 -0
- package/lib/services/recovery-instruction-service.js +348 -0
- package/lib/services/restore-service.js +221 -0
- package/lib/setup-command.js +359 -0
- package/lib/setup-wizard.js +155 -262
- package/lib/uninstall-command.js +100 -0
- package/lib/utils/claude-path-config.js +184 -0
- package/lib/utils/file-system-utils.js +152 -0
- package/lib/utils.js +8 -4
- package/lib/verify-command.js +430 -0
- package/package.json +7 -3
- package/scripts/postinstall.js +172 -157
- package/subagents/debug-specialist.md +7 -0
- package/templates/README.md +115 -0
- package/templates/basic-settings.json +30 -0
- package/templates/comprehensive-settings.json +57 -0
- package/templates/global-claude.md +344 -0
- package/templates/hybrid-hook-config.yaml +132 -0
- package/templates/security-focused-settings.json +62 -0
- package/templates/subagent-hooks.yaml +188 -0
- package/lib/package-manager-service.js +0 -270
- package/subagents/debug-context.md +0 -197
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Manage and enforce development constraints for quality and compliance
|
|
3
|
+
tags: [constraints, quality, compliance, validation, governance]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Manage development constraints based on the arguments provided in $ARGUMENTS.
|
|
7
|
+
|
|
8
|
+
First, check for existing constraint configuration:
|
|
9
|
+
!ls -la .constraints.yml .constraints.yaml 2>/dev/null || echo "No constraint configuration found"
|
|
10
|
+
!find . -name "*constraint*" -o -name "*rule*" | head -5
|
|
11
|
+
|
|
12
|
+
Based on $ARGUMENTS, perform the appropriate constraint operation:
|
|
13
|
+
|
|
14
|
+
## 1. Define New Constraints
|
|
15
|
+
|
|
16
|
+
If defining constraints (--define):
|
|
17
|
+
!touch .constraints.yml
|
|
18
|
+
!echo "Adding constraint: $constraint_name" >> .constraints.yml
|
|
19
|
+
|
|
20
|
+
Common constraint types to define:
|
|
21
|
+
- Code complexity limits (max_complexity=10)
|
|
22
|
+
- File size limits (max_lines=500)
|
|
23
|
+
- Naming conventions (snake_case, camelCase)
|
|
24
|
+
- Security patterns (no_secrets, https_only)
|
|
25
|
+
- Architecture boundaries (no_direct_db_access)
|
|
26
|
+
|
|
27
|
+
## 2. Enforce Constraints
|
|
28
|
+
|
|
29
|
+
If enforcing constraints (--enforce):
|
|
30
|
+
!python -m flake8 --max-complexity=10 . 2>/dev/null || echo "No Python linter available"
|
|
31
|
+
!eslint --max-complexity 10 . 2>/dev/null || echo "No JavaScript linter available"
|
|
32
|
+
!grep -r "password\|secret\|key" . --exclude-dir=.git | head -5 || echo "No hardcoded secrets found"
|
|
33
|
+
|
|
34
|
+
Check for:
|
|
35
|
+
- Code complexity violations
|
|
36
|
+
- File size violations
|
|
37
|
+
- Naming convention violations
|
|
38
|
+
- Security violations
|
|
39
|
+
- Architecture violations
|
|
40
|
+
|
|
41
|
+
## 3. Validate Compliance
|
|
42
|
+
|
|
43
|
+
If validating constraints (--validate):
|
|
44
|
+
!find . -name "*.py" -exec wc -l {} \; | awk '$1 > 500 {print $2 ": " $1 " lines (exceeds 500)"}'
|
|
45
|
+
!find . -name "*.js" -exec wc -l {} \; | awk '$1 > 300 {print $2 ": " $1 " lines (exceeds 300)"}'
|
|
46
|
+
|
|
47
|
+
Validate:
|
|
48
|
+
- Code meets complexity limits
|
|
49
|
+
- Files are within size limits
|
|
50
|
+
- Naming follows conventions
|
|
51
|
+
- No security violations
|
|
52
|
+
- Architecture boundaries respected
|
|
53
|
+
|
|
54
|
+
## 4. List Current Constraints
|
|
55
|
+
|
|
56
|
+
If listing constraints (--list):
|
|
57
|
+
@.constraints.yml 2>/dev/null || echo "No constraints file found"
|
|
58
|
+
!echo "Active constraints:"
|
|
59
|
+
!echo "- Max complexity: 10"
|
|
60
|
+
!echo "- Max file lines: 500"
|
|
61
|
+
!echo "- Naming: snake_case (Python), camelCase (JavaScript)"
|
|
62
|
+
!echo "- Security: No hardcoded secrets"
|
|
63
|
+
|
|
64
|
+
## 5. Generate Compliance Report
|
|
65
|
+
|
|
66
|
+
If generating report (--report):
|
|
67
|
+
!date
|
|
68
|
+
!echo "=== Constraint Compliance Report ==="
|
|
69
|
+
!echo "Project: $(basename $(pwd))"
|
|
70
|
+
|
|
71
|
+
Run constraint checks:
|
|
72
|
+
!python -c "import ast; print('Python syntax check: OK')" 2>/dev/null || echo "Python syntax issues found"
|
|
73
|
+
!node -c "console.log('JavaScript syntax check: OK')" 2>/dev/null || echo "JavaScript syntax issues found"
|
|
74
|
+
|
|
75
|
+
Generate summary:
|
|
76
|
+
- Total files checked
|
|
77
|
+
- Violations found
|
|
78
|
+
- Compliance percentage
|
|
79
|
+
- Recommendations for fixes
|
|
80
|
+
|
|
81
|
+
Think step by step about constraint violations and provide:
|
|
82
|
+
- Current compliance status
|
|
83
|
+
- Specific violations found
|
|
84
|
+
- Prioritized fix recommendations
|
|
85
|
+
- Prevention strategies
|
|
86
|
+
- Integration suggestions
|
|
87
|
+
|
|
88
|
+
Report overall constraint health and suggest improvements for maintaining code quality and compliance.
|
|
89
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Comprehensive dual coverage analysis for code and specifications
|
|
3
|
+
tags: [coverage, testing, specifications, quality, metrics]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Perform dual coverage analysis based on the arguments provided in $ARGUMENTS.
|
|
7
|
+
|
|
8
|
+
First, examine the project structure for test files and coverage tools:
|
|
9
|
+
!find . -name "*test*" -o -name "*spec*" | grep -E "\.(py|js|ts)$" | head -10
|
|
10
|
+
!ls -la | grep -E "(pytest|jest|coverage|nyc)"
|
|
11
|
+
!which pytest 2>/dev/null || which npm 2>/dev/null || echo "No test runners found"
|
|
12
|
+
|
|
13
|
+
Based on $ARGUMENTS, perform the appropriate coverage analysis:
|
|
14
|
+
|
|
15
|
+
## 1. HTML Coverage Report Generation
|
|
16
|
+
|
|
17
|
+
If generating HTML report (--html):
|
|
18
|
+
!python -m pytest --cov=. --cov-report=html 2>/dev/null || npm test -- --coverage 2>/dev/null || echo "No coverage tools configured"
|
|
19
|
+
!ls htmlcov/ 2>/dev/null && echo "HTML report generated in htmlcov/" || echo "No HTML coverage report found"
|
|
20
|
+
|
|
21
|
+
## 2. Missing Coverage Analysis
|
|
22
|
+
|
|
23
|
+
If checking missing coverage (--missing):
|
|
24
|
+
!python -m pytest --cov=. --cov-report=term-missing 2>/dev/null || echo "Python coverage not available"
|
|
25
|
+
!npm test -- --coverage --verbose 2>/dev/null || echo "JavaScript coverage not available"
|
|
26
|
+
|
|
27
|
+
Show uncovered lines and specifications that need attention.
|
|
28
|
+
|
|
29
|
+
## 3. Specification Coverage Analysis
|
|
30
|
+
|
|
31
|
+
If checking specific specification (--spec):
|
|
32
|
+
@specs/ 2>/dev/null || echo "No specs directory found"
|
|
33
|
+
!find . -name "*test*" -exec grep -l "$spec_id" {} \; 2>/dev/null
|
|
34
|
+
|
|
35
|
+
Analyze:
|
|
36
|
+
- Tests linked to the specification
|
|
37
|
+
- Code coverage for specification implementation
|
|
38
|
+
- Traceability from spec to test to code
|
|
39
|
+
|
|
40
|
+
## 4. Dual Coverage Metrics
|
|
41
|
+
|
|
42
|
+
If showing dual coverage (--dual):
|
|
43
|
+
!python -m pytest --cov=. --cov-report=term 2>/dev/null | grep "TOTAL" || echo "Code coverage not available"
|
|
44
|
+
!find specs/ -name "*.md" 2>/dev/null | wc -l | xargs echo "Total specifications:"
|
|
45
|
+
!find . -name "*test*" 2>/dev/null | wc -l | xargs echo "Total test files:"
|
|
46
|
+
|
|
47
|
+
Calculate:
|
|
48
|
+
- Code coverage percentage
|
|
49
|
+
- Specification coverage percentage
|
|
50
|
+
- Traceability coverage percentage
|
|
51
|
+
- Combined dual coverage score
|
|
52
|
+
|
|
53
|
+
## 5. Authority Level Coverage
|
|
54
|
+
|
|
55
|
+
If checking by authority (--authority):
|
|
56
|
+
!grep -r "authority=$authority_level" specs/ 2>/dev/null || echo "No authority specifications found"
|
|
57
|
+
|
|
58
|
+
Break down coverage by:
|
|
59
|
+
- System level specifications
|
|
60
|
+
- Platform level specifications
|
|
61
|
+
- Developer level specifications
|
|
62
|
+
|
|
63
|
+
## 6. Coverage Gaps Analysis
|
|
64
|
+
|
|
65
|
+
If identifying gaps (--gaps):
|
|
66
|
+
!find specs/ -name "*.md" -exec basename {} \; 2>/dev/null | sed 's/\.md$//' > /tmp/specs.txt
|
|
67
|
+
!find . -name "*test*" -exec grep -l "spec" {} \; 2>/dev/null | xargs grep -o "spec[0-9a-zA-Z]*" | sort -u > /tmp/tested_specs.txt
|
|
68
|
+
!comm -23 <(sort /tmp/specs.txt) <(sort /tmp/tested_specs.txt) 2>/dev/null || echo "Gap analysis not available"
|
|
69
|
+
|
|
70
|
+
Identify:
|
|
71
|
+
- Specifications without tests
|
|
72
|
+
- Code without specification coverage
|
|
73
|
+
- Missing traceability links
|
|
74
|
+
|
|
75
|
+
## 7. Comprehensive Metrics Dashboard
|
|
76
|
+
|
|
77
|
+
If generating metrics (--metrics):
|
|
78
|
+
!uptime
|
|
79
|
+
!date
|
|
80
|
+
|
|
81
|
+
Think step by step about coverage analysis and provide:
|
|
82
|
+
- Current code coverage percentage
|
|
83
|
+
- Specification coverage percentage
|
|
84
|
+
- Traceability coverage percentage
|
|
85
|
+
- Gap analysis summary
|
|
86
|
+
- Recommendations for improvement
|
|
87
|
+
- Coverage trends and targets
|
|
88
|
+
|
|
89
|
+
Generate a comprehensive coverage report with actionable insights and recommendations.
|
|
90
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Comprehensive database management, migrations, and performance operations
|
|
3
|
+
tags: [database, schema, migration, performance, backup]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Perform database operations based on the arguments provided in $ARGUMENTS.
|
|
7
|
+
|
|
8
|
+
First, examine the project for database configuration and tools:
|
|
9
|
+
!ls -la | grep -E "(database|db|migration|schema)"
|
|
10
|
+
!find . -name "*.sql" -o -name "*migration*" -o -name "*schema*" | head -10
|
|
11
|
+
!which psql 2>/dev/null || which mysql 2>/dev/null || which sqlite3 2>/dev/null || echo "No database clients found"
|
|
12
|
+
|
|
13
|
+
Based on $ARGUMENTS, perform the appropriate database operation:
|
|
14
|
+
|
|
15
|
+
## 1. Schema Management
|
|
16
|
+
|
|
17
|
+
If managing schema (--schema):
|
|
18
|
+
!find . -name "schema.sql" -o -name "*.schema" | head -5
|
|
19
|
+
!ls models/ 2>/dev/null || ls app/models/ 2>/dev/null || echo "No models directory found"
|
|
20
|
+
|
|
21
|
+
For schema operations:
|
|
22
|
+
- Check existing schema files
|
|
23
|
+
- Validate schema syntax
|
|
24
|
+
- Generate schema documentation
|
|
25
|
+
- Compare schema versions
|
|
26
|
+
|
|
27
|
+
## 2. Migration Operations
|
|
28
|
+
|
|
29
|
+
If handling migrations (--migrate):
|
|
30
|
+
!find . -name "*migration*" -o -path "*/migrations/*" | head -10
|
|
31
|
+
!python manage.py showmigrations 2>/dev/null || rails db:migrate:status 2>/dev/null || echo "No migration framework detected"
|
|
32
|
+
|
|
33
|
+
Migration tasks:
|
|
34
|
+
- Check migration status
|
|
35
|
+
- Run pending migrations
|
|
36
|
+
- Create new migration files
|
|
37
|
+
- Rollback migrations if needed
|
|
38
|
+
|
|
39
|
+
## 3. Data Seeding
|
|
40
|
+
|
|
41
|
+
If seeding data (--seed):
|
|
42
|
+
!find . -name "*seed*" -o -name "*fixture*" | head -5
|
|
43
|
+
!python manage.py loaddata 2>/dev/null || rails db:seed 2>/dev/null || echo "No seeding framework detected"
|
|
44
|
+
|
|
45
|
+
Seeding operations:
|
|
46
|
+
- Load test fixtures
|
|
47
|
+
- Populate sample data
|
|
48
|
+
- Environment-specific seeding
|
|
49
|
+
- Data validation after seeding
|
|
50
|
+
|
|
51
|
+
## 4. Performance Analysis
|
|
52
|
+
|
|
53
|
+
If analyzing performance (--performance):
|
|
54
|
+
!ps aux | grep -E "(postgres|mysql|sqlite)" | head -3
|
|
55
|
+
!top -l 1 | grep -E "(CPU|Memory)" 2>/dev/null || echo "System stats not available"
|
|
56
|
+
|
|
57
|
+
Performance checks:
|
|
58
|
+
- Database connection status
|
|
59
|
+
- Query performance analysis
|
|
60
|
+
- Index optimization suggestions
|
|
61
|
+
- Resource usage monitoring
|
|
62
|
+
|
|
63
|
+
## 5. Backup Operations
|
|
64
|
+
|
|
65
|
+
If performing backup (--backup):
|
|
66
|
+
!ls -la *.sql *.dump 2>/dev/null || echo "No backup files found"
|
|
67
|
+
!which pg_dump 2>/dev/null || which mysqldump 2>/dev/null || echo "No backup tools found"
|
|
68
|
+
|
|
69
|
+
Backup tasks:
|
|
70
|
+
- Create database backups
|
|
71
|
+
- Verify backup integrity
|
|
72
|
+
- Schedule automated backups
|
|
73
|
+
- Test restore procedures
|
|
74
|
+
|
|
75
|
+
## 6. Database Testing
|
|
76
|
+
|
|
77
|
+
If testing database (--test):
|
|
78
|
+
!python -m pytest tests/test_*db* 2>/dev/null || npm test 2>/dev/null || echo "No database tests found"
|
|
79
|
+
!find . -name "*test*" | grep -i db | head -5
|
|
80
|
+
|
|
81
|
+
Testing operations:
|
|
82
|
+
- Run database unit tests
|
|
83
|
+
- Test migration scripts
|
|
84
|
+
- Validate data integrity
|
|
85
|
+
- Check constraint violations
|
|
86
|
+
|
|
87
|
+
## 7. Connection and Status
|
|
88
|
+
|
|
89
|
+
Check database connectivity:
|
|
90
|
+
!python -c "import sqlite3; print('SQLite available')" 2>/dev/null || echo "SQLite not available"
|
|
91
|
+
!python -c "import psycopg2; print('PostgreSQL client available')" 2>/dev/null || echo "PostgreSQL client not available"
|
|
92
|
+
!python -c "import pymongo; print('MongoDB client available')" 2>/dev/null || echo "MongoDB client not available"
|
|
93
|
+
|
|
94
|
+
Think step by step about database operations and provide:
|
|
95
|
+
- Current database status
|
|
96
|
+
- Available operations for detected database type
|
|
97
|
+
- Recommendations for database optimization
|
|
98
|
+
- Best practices for data management
|
|
99
|
+
- Security considerations
|
|
100
|
+
|
|
101
|
+
Generate database management report with actionable recommendations.
|
|
102
|
+
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Apply design patterns and architectural principles to improve code quality
|
|
3
|
+
tags: [design-patterns, architecture, solid, refactoring, best-practices]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Analyze code structure and apply design patterns based on the arguments provided in $ARGUMENTS.
|
|
7
|
+
|
|
8
|
+
First, examine the project structure and identify current patterns:
|
|
9
|
+
!find . -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" | head -15
|
|
10
|
+
!ls -la src/ app/ lib/ 2>/dev/null || echo "No standard source directories found"
|
|
11
|
+
|
|
12
|
+
Based on $ARGUMENTS, perform the appropriate design analysis:
|
|
13
|
+
|
|
14
|
+
## 1. Pattern Analysis and Suggestions
|
|
15
|
+
|
|
16
|
+
If analyzing patterns (--patterns, --analyze):
|
|
17
|
+
!grep -r "class" . --include="*.py" --include="*.js" --include="*.ts" | head -10
|
|
18
|
+
!grep -r "interface\|abstract" . --include="*.py" --include="*.js" --include="*.ts" | head -5
|
|
19
|
+
|
|
20
|
+
Analyze current code for:
|
|
21
|
+
- Existing design patterns
|
|
22
|
+
- Anti-patterns and code smells
|
|
23
|
+
- Opportunities for pattern application
|
|
24
|
+
- Architectural structure
|
|
25
|
+
|
|
26
|
+
## 2. SOLID Principles Assessment
|
|
27
|
+
|
|
28
|
+
If checking SOLID principles (--solid, --principles):
|
|
29
|
+
!find . -name "*.py" -exec grep -l "class" {} \; | head -5
|
|
30
|
+
!python -c "import ast; print('Analyzing class structures...')" 2>/dev/null || echo "Python AST analysis not available"
|
|
31
|
+
|
|
32
|
+
Check for:
|
|
33
|
+
- Single Responsibility Principle violations
|
|
34
|
+
- Open/Closed Principle compliance
|
|
35
|
+
- Liskov Substitution Principle adherence
|
|
36
|
+
- Interface Segregation implementation
|
|
37
|
+
- Dependency Inversion usage
|
|
38
|
+
|
|
39
|
+
## 3. Code Quality Analysis
|
|
40
|
+
|
|
41
|
+
If checking DRY violations (--dry):
|
|
42
|
+
!grep -r "def\|function" . --include="*.py" --include="*.js" | cut -d: -f2 | sort | uniq -c | sort -nr | head -10
|
|
43
|
+
!find . -name "*.py" -exec grep -l "copy\|duplicate" {} \; 2>/dev/null
|
|
44
|
+
|
|
45
|
+
Identify:
|
|
46
|
+
- Duplicated code blocks
|
|
47
|
+
- Similar functions/methods
|
|
48
|
+
- Copy-paste patterns
|
|
49
|
+
- Refactoring opportunities
|
|
50
|
+
|
|
51
|
+
## 4. Coupling and Cohesion Analysis
|
|
52
|
+
|
|
53
|
+
If analyzing coupling (--coupling):
|
|
54
|
+
!find . -name "*.py" -exec grep -c "import" {} \; | sort -nr | head -10
|
|
55
|
+
!grep -r "from.*import" . --include="*.py" | wc -l
|
|
56
|
+
|
|
57
|
+
Evaluate:
|
|
58
|
+
- Module dependencies
|
|
59
|
+
- Import complexity
|
|
60
|
+
- Circular dependencies
|
|
61
|
+
- Cohesion within modules
|
|
62
|
+
|
|
63
|
+
## 5. Refactoring Suggestions
|
|
64
|
+
|
|
65
|
+
If providing refactoring guidance (--refactor):
|
|
66
|
+
!find . -name "*.py" -exec wc -l {} \; | awk '$1 > 100 {print $2 ": " $1 " lines (consider refactoring)"}'
|
|
67
|
+
!grep -r "def" . --include="*.py" | wc -l | xargs echo "Total functions:"
|
|
68
|
+
|
|
69
|
+
Suggest:
|
|
70
|
+
- Extract method opportunities
|
|
71
|
+
- Class decomposition
|
|
72
|
+
- Interface extraction
|
|
73
|
+
- Dependency injection improvements
|
|
74
|
+
|
|
75
|
+
## 6. Specific Pattern Implementation
|
|
76
|
+
|
|
77
|
+
If implementing specific patterns (--factory, --observer, --strategy):
|
|
78
|
+
@src/ 2>/dev/null || @app/ 2>/dev/null || echo "No source directory to analyze"
|
|
79
|
+
|
|
80
|
+
Pattern suggestions based on context:
|
|
81
|
+
- Factory patterns for object creation
|
|
82
|
+
- Observer patterns for event handling
|
|
83
|
+
- Strategy patterns for algorithm selection
|
|
84
|
+
- Repository patterns for data access
|
|
85
|
+
- Decorator patterns for feature extension
|
|
86
|
+
|
|
87
|
+
## 7. Architecture Pattern Assessment
|
|
88
|
+
|
|
89
|
+
If checking architecture patterns (--mvc, --repository):
|
|
90
|
+
!find . -name "*model*" -o -name "*view*" -o -name "*controller*" | head -10
|
|
91
|
+
!find . -name "*repository*" -o -name "*service*" -o -name "*dao*" | head -5
|
|
92
|
+
|
|
93
|
+
Assess current architecture:
|
|
94
|
+
- MVC pattern implementation
|
|
95
|
+
- Layer separation
|
|
96
|
+
- Service layer design
|
|
97
|
+
- Data access patterns
|
|
98
|
+
|
|
99
|
+
## 8. Best Practices Review
|
|
100
|
+
|
|
101
|
+
If reviewing best practices (--best-practices, --clean-code):
|
|
102
|
+
!python -m flake8 . 2>/dev/null | head -10 || echo "No Python linting available"
|
|
103
|
+
!eslint . 2>/dev/null | head -10 || echo "No JavaScript linting available"
|
|
104
|
+
|
|
105
|
+
Review:
|
|
106
|
+
- Naming conventions
|
|
107
|
+
- Function/method length
|
|
108
|
+
- Class responsibilities
|
|
109
|
+
- Code complexity
|
|
110
|
+
- Documentation quality
|
|
111
|
+
|
|
112
|
+
Think step by step about design improvements and provide:
|
|
113
|
+
- Current design pattern usage
|
|
114
|
+
- Anti-pattern identification
|
|
115
|
+
- SOLID principle compliance
|
|
116
|
+
- Refactoring recommendations
|
|
117
|
+
- Architecture improvement suggestions
|
|
118
|
+
- Implementation guidance for suggested patterns
|
|
119
|
+
|
|
120
|
+
Generate a comprehensive design analysis with actionable recommendations for code quality improvement.
|
|
121
|
+
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Set up Anthropic's official devcontainer for running Claude Code with --dangerously-skip-permissions safely
|
|
3
|
+
tags: [devcontainer, security, isolation, docker, autonomous, permissions]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Set up a secure devcontainer environment based on Anthropic's official reference implementation.
|
|
7
|
+
|
|
8
|
+
Reference: https://docs.anthropic.com/en/docs/claude-code/devcontainer
|
|
9
|
+
|
|
10
|
+
First, check the current environment and any existing configuration:
|
|
11
|
+
!ls -la .devcontainer/ 2>/dev/null || echo "No existing devcontainer configuration"
|
|
12
|
+
!which docker 2>/dev/null && docker --version || echo "Docker not installed"
|
|
13
|
+
!which devcontainer 2>/dev/null && devcontainer --version || echo "devcontainer CLI not installed"
|
|
14
|
+
!echo "ANTHROPIC_API_KEY is $([ -n \"$ANTHROPIC_API_KEY\" ] && echo 'set' || echo 'NOT SET')"
|
|
15
|
+
|
|
16
|
+
Based on $ARGUMENTS, perform the appropriate devcontainer operation:
|
|
17
|
+
|
|
18
|
+
## 1. Create Devcontainer (default, --create, --setup)
|
|
19
|
+
|
|
20
|
+
If creating a new devcontainer configuration or no arguments provided:
|
|
21
|
+
|
|
22
|
+
### Recommended Security Configuration
|
|
23
|
+
|
|
24
|
+
Create `.devcontainer/devcontainer.json`:
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"name": "Claude Code Sandbox",
|
|
28
|
+
"build": {
|
|
29
|
+
"dockerfile": "Dockerfile"
|
|
30
|
+
},
|
|
31
|
+
"features": {
|
|
32
|
+
"ghcr.io/devcontainers/features/node:1": {},
|
|
33
|
+
"ghcr.io/devcontainers/features/python:1": {},
|
|
34
|
+
"ghcr.io/devcontainers/features/git:1": {},
|
|
35
|
+
"ghcr.io/devcontainers/features/github-cli:1": {},
|
|
36
|
+
"ghcr.io/devcontainers/features/aws-cli:1": {},
|
|
37
|
+
"ghcr.io/devcontainers/features/docker-in-docker:1": {}
|
|
38
|
+
},
|
|
39
|
+
"postCreateCommand": "npm install -g @anthropic-ai/claude-code && pip install --user boto3 requests",
|
|
40
|
+
"remoteEnv": {
|
|
41
|
+
"ANTHROPIC_API_KEY": "${localEnv:ANTHROPIC_API_KEY}",
|
|
42
|
+
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}",
|
|
43
|
+
"AWS_ACCESS_KEY_ID": "${localEnv:AWS_ACCESS_KEY_ID}",
|
|
44
|
+
"AWS_SECRET_ACCESS_KEY": "${localEnv:AWS_SECRET_ACCESS_KEY}",
|
|
45
|
+
"AWS_DEFAULT_REGION": "${localEnv:AWS_DEFAULT_REGION}"
|
|
46
|
+
},
|
|
47
|
+
"runArgs": [
|
|
48
|
+
"--cap-drop=ALL",
|
|
49
|
+
"--security-opt=no-new-privileges"
|
|
50
|
+
],
|
|
51
|
+
"mounts": [],
|
|
52
|
+
"customizations": {
|
|
53
|
+
"vscode": {
|
|
54
|
+
"extensions": [
|
|
55
|
+
"anthropic.claude-code"
|
|
56
|
+
],
|
|
57
|
+
"settings": {
|
|
58
|
+
"terminal.integrated.defaultProfile.linux": "bash"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Create `.devcontainer/Dockerfile`:
|
|
66
|
+
```dockerfile
|
|
67
|
+
# Anthropic's recommended devcontainer for Claude Code
|
|
68
|
+
# Reference: https://docs.anthropic.com/en/docs/claude-code/devcontainer
|
|
69
|
+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
|
|
70
|
+
|
|
71
|
+
# Security labels
|
|
72
|
+
LABEL org.opencontainers.image.title="Claude Code Sandbox"
|
|
73
|
+
LABEL org.opencontainers.image.description="Secure container for running Claude Code with --dangerously-skip-permissions"
|
|
74
|
+
LABEL org.opencontainers.image.vendor="Generated by setup-devcontainer.sh"
|
|
75
|
+
|
|
76
|
+
# Install essential security tools
|
|
77
|
+
RUN apt-get update && apt-get install -y \
|
|
78
|
+
curl \
|
|
79
|
+
ca-certificates \
|
|
80
|
+
gnupg \
|
|
81
|
+
lsb-release \
|
|
82
|
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
83
|
+
|
|
84
|
+
# Network firewall - only allow specific domains
|
|
85
|
+
RUN apt-get update && apt-get install -y iptables dnsutils && \
|
|
86
|
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
87
|
+
|
|
88
|
+
# Create firewall setup script (runs at container start)
|
|
89
|
+
# Rules are processed in order - first match wins
|
|
90
|
+
RUN echo '#!/bin/bash' > /usr/local/bin/setup-firewall.sh && \
|
|
91
|
+
echo 'set -e' >> /usr/local/bin/setup-firewall.sh && \
|
|
92
|
+
echo 'iptables -A OUTPUT -o lo -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
93
|
+
echo 'iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
94
|
+
echo 'iptables -A OUTPUT -p udp --dport 53 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
95
|
+
echo 'iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
96
|
+
echo 'iptables -A OUTPUT -p tcp -d api.anthropic.com --dport 443 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
97
|
+
echo 'iptables -A OUTPUT -p tcp -d github.com --dport 443 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
98
|
+
echo 'iptables -A OUTPUT -p tcp -d registry.npmjs.org --dport 443 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
99
|
+
echo 'iptables -A OUTPUT -p tcp -d pypi.org --dport 443 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
100
|
+
echo 'iptables -A OUTPUT -p tcp -d files.pythonhosted.org --dport 443 -j ACCEPT' >> /usr/local/bin/setup-firewall.sh && \
|
|
101
|
+
echo 'iptables -A OUTPUT -p tcp --dport 443 -j DROP' >> /usr/local/bin/setup-firewall.sh && \
|
|
102
|
+
echo 'iptables -A OUTPUT -p tcp --dport 80 -j DROP' >> /usr/local/bin/setup-firewall.sh && \
|
|
103
|
+
chmod +x /usr/local/bin/setup-firewall.sh
|
|
104
|
+
|
|
105
|
+
# Create non-root user workspace
|
|
106
|
+
RUN mkdir -p /workspace && chown vscode:vscode /workspace
|
|
107
|
+
WORKDIR /workspace
|
|
108
|
+
|
|
109
|
+
# Default to non-root user
|
|
110
|
+
USER vscode
|
|
111
|
+
|
|
112
|
+
# Health check
|
|
113
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
114
|
+
CMD curl -sf https://api.anthropic.com/health || exit 1
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Key security features:
|
|
118
|
+
- **`--cap-drop=ALL`**: Drops all Linux capabilities
|
|
119
|
+
- **`--security-opt=no-new-privileges`**: Prevents privilege escalation
|
|
120
|
+
- **Network firewall**: Only allows traffic to allowlisted domains
|
|
121
|
+
- **No mounts**: Isolates from host filesystem
|
|
122
|
+
|
|
123
|
+
## 2. Using the Setup Script (--script)
|
|
124
|
+
|
|
125
|
+
If the user wants to use the automated setup script:
|
|
126
|
+
!ls -la setup-devcontainer.sh 2>/dev/null || echo "Script not in current directory"
|
|
127
|
+
|
|
128
|
+
Run the setup script:
|
|
129
|
+
```bash
|
|
130
|
+
# Full setup with recommended security
|
|
131
|
+
./setup-devcontainer.sh
|
|
132
|
+
|
|
133
|
+
# Minimal setup (Node.js and Git only)
|
|
134
|
+
./setup-devcontainer.sh --minimal
|
|
135
|
+
|
|
136
|
+
# Skip network firewall restrictions
|
|
137
|
+
./setup-devcontainer.sh --no-network-firewall
|
|
138
|
+
|
|
139
|
+
# Preview what would be created
|
|
140
|
+
./setup-devcontainer.sh --dry-run
|
|
141
|
+
|
|
142
|
+
# Strict mode for CI (fails if prerequisites missing)
|
|
143
|
+
./setup-devcontainer.sh --strict
|
|
144
|
+
|
|
145
|
+
# Add custom domains for enterprise private registries
|
|
146
|
+
./setup-devcontainer.sh --allow-domain internal.registry.com
|
|
147
|
+
|
|
148
|
+
# Or use environment variable for extra domains
|
|
149
|
+
DEVCONTAINER_EXTRA_DOMAINS="internal.registry.com,npm.mycompany.com" ./setup-devcontainer.sh
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## 3. Start Container (--start, --up)
|
|
153
|
+
|
|
154
|
+
If starting the devcontainer:
|
|
155
|
+
!docker ps -a | grep -i devcontainer | head -3 || echo "No devcontainer running"
|
|
156
|
+
|
|
157
|
+
Start commands:
|
|
158
|
+
```bash
|
|
159
|
+
# Using VS Code
|
|
160
|
+
# Cmd/Ctrl+Shift+P → "Dev Containers: Reopen in Container"
|
|
161
|
+
|
|
162
|
+
# Using devcontainer CLI
|
|
163
|
+
devcontainer up --workspace-folder .
|
|
164
|
+
devcontainer exec --workspace-folder . claude --dangerously-skip-permissions
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 4. Security Validation (--validate, --check)
|
|
168
|
+
|
|
169
|
+
If validating the devcontainer security:
|
|
170
|
+
!cat .devcontainer/devcontainer.json 2>/dev/null | grep -E "(cap-drop|no-new-privileges|mounts)" || echo "Security settings not found"
|
|
171
|
+
!cat .devcontainer/Dockerfile 2>/dev/null | grep -E "(iptables|DROP)" || echo "Firewall rules not found"
|
|
172
|
+
|
|
173
|
+
Verify:
|
|
174
|
+
- [ ] `--cap-drop=ALL` is present in runArgs
|
|
175
|
+
- [ ] `--security-opt=no-new-privileges` is present
|
|
176
|
+
- [ ] Network firewall rules block unauthorized outbound traffic
|
|
177
|
+
- [ ] No host filesystem mounts configured
|
|
178
|
+
|
|
179
|
+
## 5. Cleanup (--cleanup, --remove)
|
|
180
|
+
|
|
181
|
+
If cleaning up devcontainer:
|
|
182
|
+
```bash
|
|
183
|
+
# Stop and remove container
|
|
184
|
+
devcontainer down --workspace-folder .
|
|
185
|
+
|
|
186
|
+
# Remove configuration (optional)
|
|
187
|
+
rm -rf .devcontainer/
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Comparison: /sandbox vs Devcontainer
|
|
191
|
+
|
|
192
|
+
| Aspect | Claude's `/sandbox` | Devcontainer |
|
|
193
|
+
|--------|---------------------|--------------|
|
|
194
|
+
| **Purpose** | Run code snippets safely | Run Claude itself isolated |
|
|
195
|
+
| **Scope** | Ephemeral execution | Persistent dev environment |
|
|
196
|
+
| **What's isolated** | Your code | The entire Claude session |
|
|
197
|
+
| **Use case** | "Test this script" | "Let Claude work autonomously" |
|
|
198
|
+
| **Flag enabled** | N/A | `--dangerously-skip-permissions` |
|
|
199
|
+
|
|
200
|
+
## Security Considerations
|
|
201
|
+
|
|
202
|
+
**Safe for:**
|
|
203
|
+
- Your own trusted projects
|
|
204
|
+
- Development and testing workflows
|
|
205
|
+
- CI/CD automation with Claude
|
|
206
|
+
|
|
207
|
+
**Avoid for:**
|
|
208
|
+
- Untrusted repositories (prompt injection risk)
|
|
209
|
+
- Projects with sensitive credentials you haven't reviewed
|
|
210
|
+
- Production systems
|
|
211
|
+
|
|
212
|
+
**Remember:** Even with isolation, credentials inside the container are accessible to Claude. Only pass credentials you're comfortable with Claude having access to.
|
|
213
|
+
|
|
214
|
+
## Quick Start
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# 1. Set API key
|
|
218
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
219
|
+
|
|
220
|
+
# 2. Run setup script (or create files manually)
|
|
221
|
+
./setup-devcontainer.sh
|
|
222
|
+
|
|
223
|
+
# 3. Open in VS Code and reopen in container
|
|
224
|
+
code . && # Cmd+Shift+P → "Dev Containers: Reopen in Container"
|
|
225
|
+
|
|
226
|
+
# 4. Run Claude with full autonomy
|
|
227
|
+
claude --dangerously-skip-permissions
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Think step by step about the user's devcontainer needs and provide:
|
|
231
|
+
|
|
232
|
+
1. **Environment Assessment**: Current setup, Docker availability, existing configuration
|
|
233
|
+
2. **Security Recommendation**: Appropriate isolation level based on use case
|
|
234
|
+
3. **Implementation**: Create or modify devcontainer configuration
|
|
235
|
+
4. **Validation**: Verify security settings are correctly applied
|
|
236
|
+
5. **Usage Instructions**: How to start and use the devcontainer
|
|
237
|
+
|
|
238
|
+
If no specific operation is provided, assess the current environment and help create a secure devcontainer configuration using Anthropic's recommended approach.
|