chaos_to_the_rescue 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.
- checksums.yaml +7 -0
- data/.claude/CLAUDE.md +3 -0
- data/.claude/memory.sqlite3 +0 -0
- data/.claude/rules/claude_memory.generated.md +8 -0
- data/.claude/settings.local.json +9 -0
- data/.devcontainer/.env.example +12 -0
- data/.devcontainer/Dockerfile.standalone +30 -0
- data/.devcontainer/README.md +207 -0
- data/.devcontainer/devcontainer.json +54 -0
- data/.devcontainer/docker-compose.yml +32 -0
- data/CHANGELOG.md +18 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/FEATURES.md +306 -0
- data/LICENSE.txt +21 -0
- data/README.md +502 -0
- data/Rakefile +10 -0
- data/examples/guidance_and_verification.rb +226 -0
- data/lib/chaos_to_the_rescue/chaos_rescue.rb +336 -0
- data/lib/chaos_to_the_rescue/configuration.rb +157 -0
- data/lib/chaos_to_the_rescue/llm_client.rb +182 -0
- data/lib/chaos_to_the_rescue/logger.rb +82 -0
- data/lib/chaos_to_the_rescue/railtie.rb +24 -0
- data/lib/chaos_to_the_rescue/redactor.rb +76 -0
- data/lib/chaos_to_the_rescue/rescue_from.rb +156 -0
- data/lib/chaos_to_the_rescue/verifier.rb +277 -0
- data/lib/chaos_to_the_rescue/version.rb +5 -0
- data/lib/chaos_to_the_rescue.rb +57 -0
- data/lib/generators/chaos_to_the_rescue/install_generator.rb +37 -0
- data/lib/generators/chaos_to_the_rescue/templates/chaos_to_the_rescue.rb +97 -0
- data/sig/chaos_to_the_rescue.rbs +4 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e01d621ff7f3e1d88f48888ff81201637e0a76b9a616e79f068293e265281442
|
|
4
|
+
data.tar.gz: c2dbfe23e355ca5463f560c4b0830931fac80d30e463e2ce334d8f947f737952
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 0c0311d177394bd8fdfb6e216210cd1c6d1fb1833dde4a3f7fc33e854337622ecf5ea1cd7a4b308714d6061d46a89f8b0ee6a0cc2937ceb036fc710a04e3a418
|
|
7
|
+
data.tar.gz: d90c83c44f7489c705c4f803cca22aa3c92576d42167bd4845604601fa90ab41fd8ba80d05543d3cbfc191d78f370b330a6d5f2eb12f706754296b4b79ca54e3
|
data/.claude/CLAUDE.md
ADDED
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Copy this file to .env and add your API keys
|
|
2
|
+
# DO NOT commit .env to git!
|
|
3
|
+
|
|
4
|
+
# OpenAI API Key (optional - for testing LLM features)
|
|
5
|
+
OPENAI_API_KEY=sk-proj-your-key-here
|
|
6
|
+
|
|
7
|
+
# Anthropic API Key (optional - for testing LLM features)
|
|
8
|
+
ANTHROPIC_API_KEY=sk-ant-your-key-here
|
|
9
|
+
|
|
10
|
+
# Or leave empty to test without API calls
|
|
11
|
+
# OPENAI_API_KEY=
|
|
12
|
+
# ANTHROPIC_API_KEY=
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Standalone Dockerfile for testing outside VS Code
|
|
2
|
+
FROM ruby:4.0
|
|
3
|
+
|
|
4
|
+
# Install any additional system dependencies
|
|
5
|
+
RUN apt-get update && apt-get install -y \
|
|
6
|
+
build-essential \
|
|
7
|
+
git \
|
|
8
|
+
vim \
|
|
9
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
10
|
+
|
|
11
|
+
# Set up working directory
|
|
12
|
+
WORKDIR /workspaces/chaos_to_the_rescue
|
|
13
|
+
|
|
14
|
+
# Copy Gemfile and install dependencies
|
|
15
|
+
COPY Gemfile Gemfile.lock chaos_to_the_rescue.gemspec ./
|
|
16
|
+
COPY lib/chaos_to_the_rescue/version.rb ./lib/chaos_to_the_rescue/
|
|
17
|
+
|
|
18
|
+
RUN bundle install
|
|
19
|
+
|
|
20
|
+
# Copy the rest of the application
|
|
21
|
+
COPY . .
|
|
22
|
+
|
|
23
|
+
# Set up non-root user for security
|
|
24
|
+
RUN useradd -m -u 1000 -s /bin/bash vscode && \
|
|
25
|
+
chown -R vscode:vscode /workspaces/chaos_to_the_rescue
|
|
26
|
+
|
|
27
|
+
USER vscode
|
|
28
|
+
|
|
29
|
+
# Default command: run the console
|
|
30
|
+
CMD ["bin/console"]
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# DevContainer for Safe Testing
|
|
2
|
+
|
|
3
|
+
This devcontainer provides an isolated, safe environment for testing `bin/console` and other potentially dangerous features of ChaosToTheRescue.
|
|
4
|
+
|
|
5
|
+
## Why Use This?
|
|
6
|
+
|
|
7
|
+
The `bin/console` script:
|
|
8
|
+
- Auto-configures with API keys from environment variables
|
|
9
|
+
- Enables `auto_define_methods` (executes generated code automatically)
|
|
10
|
+
- Enables `allow_everything!` (any method name allowed)
|
|
11
|
+
- Makes real API calls that cost money
|
|
12
|
+
|
|
13
|
+
**Devcontainer Benefits:**
|
|
14
|
+
- ✅ Isolated from your host system
|
|
15
|
+
- ✅ Can't accidentally harm your local files
|
|
16
|
+
- ✅ Easy to reset/rebuild
|
|
17
|
+
- ✅ Reproducible environment
|
|
18
|
+
- ✅ Can limit network access
|
|
19
|
+
- ✅ Safe for experimentation
|
|
20
|
+
- ✅ Uses Ruby 4.0 (matches latest Ruby)
|
|
21
|
+
|
|
22
|
+
## Setup Options
|
|
23
|
+
|
|
24
|
+
### Option 1: Using VS Code (Recommended)
|
|
25
|
+
|
|
26
|
+
1. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
|
|
27
|
+
2. Open this project in VS Code
|
|
28
|
+
3. Click the popup "Reopen in Container" or:
|
|
29
|
+
- Press `F1`
|
|
30
|
+
- Select "Dev Containers: Reopen in Container"
|
|
31
|
+
4. Wait for the container to build (first time only)
|
|
32
|
+
5. Run `bin/console` in the terminal
|
|
33
|
+
|
|
34
|
+
### Option 2: Using Docker Directly
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Build the container
|
|
38
|
+
docker build -t chaos-test -f .devcontainer/Dockerfile.standalone .
|
|
39
|
+
|
|
40
|
+
# Run with API keys (makes real API calls - costs money!)
|
|
41
|
+
docker run -it --rm \
|
|
42
|
+
-v $(pwd):/workspaces/chaos_to_the_rescue \
|
|
43
|
+
-w /workspaces/chaos_to_the_rescue \
|
|
44
|
+
-e OPENAI_API_KEY="sk-..." \
|
|
45
|
+
-e ANTHROPIC_API_KEY="sk-ant-..." \
|
|
46
|
+
chaos-test
|
|
47
|
+
|
|
48
|
+
# Or run WITHOUT network access (no API calls possible)
|
|
49
|
+
docker run -it --rm --network=none \
|
|
50
|
+
-v $(pwd):/workspaces/chaos_to_the_rescue \
|
|
51
|
+
-w /workspaces/chaos_to_the_rescue \
|
|
52
|
+
chaos-test
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Option 3: Docker Compose
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Copy the example env file
|
|
59
|
+
cp .devcontainer/.env.example .devcontainer/.env
|
|
60
|
+
|
|
61
|
+
# Edit .env and add your API keys (optional)
|
|
62
|
+
# vim .devcontainer/.env
|
|
63
|
+
|
|
64
|
+
# Start the container
|
|
65
|
+
docker compose -f .devcontainer/docker-compose.yml up -d
|
|
66
|
+
|
|
67
|
+
# Attach to it
|
|
68
|
+
docker compose -f .devcontainer/docker-compose.yml exec chaos bash
|
|
69
|
+
|
|
70
|
+
# Inside the container
|
|
71
|
+
bin/console
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API Key Management
|
|
75
|
+
|
|
76
|
+
### Recommended: Use `.env.devcontainer` (gitignored)
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Create the file
|
|
80
|
+
cat > .devcontainer/.env.devcontainer <<EOF
|
|
81
|
+
OPENAI_API_KEY=sk-proj-...
|
|
82
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
83
|
+
EOF
|
|
84
|
+
|
|
85
|
+
# The devcontainer will auto-load this file
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Alternative: Set in devcontainer.json
|
|
89
|
+
|
|
90
|
+
Edit `.devcontainer/devcontainer.json` and add to `containerEnv`:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
"containerEnv": {
|
|
94
|
+
"OPENAI_API_KEY": "sk-...",
|
|
95
|
+
"ANTHROPIC_API_KEY": "sk-ant-..."
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**⚠️ Warning:** Don't commit API keys to git!
|
|
100
|
+
|
|
101
|
+
## Network Isolation (Ultra-Safe Mode)
|
|
102
|
+
|
|
103
|
+
To prevent any network access (blocks API calls):
|
|
104
|
+
|
|
105
|
+
1. Edit `.devcontainer/devcontainer.json`
|
|
106
|
+
2. Uncomment the `runArgs` line:
|
|
107
|
+
```json
|
|
108
|
+
"runArgs": ["--network=none"],
|
|
109
|
+
```
|
|
110
|
+
3. Rebuild the container
|
|
111
|
+
|
|
112
|
+
**In this mode:**
|
|
113
|
+
- ✅ No API calls possible (no costs)
|
|
114
|
+
- ✅ Maximum isolation
|
|
115
|
+
- ❌ Can't test actual LLM features
|
|
116
|
+
- ✅ Can test configuration, patterns, allowlists, etc.
|
|
117
|
+
|
|
118
|
+
## Testing Without Real API Calls
|
|
119
|
+
|
|
120
|
+
You can test most functionality without making API calls:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# In bin/console
|
|
124
|
+
|
|
125
|
+
# Test configuration
|
|
126
|
+
ChaosToTheRescue.configuration.enabled
|
|
127
|
+
ChaosToTheRescue.configuration.model
|
|
128
|
+
|
|
129
|
+
# Test allowlist patterns
|
|
130
|
+
ChaosToTheRescue.configuration.allow_everything!
|
|
131
|
+
ChaosToTheRescue.configuration.allowed_method_name_patterns
|
|
132
|
+
|
|
133
|
+
# Test method name matching
|
|
134
|
+
config = ChaosToTheRescue.configuration
|
|
135
|
+
config.allowed_method_name_patterns = [/^calc_/]
|
|
136
|
+
config.method_name_allowed?(:calc_sum) # true
|
|
137
|
+
config.method_name_allowed?(:delete_everything) # false
|
|
138
|
+
|
|
139
|
+
# Disable auto-execution to see generated code
|
|
140
|
+
ChaosToTheRescue.configuration.auto_define_methods = false
|
|
141
|
+
ChaosToTheRescue.configuration.log_level = :debug
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Cleanup
|
|
145
|
+
|
|
146
|
+
### VS Code
|
|
147
|
+
- `F1` → "Dev Containers: Rebuild Container" (clean rebuild)
|
|
148
|
+
- `F1` → "Remote: Close Remote Connection" (exit)
|
|
149
|
+
|
|
150
|
+
### Docker
|
|
151
|
+
```bash
|
|
152
|
+
# Stop and remove
|
|
153
|
+
docker compose -f .devcontainer/docker-compose.yml down
|
|
154
|
+
|
|
155
|
+
# Remove volumes
|
|
156
|
+
docker compose -f .devcontainer/docker-compose.yml down -v
|
|
157
|
+
|
|
158
|
+
# Clean everything
|
|
159
|
+
docker system prune -a
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Troubleshooting
|
|
163
|
+
|
|
164
|
+
### Container won't start
|
|
165
|
+
```bash
|
|
166
|
+
# Check Docker is running
|
|
167
|
+
docker ps
|
|
168
|
+
|
|
169
|
+
# Rebuild from scratch
|
|
170
|
+
docker compose -f .devcontainer/docker-compose.yml build --no-cache
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Bundle install fails
|
|
174
|
+
```bash
|
|
175
|
+
# Inside container
|
|
176
|
+
bundle config set --local path 'vendor/bundle'
|
|
177
|
+
bundle install
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### API calls not working
|
|
181
|
+
- Check API keys are set: `echo $OPENAI_API_KEY`
|
|
182
|
+
- Check network isn't disabled: `ping google.com`
|
|
183
|
+
- Check `config.enabled = true` in console
|
|
184
|
+
|
|
185
|
+
### Want to test with a mock LLM
|
|
186
|
+
Consider adding a mock mode to the gem itself (see FEATURES.md)
|
|
187
|
+
|
|
188
|
+
## Security Notes
|
|
189
|
+
|
|
190
|
+
Even in a container:
|
|
191
|
+
- ✅ Generated code runs in isolation
|
|
192
|
+
- ✅ File system access limited to mounted workspace
|
|
193
|
+
- ✅ Network can be disabled
|
|
194
|
+
- ⚠️ Container shares host kernel (not a VM)
|
|
195
|
+
- ⚠️ Mounted files can be modified
|
|
196
|
+
- ⚠️ API keys are visible in container
|
|
197
|
+
|
|
198
|
+
**Best Practices:**
|
|
199
|
+
1. Use test API keys with limited budgets
|
|
200
|
+
2. Enable network isolation when possible
|
|
201
|
+
3. Review generated code before copying to host
|
|
202
|
+
4. Don't mount sensitive directories
|
|
203
|
+
5. Rebuild container regularly for fresh state
|
|
204
|
+
|
|
205
|
+
## Ruby Version
|
|
206
|
+
|
|
207
|
+
This devcontainer uses **Ruby 4.0** (official ruby:4.0 image) to match the latest Ruby version and ensure forward compatibility testing.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ChaosToTheRescue Safe Testing",
|
|
3
|
+
"image": "ruby:4.0",
|
|
4
|
+
|
|
5
|
+
"features": {
|
|
6
|
+
"ghcr.io/devcontainers/features/git:1": {},
|
|
7
|
+
"ghcr.io/devcontainers/features/common-utils:2": {
|
|
8
|
+
"installZsh": false,
|
|
9
|
+
"installOhMyZsh": false,
|
|
10
|
+
"username": "vscode",
|
|
11
|
+
"uid": "1000",
|
|
12
|
+
"gid": "1000"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"customizations": {
|
|
17
|
+
"vscode": {
|
|
18
|
+
"extensions": [
|
|
19
|
+
"rebornix.ruby",
|
|
20
|
+
"castwide.solargraph",
|
|
21
|
+
"kaiwood.endwise"
|
|
22
|
+
],
|
|
23
|
+
"settings": {
|
|
24
|
+
"terminal.integrated.defaultProfile.linux": "bash"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// Mount the repo but keep isolation
|
|
30
|
+
"mounts": [
|
|
31
|
+
"source=${localWorkspaceFolder},target=/workspaces/chaos_to_the_rescue,type=bind,consistency=cached"
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// Run as non-root user for safety
|
|
35
|
+
"remoteUser": "vscode",
|
|
36
|
+
|
|
37
|
+
"workspaceFolder": "/workspaces/chaos_to_the_rescue",
|
|
38
|
+
|
|
39
|
+
// Automatically run bundle install on container creation
|
|
40
|
+
"postCreateCommand": "bundle install",
|
|
41
|
+
|
|
42
|
+
// Set up environment variables for testing
|
|
43
|
+
// NOTE: Add API keys via .devcontainer/.env.devcontainer (gitignored)
|
|
44
|
+
"containerEnv": {
|
|
45
|
+
"CHAOS_TESTING": "true"
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
// Optional: Limit network access for paranoid isolation
|
|
49
|
+
// Uncomment to enable (this will block API calls)
|
|
50
|
+
// "runArgs": ["--network=none"],
|
|
51
|
+
|
|
52
|
+
// Keep container running for interactive console sessions
|
|
53
|
+
"postAttachCommand": "echo '✓ Ready for safe testing! Run: bin/console'"
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
version: '3.8'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
chaos:
|
|
5
|
+
image: ruby:4.0
|
|
6
|
+
container_name: chaos-to-the-rescue-testing
|
|
7
|
+
|
|
8
|
+
volumes:
|
|
9
|
+
- ..:/workspaces/chaos_to_the_rescue:cached
|
|
10
|
+
- bundle_cache:/usr/local/bundle
|
|
11
|
+
|
|
12
|
+
working_dir: /workspaces/chaos_to_the_rescue
|
|
13
|
+
|
|
14
|
+
# Load API keys from .env file (create from .env.example)
|
|
15
|
+
env_file:
|
|
16
|
+
- .env
|
|
17
|
+
|
|
18
|
+
environment:
|
|
19
|
+
- CHAOS_TESTING=true
|
|
20
|
+
- BUNDLE_PATH=/usr/local/bundle
|
|
21
|
+
|
|
22
|
+
# Keep container running
|
|
23
|
+
command: sleep infinity
|
|
24
|
+
|
|
25
|
+
# Uncomment to disable network (ultra-safe mode)
|
|
26
|
+
# network_mode: none
|
|
27
|
+
|
|
28
|
+
# Run as non-root user for added security
|
|
29
|
+
user: "1000:1000"
|
|
30
|
+
|
|
31
|
+
volumes:
|
|
32
|
+
bundle_cache:
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-01-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Safe-by-default LLM-powered method generation via `ChaosRescue` mixin
|
|
7
|
+
- Support for both instance and class method generation
|
|
8
|
+
- Rails exception rescue suggestions with `chaos_suggest_fix`
|
|
9
|
+
- Method guidance and verification system with `chaos_guidance` and `verify_chaos`
|
|
10
|
+
- Comprehensive security features (secret redaction, opt-in behavior, allowlist controls)
|
|
11
|
+
- Configurable allowlist patterns and explicit method allowlists
|
|
12
|
+
- Auto-fix capability for incorrect method implementations
|
|
13
|
+
- Devcontainer setup for safe testing in isolated environment
|
|
14
|
+
- Support for multiple LLM providers via RubyLLM integration
|
|
15
|
+
- Disabled by default with multiple safety layers
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Renamed `chaos_verify` to `verify_chaos` for better API consistency
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"chaos_to_the_rescue" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["v@codenamev.com"](mailto:"v@codenamev.com").
|