bugsage 0.2.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 (69) hide show
  1. checksums.yaml +7 -0
  2. data/ARCHITECTURE.md +442 -0
  3. data/CHANGELOG.md +28 -0
  4. data/CODE_OF_CONDUCT.md +10 -0
  5. data/CONTRIBUTING.md +301 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +344 -0
  8. data/ROADMAP.md +217 -0
  9. data/SECURITY.md +83 -0
  10. data/docs/AI.md +167 -0
  11. data/docs/Configuration.md +168 -0
  12. data/docs/GettingStarted.md +146 -0
  13. data/docs/RELEASE_CHECKLIST.md +346 -0
  14. data/docs/Troubleshooting.md +181 -0
  15. data/docs/images/BadRequest.png +0 -0
  16. data/docs/images/BadRequest2.png +0 -0
  17. data/docs/images/BugSage_Logo.png +0 -0
  18. data/docs/images/BugSage_Social_Preview.png +0 -0
  19. data/docs/images/NoMethodError.png +0 -0
  20. data/docs/images/NoMethodError2.png +0 -0
  21. data/docs/images/README.md +38 -0
  22. data/docs/releases/README.md +21 -0
  23. data/docs/releases/v0.2.0.md +40 -0
  24. data/exe/bugsage +7 -0
  25. data/lib/bugsage/ai_analyzer.rb +145 -0
  26. data/lib/bugsage/ai_chat.rb +388 -0
  27. data/lib/bugsage/ai_context.rb +69 -0
  28. data/lib/bugsage/ai_panel.rb +708 -0
  29. data/lib/bugsage/ai_support.rb +36 -0
  30. data/lib/bugsage/auto_configurator.rb +97 -0
  31. data/lib/bugsage/cli.rb +59 -0
  32. data/lib/bugsage/code_context.rb +81 -0
  33. data/lib/bugsage/code_patch.rb +147 -0
  34. data/lib/bugsage/configuration.rb +149 -0
  35. data/lib/bugsage/console_context.rb +51 -0
  36. data/lib/bugsage/cursor_client.rb +165 -0
  37. data/lib/bugsage/dashboard.rb +627 -0
  38. data/lib/bugsage/editor_links.rb +34 -0
  39. data/lib/bugsage/error_page.rb +298 -0
  40. data/lib/bugsage/exception_handler.rb +66 -0
  41. data/lib/bugsage/exception_support.rb +95 -0
  42. data/lib/bugsage/exceptions_app.rb +31 -0
  43. data/lib/bugsage/fix_applicator.rb +107 -0
  44. data/lib/bugsage/formatter.rb +37 -0
  45. data/lib/bugsage/http_error_capture.rb +104 -0
  46. data/lib/bugsage/http_response_error.rb +14 -0
  47. data/lib/bugsage/inline_console.rb +226 -0
  48. data/lib/bugsage/installation.rb +94 -0
  49. data/lib/bugsage/installer.rb +66 -0
  50. data/lib/bugsage/json_endpoint.rb +34 -0
  51. data/lib/bugsage/locales/en.yml +439 -0
  52. data/lib/bugsage/middleware.rb +152 -0
  53. data/lib/bugsage/openai_client.rb +103 -0
  54. data/lib/bugsage/page_actions.rb +255 -0
  55. data/lib/bugsage/railtie.rb +49 -0
  56. data/lib/bugsage/request_context.rb +56 -0
  57. data/lib/bugsage/rule.rb +271 -0
  58. data/lib/bugsage/session_clear.rb +35 -0
  59. data/lib/bugsage/store.rb +60 -0
  60. data/lib/bugsage/suggestion.rb +58 -0
  61. data/lib/bugsage/trace_cleaner.rb +24 -0
  62. data/lib/bugsage/translations.rb +85 -0
  63. data/lib/bugsage/version.rb +5 -0
  64. data/lib/bugsage.rb +65 -0
  65. data/lib/generators/bugsage/install/install_generator.rb +21 -0
  66. data/lib/generators/bugsage/install/templates/bugsage.rb +22 -0
  67. data/scripts/publish-github-release.sh +38 -0
  68. data/sig/bugsage.rbs +4 -0
  69. metadata +157 -0
data/ROADMAP.md ADDED
@@ -0,0 +1,217 @@
1
+ # BugSage Roadmap
2
+
3
+ This document describes where BugSage is today and where the project is headed. It is a living plan for contributors and users—not a contractual release schedule. Priorities may shift based on feedback, security needs, and community interest.
4
+
5
+ > **Current release:** [v0.2.0](CHANGELOG.md)
6
+ > **Discuss ideas:** [GitHub Issues](https://github.com/MONARCHKOLI/bugsage/issues) · [Feature request template](https://github.com/MONARCHKOLI/bugsage/issues/new/choose)
7
+
8
+ ---
9
+
10
+ ## Vision
11
+
12
+ BugSage aims to be the fastest path from a Rails failure to a confident fix.
13
+
14
+ Today, developers often bounce between stack traces, logs, docs, and AI chat tools with little shared context. BugSage brings **classification, explanation, and actionable repair** into the development loop—starting with deterministic rules and layering optional AI only when you ask for it.
15
+
16
+ Long term, BugSage should feel like a coherent debugging companion across:
17
+
18
+ - Local Rails development (error pages, session dashboard, inline console)
19
+ - CI and pull requests (automated failure analysis)
20
+ - Editors (Cursor, VS Code, RubyMine)
21
+ - Background jobs and production-adjacent log workflows—always with clear safety boundaries
22
+
23
+ **Principles:**
24
+
25
+ 1. **Rules first, AI second** — instant, predictable baselines; AI on demand
26
+ 2. **Zero-config by default** — useful after `bundle install` in development
27
+ 3. **Safe by design** — write actions limited to development/test; production opt-in only with careful defaults
28
+ 4. **Open and extensible** — clear extension points for rules, providers, and plugins
29
+
30
+ ---
31
+
32
+ ## Current Status
33
+
34
+ BugSage **v0.2.x** is a development-focused Rails gem with:
35
+
36
+ | Capability | Status |
37
+ |------------|--------|
38
+ | Zero-config Railtie install | Shipped |
39
+ | Exception classification (Ruby / Rails rules) | Shipped |
40
+ | HTML error page + request context | Shipped |
41
+ | Session dashboard at `/bugsage` | Shipped (in-memory, per process) |
42
+ | Inline Rails console | Shipped |
43
+ | HTTP 4xx/5xx capture (API responses) | Shipped |
44
+ | On-demand AI (OpenAI / Cursor Cloud Agents) | Shipped |
45
+ | Follow-up AI chat + surgical `code_patch` | Shipped |
46
+ | Apply patch / editor deep links | Shipped (dev/test) |
47
+ | I18n-backed user-facing strings | Shipped |
48
+ | Community docs (README, CONTRIBUTING, SECURITY, `docs/`) | In progress / expanding |
49
+
50
+ **Not yet productized:** persistent production analytics, CI GitHub Action, editor extensions, deep Sidekiq/ActiveJob runtime integration beyond exception rules, Docker/log pipelines, or a formal plugin API.
51
+
52
+ ---
53
+
54
+ ## Short-term Goals (v0.2–v0.5)
55
+
56
+ Focus: harden the core gem, improve AI/editor workflows, and prepare for a trustworthy **v1.0**.
57
+
58
+ ### v0.2.x (stability)
59
+
60
+ - Publish clear docs and community health files
61
+ - Expand RSpec coverage for public APIs (Store, CodePatch, HTTP capture edges, CLI)
62
+ - Gemspec / packaging polish for RubyGems release
63
+ - Bug fixes for Rack body handling, chat→apply patch flow, and edge-case capture
64
+
65
+ ### v0.3 — Stronger AI error analysis
66
+
67
+ - Richer AI prompts with safer, more reliable `code_patch` schemas
68
+ - Better multi-file / multi-hunk patch previews
69
+ - Provider resilience (retries, clearer timeouts, offline fallback messaging)
70
+ - Optional “explain this HTTP 400 body” analysis from captured API errors
71
+
72
+ ### v0.4 — Rails dashboard 2.0
73
+
74
+ - Persist session history across requests more usefully (optional file/SQLite/Redis store)
75
+ - Filtering, search, and grouping (by exception class, path, confidence)
76
+ - Clearer split between exception events and HTTP error events
77
+ - Export a single error as a shareable Markdown / clipboard report
78
+
79
+ ### v0.5 — Jobs & CI foundations
80
+
81
+ - Deeper **ActiveJob** and **Sidekiq** error context (queue, job class, arguments sanitization)
82
+ - First **GitHub Action** prototype: annotate failing CI jobs with BugSage-style summaries
83
+ - Public **plugin-ready hooks** for custom rules (preview of the later plugin system)
84
+
85
+ ---
86
+
87
+ ## Mid-term Goals (v1.0)
88
+
89
+ **v1.0** marks BugSage as a stable, documented tool for day-to-day Rails development.
90
+
91
+ ### Release criteria (target)
92
+
93
+ - SemVer stability commitments for public Ruby APIs (`Bugsage.configure`, rule result shape, patch schema)
94
+ - Comprehensive docs and examples
95
+ - Solid test matrix (Ruby 3.2+ × modern Rails)
96
+ - Official RubyGems release with MFA and security policy
97
+
98
+ ### Headline v1.0 themes
99
+
100
+ | Theme | Outcome |
101
+ |-------|---------|
102
+ | **AI Error Analysis** | Dependable on-demand analysis with structured patches and chat refinement |
103
+ | **Rails Dashboard** | Polished session dashboard suitable as the default local error hub |
104
+ | **Cursor Integration** | First-class Cursor provider + deep links + smoother “open and apply” loop |
105
+ | **ActiveJob / Sidekiq Support** | First-class job failure context in dashboard and AI prompts |
106
+ | **GitHub Action** | Supported action for PR/CI failure comments (opt-in) |
107
+ | **Plugin System (v1)** | Documented API for custom rules and suggestion enrichers |
108
+
109
+ v1.0 remains **development-first**. Production deployment, if offered, will be explicit, limited, and separately documented.
110
+
111
+ ---
112
+
113
+ ## Long-term Goals (v2.0+)
114
+
115
+ **v2.0+** expands BugSage from an in-app development assistant into a broader debugging platform—without abandoning the rules-first identity.
116
+
117
+ | Theme | Direction |
118
+ |-------|-----------|
119
+ | **Log Analyzer** | Parse Rails / job logs into classified events offline or in CI |
120
+ | **Docker Logs** | Tail or batch-analyze container logs with the same rule engine |
121
+ | **Production Log Analysis** | Redacted, privacy-aware analysis pipelines (never default-on) |
122
+ | **Performance Analyzer** | Slow endpoints, N+1 hints, allocation hotspots as advisory findings |
123
+ | **Security Checks** | Opinionated checks for risky patterns (open redirects, unsafe eval in captured context, secret leakage in error pages) |
124
+ | **VS Code Extension** | Browse BugSage events, jump to frames, trigger explain/fix from the editor |
125
+ | **RubyMine Plugin** | Parity features for JetBrains workflows |
126
+ | **Plugin System (v2)** | Installable rule packs and provider plugins |
127
+ | **Ecosystem** | Shared formats for CI annotations, editor protocols, and report export |
128
+
129
+ These tracks are aspirational and may ship as companion repos (for example `bugsage-action`, `bugsage-vscode`) rather than inside the core gem.
130
+
131
+ ---
132
+
133
+ ## Planned Features
134
+
135
+ Status key: **Shipped** · **Partial** · **Planned** · **Exploratory**
136
+
137
+ | Feature | Status | Target window | Notes |
138
+ |---------|--------|---------------|-------|
139
+ | **AI Error Analysis** | Partial | v0.3 → v1.0 | On-demand OpenAI/Cursor + chat/patches shipped; depth & reliability ongoing |
140
+ | **Rails Dashboard** | Partial | v0.4 → v1.0 | Session UI shipped; persistence, filters, exports planned |
141
+ | **Cursor Integration** | Partial | v0.3 → v1.0 | Cloud Agents provider + editor links shipped; tighter UX planned |
142
+ | **ActiveJob Support** | Partial | v0.5 → v1.0 | Deserialization/rules exist; richer job metadata planned |
143
+ | **Sidekiq Support** | Planned | v0.5 → v1.0 | Failure middleware / context adapters |
144
+ | **GitHub Action** | Planned | v0.5 → v1.0 | CI annotations from test/job failures |
145
+ | **Plugin System** | Planned | v0.5 → v2.0 | Custom rules first; installable packs later |
146
+ | **VS Code Extension** | Planned | v2.0+ | Companion extension |
147
+ | **RubyMine Plugin** | Planned | v2.0+ | Companion plugin |
148
+ | **Log Analyzer** | Planned | v2.0+ | Offline/CI log → classified events |
149
+ | **Docker Logs** | Planned | v2.0+ | Container log ingestion |
150
+ | **Production Log Analysis** | Exploratory | v2.0+ | Strict redaction & opt-in only |
151
+ | **Performance Analyzer** | Exploratory | v2.0+ | Advisory performance findings |
152
+ | **Security Checks** | Exploratory | v1.0 → v2.0 | Start with safe defaults in error presentation |
153
+
154
+ ---
155
+
156
+ ## Nice-to-have Features
157
+
158
+ Ideas we like but are not committed to a milestone:
159
+
160
+ - Slack / Discord webhook summaries for local session digests
161
+ - Browser extension to pin the BugSage dashboard beside the app
162
+ - Multi-language UI beyond English locale files
163
+ - “Reproduction gist” exporter (redacted params + failing snippet)
164
+ - Webhook provider plugins (non–OpenAI/Cursor HTTP endpoints)
165
+ - Replayable fixture recorder for flaky request failures
166
+ - Metrics: time-to-fix estimates from historical session data (local only)
167
+ - Themeable error page / dashboard CSS tokens for host apps
168
+
169
+ Propose additions via a [feature request](https://github.com/MONARCHKOLI/bugsage/issues/new/choose).
170
+
171
+ ---
172
+
173
+ ## Community Contributions
174
+
175
+ BugSage welcomes contributions of all sizes. High-impact areas:
176
+
177
+ | Area | How to help |
178
+ |------|-------------|
179
+ | **Bug reports** | Use the bug report template; include Ruby/Rails/BugSage versions |
180
+ | **Rules** | Add deterministic matchers for common Rails/Ruby failures + specs |
181
+ | **Docs** | Improve `docs/`, README examples, and troubleshooting |
182
+ | **Tests** | Fill public API coverage gaps called out in reviews/issues |
183
+ | **AI providers** | Hardening, fixtures, and safer patch schemas |
184
+ | **Jobs** | Sidekiq / ActiveJob integrations with sanitized argument display |
185
+ | **Tooling** | GitHub Action, editor extensions (often as companion repos) |
186
+
187
+ ### Getting started
188
+
189
+ 1. Read [CONTRIBUTING.md](CONTRIBUTING.md)
190
+ 2. Skim [docs/GettingStarted.md](docs/GettingStarted.md) (if present)
191
+ 3. Open an issue before large features
192
+ 4. Prefer small PRs with specs and changelog notes under `[Unreleased]`
193
+
194
+ ### Security
195
+
196
+ Do **not** report vulnerabilities in public issues. Follow [SECURITY.md](SECURITY.md).
197
+
198
+ ### Roadmap feedback
199
+
200
+ If a planned item should move up or down:
201
+
202
+ - Comment on an existing related issue, or
203
+ - Open a feature request describing user impact and whether it changes zero-config defaults
204
+
205
+ ---
206
+
207
+ ## Version legend
208
+
209
+ | Range | Intent |
210
+ |-------|--------|
211
+ | **v0.2–v0.5** | Iterate quickly; APIs may refine before 1.0 |
212
+ | **v1.0** | Stable core for Rails development workflows |
213
+ | **v2.0+** | Broader platform (logs, CI depth, editors, production-adjacent tools) |
214
+
215
+ ---
216
+
217
+ *Last updated: July 2026. Maintainers will revise this file as milestones land.*
data/SECURITY.md ADDED
@@ -0,0 +1,83 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ The following versions of BugSage receive security updates:
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 0.2.x | :white_check_mark: |
10
+ | 0.1.x | :x: |
11
+ | < 0.1 | :x: |
12
+
13
+ Only the latest minor release line (`0.2.x`) is actively maintained. If you discover a vulnerability in an older release, please still report it — we may issue guidance or backport a fix when impact is high.
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ **Please do not report security vulnerabilities through public GitHub issues, pull requests, or discussions.**
18
+
19
+ ### Preferred method
20
+
21
+ Report vulnerabilities privately using [GitHub Security Advisories](https://github.com/MONARCHKOLI/bugsage/security/advisories/new):
22
+
23
+ 1. Open **Report a vulnerability** on the repository Security Advisories page.
24
+ 2. Include as much detail as you can (see below).
25
+ 3. Submit the report. Only maintainers will be able to see it until we choose to publish or request a CVE.
26
+
27
+ ### Alternative method
28
+
29
+ If you cannot use private reporting, email the maintainer at [monarchkoli12@gmail.com](mailto:monarchkoli12@gmail.com) with the subject line:
30
+
31
+ ```text
32
+ [SECURITY] BugSage vulnerability report
33
+ ```
34
+
35
+ ### What to include
36
+
37
+ Please provide:
38
+
39
+ - A clear description of the vulnerability and its potential impact
40
+ - Affected BugSage version(s) (gem version or Git commit SHA)
41
+ - Ruby and Rails versions used in reproduction
42
+ - Step-by-step reproduction instructions
43
+ - Proof of concept, logs, or patches (if available)
44
+ - Any suggested remediation
45
+
46
+ Redact secrets, API keys, and personal data from reproductions and logs.
47
+
48
+ ### What to expect
49
+
50
+ | Stage | Expectation |
51
+ | ----- | ----------- |
52
+ | Acknowledgement | Within **5 business days** |
53
+ | Initial triage | Within **10 business days** of acknowledgement |
54
+ | Status updates | As progress is made, or at least every **30 days** until resolution |
55
+
56
+ If the report is **accepted**, we will work on a fix, coordinate disclosure timing with you when possible, and publish a security advisory and/or `CHANGELOG.md` entry as appropriate.
57
+
58
+ If the report is **declined** (for example, out of scope, already fixed, or not a security issue), we will explain why.
59
+
60
+ We ask that you **do not publicly disclose** the vulnerability until we have released a fix or explicitly agreed on a disclosure date. Coordinated disclosure windows of up to **90 days** are typical unless a shorter or longer timeline is agreed.
61
+
62
+ ## Scope
63
+
64
+ In scope for this policy includes, for example:
65
+
66
+ - Remote or local privilege escalation via BugSage middleware or endpoints
67
+ - Unintended exposure of application secrets, credentials, or user data through BugSage capture, logging, dashboard, console, or AI features
68
+ - Path traversal or arbitrary file write through apply-fix / patch features outside intended development safeguards
69
+ - Cross-site scripting or request forgery affecting BugSage-served pages or endpoints
70
+ - Supply-chain issues in published gem artifacts
71
+
72
+ Out of scope (please use public issues when appropriate):
73
+
74
+ - Bugs with no security impact
75
+ - Denial of service that only requires exhausting normal application resources
76
+ - Vulnerabilities solely in third-party dependencies (report upstream; tell us if BugSage needs a dependency bump)
77
+ - Security issues in host Rails applications that are not caused by BugSage
78
+
79
+ ## Safe Harbor
80
+
81
+ We appreciate good-faith security research. If you report a vulnerability responsibly and in accordance with this policy, we will not pursue legal action related to that research.
82
+
83
+ Thank you for helping keep BugSage and its users safe.
data/docs/AI.md ADDED
@@ -0,0 +1,167 @@
1
+ # AI
2
+
3
+ BugSage can optionally refine rule-based suggestions with OpenAI or Cursor. AI is **on-demand**: the error page stays fast, and the provider is called only when you click **Quick Fix Suggestion** or send a **Chat** message.
4
+
5
+ Related docs: [GettingStarted.md](GettingStarted.md) · [Configuration.md](Configuration.md) · [Troubleshooting.md](Troubleshooting.md)
6
+
7
+ ## Enable AI
8
+
9
+ ### 1. Provide an API key
10
+
11
+ In the same shell that starts Rails:
12
+
13
+ ```bash
14
+ # OpenAI
15
+ export OPENAI_API_KEY=sk-your-openai-key-here
16
+
17
+ # or Cursor
18
+ export CURSOR_API_KEY=crsr_your-cursor-key-here
19
+
20
+ bin/rails server
21
+ ```
22
+
23
+ Alternate variable names:
24
+
25
+ | Provider | Environment variables |
26
+ |----------|------------------------|
27
+ | OpenAI | `OPENAI_API_KEY`, `BUGSAGE_OPENAI_API_KEY` |
28
+ | Cursor | `CURSOR_API_KEY`, `BUGSAGE_CURSOR_API_KEY` |
29
+
30
+ ### 2. Confirm the panel appears
31
+
32
+ On the BugSage error page or `/bugsage` dashboard you should see the **AI Suggestions** panel when AI is enabled.
33
+
34
+ If no key is present, BugSage continues to work with rule-based suggestions only.
35
+
36
+ ### 3. Use Quick Fix and Chat
37
+
38
+ 1. Toggle **Enable AI** if your browser session has it turned off (`localStorage`).
39
+ 2. Click **Quick Fix Suggestion**.
40
+ 3. Wait for the loading animation (Cursor can take longer — up to ~90 seconds).
41
+ 4. Review fixes, AI notes, and the `code_patch` preview.
42
+ 5. Optionally open **Chat** to refine the patch (for example, “comment out that line instead of deleting it”).
43
+ 6. On the dashboard, use **Apply AI to Codebase** to write the latest patch to disk.
44
+
45
+ ## Provider selection
46
+
47
+ | Situation | Provider used |
48
+ |-----------|---------------|
49
+ | `config.bugsage.ai_provider = :openai` | OpenAI |
50
+ | `config.bugsage.ai_provider = :cursor` | Cursor |
51
+ | Key starts with `crsr_` | Cursor (auto) |
52
+ | Key starts with `sk-` / other OpenAI keys | OpenAI (auto) |
53
+ | Cursor key stored in `OPENAI_API_KEY` | Cursor (prefix detected) |
54
+
55
+ Explicit config example:
56
+
57
+ ```ruby
58
+ Rails.application.configure do |config|
59
+ config.bugsage.ai_enabled = true
60
+ config.bugsage.ai_provider = :cursor
61
+ # config.bugsage.cursor_model = "composer-2.5" # optional
62
+ end
63
+ ```
64
+
65
+ OpenAI model example:
66
+
67
+ ```ruby
68
+ Rails.application.configure do |config|
69
+ config.bugsage.ai_provider = :openai
70
+ config.bugsage.openai_model = "gpt-4o-mini"
71
+ config.bugsage.openai_api_base = "https://api.openai.com/v1"
72
+ end
73
+ ```
74
+
75
+ ## What AI receives
76
+
77
+ When you request a Quick Fix, BugSage sends:
78
+
79
+ - Exception class and message
80
+ - Numbered source context around the failure (±20 lines)
81
+ - Request context (path, controller, action, parameters when available)
82
+ - Current rule-based classification
83
+
84
+ Chat continues from that context and can return an updated `code_patch`.
85
+
86
+ ## Structured code patches
87
+
88
+ AI responses should include a surgical `code_patch` instead of blind search/replace:
89
+
90
+ | Action | Meaning |
91
+ |--------|---------|
92
+ | `delete_lines` | Remove one or more lines |
93
+ | `replace_lines` | Replace specific lines (for example comment out code) |
94
+ | `insert_before` | Insert code before a line |
95
+ | `no_change` | File already contains the correct fix |
96
+
97
+ BugSage:
98
+
99
+ - Uses absolute line numbers from numbered source context
100
+ - Rejects patches that would duplicate existing code
101
+ - Preserves indentation when applying
102
+
103
+ Chat-refined patches update the preview and the **Apply AI to Codebase** action. They are also persisted in the session store so the latest patch is used on apply.
104
+
105
+ ## Dashboard AI actions
106
+
107
+ Available on `/bugsage` (not all actions appear on the full-page error view):
108
+
109
+ | Action | Purpose |
110
+ |--------|---------|
111
+ | **Quick Fix Suggestion** | Request AI analysis |
112
+ | **Chat** | Follow up and refine the patch |
113
+ | **Apply AI to Codebase** | Write the current `code_patch` to the source file |
114
+ | **Open in Cursor** / **Open in VS Code** | Jump to file and line |
115
+ | **Copy Fix** | Copy a prompt for your editor AI |
116
+ | **Apply Fix to File** | Insert a `# BUGSAGE:` comment (non-AI helper) |
117
+
118
+ **Apply AI to Codebase** / apply-fix endpoints are limited to **development** and **test**.
119
+
120
+ ## Timeouts
121
+
122
+ | Provider | Default behavior |
123
+ |----------|------------------|
124
+ | OpenAI | `ai_timeout` default `15` seconds |
125
+ | Cursor | Effective timeout is at least `90` seconds (`[ai_timeout, 90].max`) |
126
+
127
+ Cursor runs through the [Cloud Agents API](https://cursor.com/docs/cloud-agent/api/endpoints) and often needs the longer window on the first response.
128
+
129
+ ```ruby
130
+ config.bugsage.ai_timeout = 120
131
+ ```
132
+
133
+ ## Disable AI
134
+
135
+ ```ruby
136
+ Rails.application.configure do |config|
137
+ config.bugsage.ai_enabled = false
138
+ end
139
+ ```
140
+
141
+ Or simply unset the API keys before starting the server.
142
+
143
+ ## Failure behavior
144
+
145
+ If the AI API fails (invalid key, rate limit, timeout, network error):
146
+
147
+ - BugSage keeps the rule-based suggestion
148
+ - A warning is logged, for example:
149
+
150
+ ```text
151
+ [BugSage] AI enhancement failed: ...
152
+ ```
153
+
154
+ The error page and dashboard remain usable without AI.
155
+
156
+ ## Related API endpoints
157
+
158
+ | Endpoint | Method | Purpose |
159
+ |----------|--------|---------|
160
+ | `/bugsage/ai-suggest` | `POST` | Quick Fix |
161
+ | `/bugsage/ai-chat` | `POST` | Chat + optional patch update |
162
+ | `/bugsage/apply-fix` | `POST` | Apply `code_patch` (dev/test only) |
163
+
164
+ ## Related
165
+
166
+ - [Configuration.md](Configuration.md) — all AI-related options
167
+ - [Troubleshooting.md](Troubleshooting.md) — AI-specific failures
@@ -0,0 +1,168 @@
1
+ # Configuration
2
+
3
+ BugSage is designed for zero configuration. Use this guide when you need to override defaults.
4
+
5
+ Related docs: [GettingStarted.md](GettingStarted.md) · [AI.md](AI.md) · [Troubleshooting.md](Troubleshooting.md)
6
+
7
+ ## How to configure
8
+
9
+ ### Rails initializer (recommended)
10
+
11
+ ```ruby
12
+ # config/initializers/bugsage.rb
13
+ Rails.application.configure do |config|
14
+ config.bugsage.enabled_environments = %i[development test staging]
15
+ config.bugsage.show_error_page = true
16
+ config.bugsage.show_dashboard = true
17
+ config.bugsage.ai_enabled = true
18
+ config.bugsage.ai_provider = :cursor
19
+ end
20
+ ```
21
+
22
+ Generate a commented starter file with:
23
+
24
+ ```bash
25
+ bundle exec rails generate bugsage:install
26
+ ```
27
+
28
+ ### Runtime configuration
29
+
30
+ ```ruby
31
+ Bugsage.configure do |config|
32
+ config.ai_enabled = true
33
+ config.openai_model = "gpt-4o-mini"
34
+ config.capture_http_errors = false
35
+ end
36
+ ```
37
+
38
+ ### Environment variables
39
+
40
+ | Variable | Purpose |
41
+ |----------|---------|
42
+ | `BUGSAGE_ENABLED_ENVIRONMENTS` | Comma-separated environments (for example `development,test,staging`) |
43
+ | `OPENAI_API_KEY` / `BUGSAGE_OPENAI_API_KEY` | OpenAI key (`sk-...`) |
44
+ | `CURSOR_API_KEY` / `BUGSAGE_CURSOR_API_KEY` | Cursor key (`crsr_...`) |
45
+
46
+ Keys must be present in the environment of the process that starts `bin/rails server`.
47
+
48
+ Restart the Rails server after changing configuration or environment variables.
49
+
50
+ ## Options reference
51
+
52
+ | Option | Default | Description |
53
+ |--------|---------|-------------|
54
+ | `enabled_environments` | `development`, `test` | Environments where BugSage runs |
55
+ | `show_error_page` | `true` in development only | Replace raised exceptions with the BugSage HTML page |
56
+ | `show_dashboard` | `true` in development only | Serve `GET /bugsage` |
57
+ | `show_inline_console` | `true` in development only | Enable the inline Rails console |
58
+ | `capture_errors` | `true` | Store caught errors in the in-memory session store |
59
+ | `capture_http_errors` | `true` | Capture HTTP status ≥ 400 when `capture_errors` is on |
60
+ | `ai_enabled` | auto (`true` when an API key is present) | Show the AI panel; does not call the API until Quick Fix / Chat |
61
+ | `ai_provider` | auto-detected | `:openai` or `:cursor` |
62
+ | `openai_api_key` | `nil` (env fallback) | OpenAI API key |
63
+ | `openai_model` | `gpt-4o-mini` | OpenAI model name |
64
+ | `openai_api_base` | `https://api.openai.com/v1` | OpenAI-compatible base URL |
65
+ | `cursor_api_key` | `nil` (env fallback) | Cursor API key |
66
+ | `cursor_model` | `nil` (account default) | Cursor Cloud Agents model |
67
+ | `cursor_api_base` | `https://api.cursor.com` | Cursor API base URL |
68
+ | `ai_timeout` | `15` (minimum `90` for Cursor) | Request/poll timeout in seconds |
69
+ | `ai_client` | `nil` | Custom AI client for tests or alternate providers |
70
+ | `fallback_exceptions_app` | `nil` | Optional fallback Rack app for routing errors |
71
+
72
+ ## Default behavior by environment
73
+
74
+ | Environment | Error page | Dashboard | Capture | AI (if configured) |
75
+ |-------------|------------|-----------|---------|--------------------|
76
+ | **development** | BugSage page | `/bugsage` | Yes | Available |
77
+ | **test** | Rails default | Off | Yes (silent) | Available |
78
+ | **production** | Off | Off | Off | Off |
79
+
80
+ BugSage is **off** in production unless you explicitly add `production` to `enabled_environments`. Even then, prefer keeping `show_error_page` and `show_dashboard` disabled in production.
81
+
82
+ ## Common configuration recipes
83
+
84
+ ### Enable BugSage in staging
85
+
86
+ ```ruby
87
+ Rails.application.configure do |config|
88
+ config.bugsage.enabled_environments = %i[development test staging]
89
+ end
90
+ ```
91
+
92
+ Or:
93
+
94
+ ```bash
95
+ export BUGSAGE_ENABLED_ENVIRONMENTS=development,test,staging
96
+ ```
97
+
98
+ ### Capture errors silently (no BugSage HTML page)
99
+
100
+ Useful when you want the dashboard/store without replacing Rails’ error UI:
101
+
102
+ ```ruby
103
+ Rails.application.configure do |config|
104
+ config.bugsage.show_error_page = false
105
+ config.bugsage.capture_errors = true
106
+ end
107
+ ```
108
+
109
+ ### Disable HTTP response capture
110
+
111
+ ```ruby
112
+ Rails.application.configure do |config|
113
+ config.bugsage.capture_http_errors = false
114
+ end
115
+ ```
116
+
117
+ ### Force OpenAI or Cursor
118
+
119
+ ```ruby
120
+ Rails.application.configure do |config|
121
+ config.bugsage.ai_enabled = true
122
+ config.bugsage.ai_provider = :openai
123
+ # or
124
+ # config.bugsage.ai_provider = :cursor
125
+ end
126
+ ```
127
+
128
+ ### Turn AI off completely
129
+
130
+ ```ruby
131
+ Rails.application.configure do |config|
132
+ config.bugsage.ai_enabled = false
133
+ end
134
+ ```
135
+
136
+ ### Disable the dashboard or inline console
137
+
138
+ ```ruby
139
+ Rails.application.configure do |config|
140
+ config.bugsage.show_dashboard = false
141
+ config.bugsage.show_inline_console = false
142
+ end
143
+ ```
144
+
145
+ ## Endpoints BugSage registers
146
+
147
+ These are served by BugSage middleware when the gem is enabled:
148
+
149
+ | Endpoint | Method | Purpose |
150
+ |----------|--------|---------|
151
+ | `/bugsage` | `GET` | Session dashboard |
152
+ | `/bugsage/console` | `POST` | Inline console evaluation |
153
+ | `/bugsage/ai-suggest` | `POST` | Quick Fix AI request |
154
+ | `/bugsage/ai-chat` | `POST` | Follow-up chat / patch refinement |
155
+ | `/bugsage/apply-fix` | `POST` | Apply a `code_patch` (development/test only) |
156
+ | `/bugsage/clear` | `POST` | Clear session error store |
157
+
158
+ ## Internationalization
159
+
160
+ User-facing strings ship in `lib/bugsage/locales/en.yml` and are read through `Bugsage.t`.
161
+
162
+ Host apps can override keys via Rails I18n (for example `config/locales/bugsage.en.yml`) using the same key structure under the `bugsage` namespace.
163
+
164
+ ## Related
165
+
166
+ - [GettingStarted.md](GettingStarted.md) — install and verify
167
+ - [AI.md](AI.md) — providers, chat, and patches
168
+ - [Troubleshooting.md](Troubleshooting.md) — common problems