context_drop 0.1.4 → 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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +330 -116
  3. data/Rakefile +110 -1
  4. data/SPEC.md +74 -26
  5. data/app/assets/javascripts/context_drop/context_drop.js +6329 -682
  6. data/app/controllers/context_drop/agent_controller.rb +170 -0
  7. data/app/controllers/context_drop/application_controller.rb +52 -3
  8. data/app/controllers/context_drop/configs_controller.rb +12 -2
  9. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +15 -11
  10. data/app/controllers/context_drop/feedbacks_controller.rb +396 -20
  11. data/app/controllers/context_drop/mcp_controller.rb +2 -1
  12. data/app/helpers/context_drop/widget_helper.rb +11 -1
  13. data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
  14. data/app/javascript/context_drop/__tests__/widget.test.ts +1015 -89
  15. data/app/javascript/context_drop/api-client.ts +422 -19
  16. data/app/javascript/context_drop/element-picker.ts +186 -34
  17. data/app/javascript/context_drop/icons.ts +28 -0
  18. data/app/javascript/context_drop/markdown.ts +146 -0
  19. data/app/javascript/context_drop/sanitizer.ts +413 -2
  20. data/app/javascript/context_drop/screenshot.ts +103 -9
  21. data/app/javascript/context_drop/styles.ts +1705 -248
  22. data/app/javascript/context_drop/types.ts +243 -6
  23. data/app/javascript/context_drop/widget.ts +3318 -294
  24. data/app/models/context_drop/feedback.rb +88 -8
  25. data/app/services/context_drop/ownership_token.rb +114 -0
  26. data/app/views/context_drop/dashboard/feedbacks/index.html.erb +13 -0
  27. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +19 -0
  28. data/app/views/layouts/context_drop/application.html.erb +6 -0
  29. data/config/routes.rb +22 -0
  30. data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
  31. data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
  32. data/lib/context_drop/agent/key_store.rb +290 -0
  33. data/lib/context_drop/agent/llm_client.rb +413 -0
  34. data/lib/context_drop/agent/orchestrator.rb +314 -0
  35. data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
  36. data/lib/context_drop/configuration.rb +242 -3
  37. data/lib/context_drop/mcp/dispatcher.rb +71 -29
  38. data/lib/context_drop/mcp/environment_router.rb +115 -0
  39. data/lib/context_drop/mcp/prompts/investigate_feedback.rb +90 -9
  40. data/lib/context_drop/mcp/remote_client.rb +120 -0
  41. data/lib/context_drop/mcp/server.rb +9 -2
  42. data/lib/context_drop/mcp/tools/get_feedback.rb +62 -5
  43. data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +29 -4
  44. data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
  45. data/lib/context_drop/mcp/tools/list_feedbacks.rb +195 -23
  46. data/lib/context_drop/mcp/tools/update_feedback_status.rb +48 -5
  47. data/lib/context_drop/version.rb +1 -1
  48. data/lib/context_drop.rb +8 -2
  49. data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
  50. metadata +14 -2
data/Rakefile CHANGED
@@ -1,8 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
4
+ require "shellwords"
3
5
  require "bundler/gem_tasks"
4
6
  require "rake/testtask"
5
7
 
8
+ module ContextDropReleaseExtension
9
+ protected
10
+
11
+ def sign_git_tag?
12
+ !%w[n no nil false off 0].include?(ENV["sign_tag"].to_s.downcase)
13
+ end
14
+
15
+ def tag_version
16
+ tag_cmd = ["git", "tag"]
17
+ tag_cmd << "-s" if sign_git_tag?
18
+ tag_cmd.push("-m", "Version #{version}", version_tag)
19
+
20
+ tagged = false
21
+ Bundler.ui.debug(tag_cmd)
22
+ Bundler::SharedHelpers.chdir(base) do
23
+ unless Kernel.system(*tag_cmd)
24
+ raise("Running `#{tag_cmd.shelljoin}` failed. Ensure git signing (user.signingkey / gpg.format) is configured, or pass sign_tag=no.")
25
+ end
26
+ tagged = true
27
+ end
28
+
29
+ Bundler.ui.confirm "Tagged #{version_tag}#{sign_git_tag? ? ' (signed)' : ''}."
30
+ yield if block_given?
31
+ rescue RuntimeError
32
+ if tagged
33
+ Bundler.ui.error "Untagging #{version_tag} due to error."
34
+ sh_with_status %W[git tag -d #{version_tag}]
35
+ end
36
+ raise
37
+ end
38
+ end
39
+
40
+ Bundler::GemHelper.prepend(ContextDropReleaseExtension)
41
+
6
42
  Rake::TestTask.new(:test) do |t|
7
43
  t.libs << "lib"
8
44
  t.libs << "spec"
@@ -11,10 +47,83 @@ Rake::TestTask.new(:test) do |t|
11
47
  end
12
48
 
13
49
  namespace :assets do
14
- desc "Build the decoupled TypeScript widget into app/assets/javascripts/context_drop/context_drop.js"
50
+ desc "Build the TypeScript widget bundle and NPM dist/ artifacts"
15
51
  task :build do
16
52
  sh "npm run build"
17
53
  end
18
54
  end
19
55
 
56
+ namespace :version do
57
+ desc "Synchronize version across RubyGem, package.json, and TypeScript sources (e.g. rake 'version:bump[0.2.1]')"
58
+ task :bump, [:new_version] do |_, args|
59
+ new_version = args[:new_version].to_s.strip
60
+ unless new_version.match?(/\A\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?\z/)
61
+ abort "Usage: bundle exec rake 'version:bump[X.Y.Z]' (got #{new_version.inspect})"
62
+ end
63
+
64
+ root = File.expand_path(__dir__)
65
+
66
+ version_rb = File.join(root, "lib/context_drop/version.rb")
67
+ updated_rb = File.read(version_rb).sub(/VERSION\s*=\s*"[^"]+"/, %(VERSION = "#{new_version}"))
68
+ File.write(version_rb, updated_rb)
69
+
70
+ ts_types = File.join(root, "src/server/types.ts")
71
+ updated_ts = File.read(ts_types).sub(/export const VERSION\s*=\s*"[^"]+";/, %(export const VERSION = "#{new_version}";))
72
+ File.write(ts_types, updated_ts)
73
+
74
+ sh "npm", "version", new_version, "--no-git-tag-version", "--allow-same-version"
75
+ sh "npm", "run", "build"
76
+
77
+ puts "Synchronized ContextDrop version to #{new_version} across RubyGem and NPM."
78
+ end
79
+ end
80
+
81
+ namespace :release do
82
+ desc "Verify RubyGem, package.json, and TypeScript VERSION constants match"
83
+ task :verify_versions do
84
+ root = File.expand_path(__dir__)
85
+ gem_version = Bundler::GemHelper.instance.gemspec.version.to_s
86
+ pkg_version = JSON.parse(File.read(File.join(root, "package.json"))).fetch("version")
87
+ ts_content = File.read(File.join(root, "src/server/types.ts"))
88
+ ts_version = ts_content[/export const VERSION\s*=\s*"([^"]+)"/, 1]
89
+
90
+ if [gem_version, pkg_version, ts_version].uniq.size != 1
91
+ abort <<~MSG
92
+ Version mismatch detected before release!
93
+ lib/context_drop/version.rb : #{gem_version}
94
+ package.json : #{pkg_version}
95
+ src/server/types.ts : #{ts_version}
96
+ Run `bundle exec rake "version:bump[#{gem_version}]"` to synchronize them first.
97
+ MSG
98
+ end
99
+ end
100
+
101
+ desc "Publish context-drop NPM package to npmjs.org (skip with npm_push=no)"
102
+ task :npm_push do
103
+ next if %w[n no nil false off 0].include?(ENV["npm_push"].to_s.downcase)
104
+
105
+ pkg_version = JSON.parse(File.read(File.expand_path("package.json", __dir__))).fetch("version")
106
+ existing_out = IO.popen(%W[npm view context-drop@#{pkg_version} version], err: [:child, :out], &:read)
107
+ if $?.success? && existing_out.strip == pkg_version
108
+ Bundler.ui.confirm "context-drop@#{pkg_version} is already published on npmjs.org, skipping."
109
+ next
110
+ end
111
+
112
+ Bundler.ui.confirm "Publishing context-drop@#{pkg_version} to npmjs.org..."
113
+ abort "npm publish failed!" unless Kernel.system("npm", "publish", "--access", "public")
114
+ Bundler.ui.confirm "Pushed context-drop@#{pkg_version} to npmjs.org."
115
+ end
116
+ end
117
+
118
+ Rake::Task["build"].enhance(["assets:build"])
119
+ Rake::Task["release:guard_clean"].enhance(["release:verify_versions"])
120
+ Rake::Task["release"].enhance do
121
+ Rake::Task["release:npm_push"].invoke
122
+ end
123
+ Rake::Task["release"].clear_comments
124
+ Rake::Task["release"].add_description(
125
+ "Create signed tag v#{ContextDrop::VERSION}, build & push context_drop-#{ContextDrop::VERSION}.gem to RubyGems, " \
126
+ "and publish context-drop@#{ContextDrop::VERSION} to NPM (skip with gem_push=no / npm_push=no / sign_tag=no)"
127
+ )
128
+
20
129
  task default: :test
data/SPEC.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # ContextDrop — Technical Specification
2
2
 
3
- **Status:** Draft (v0.1.0-spec)
3
+ **Status:** Active (`v0.2.0`)
4
4
  **Project Type:** Open-source Ruby Gem (`context_drop`)
5
- **Architecture:** Mountable Ruby on Rails Engine (`isolate_namespace ContextDrop`) + Decoupled TypeScript Frontend Widget + MCP Server
6
- **License:** MIT (Proposed / TBD)
5
+ **Architecture:** Mountable Ruby on Rails Engine (`isolate_namespace ContextDrop`) + Decoupled TypeScript Frontend Widget + Unified Multi-Environment MCP Hub + Local BYOK Agentic Coding Sidebar
6
+ **License:** MIT
7
7
  **Working Name:** ContextDrop
8
8
 
9
9
  > **Core Design Principle:**
@@ -68,12 +68,13 @@ The host application remains responsible for deciding whether authentication is
68
68
 
69
69
  ## 4. User Experience
70
70
 
71
- ### 4.1 Freely Floating Pin Dock & Draggable Chatbox
71
+ ### 4.1 Book-Corner Fold Launcher & Peel-to-Pin Morph (`v0.2`)
72
72
 
73
- ContextDrop provides a freely draggable floating Pin dock and chatbox on configured application pages:
74
- - **Positioning:** `position: fixed` relative to the viewport, starting at the configured corner (`:top_left`, `:bottom_right`, `:bottom_left`, `:top_right`) and freely draggable anywhere within viewport bounds.
75
- - **Pin-Shaped Selector:** Available both on the floating dock (`.cd-floating-pin-btn`) and anchored at the **top-left corner of the chatbox header** (`.cd-pin-corner-btn`) with an asymmetric pushpin silhouette (`11px 11px 11px 3px`).
76
- - **Minimize to Compact Bar:** While pinning elements on the page (or when clicking the header minimize button), the chatbox collapses into a compact floating bar (`.cd-compact-bar`) with live DOM breadcrumbs, layer Up/Down buttons, and an expand-to-chat toggle so the host page remains unobstructed.
73
+ ContextDrop rests flush in a single viewport corner rather than rendering a wide floating pill:
74
+ - **Flush Book-Corner Launcher (`.cd-book-corner`):** Compact `38×38px` (`46×46px` on hover) folded archival paper corner flush against the configured viewport corner (`:bottom_right`, `:bottom_left`, `:top_right`, `:top_left`).
75
+ - **Click Action:** Clicking the book corner opens the Feedback Chatbox (`.cd-composer`) in deployed environments (`staging`, `production`) and in local development by default (using staging/verbose mode so developers can test bug pinning and use their external IDE agents via MCP). When opted in via `config.enable_local_agent = true` on loopback (`127.0.0.1` / `::1`), it opens the docked **Local BYOK Agentic Coding Sidebar** (`.cd-agent-sidebar`) with an `Agent | Feedback` mode switcher.
76
+ - **Peel-and-Drop to Pin on Drag:** Dragging the book corner past `6px` animates the folded corner into an asymmetric pushpin (`.cd-drag-pin`) with live Inspector Cobalt element highlighting (`Release to pin`). Releasing over any valid DOM element pins it directly and opens the active composer/sidebar with the element attached; releasing inside another `68×68px` viewport corner zone (`.cd-corner-snap-ghost`) re-docks the book corner to that corner.
77
+ - **Minimize to Compact Bar:** While pinning elements via click-mode (`Pin Element` button in `.cd-pin-corner-btn`), the chatbox or sidebar collapses into a compact floating bar (`.cd-compact-bar`) with live DOM breadcrumbs, layer Up/Down buttons, and an expand toggle so the host page remains unobstructed.
77
78
 
78
79
  ### 4.2 Chatbox Feedback Composer
79
80
 
@@ -93,17 +94,23 @@ Attached items are represented as individual chips/cards within the composer tra
93
94
  - **Type Indicator:** Clearly distinguishes `Pin`, `Shot`, and `Image`.
94
95
  - **Removable:** Each item can be removed prior to submission.
95
96
 
96
- ### 4.4 Precision DOM Element Selection (Overlapping & Cascading Disambiguation)
97
+ ### 4.4 Environment-Adaptive DOM Element Selection (`smart` vs `verbose`)
97
98
 
98
- 1. User activates the Pin-shaped selector in the top-left corner of the chatbox or on the floating pin dock.
99
+ ContextDrop resolves `selection_mode` via `config.resolved_selection_mode` (`"smart"` when `Rails.env.production?` and `config.selection_mode == :auto`; `"verbose"` otherwise):
100
+
101
+ #### A. Production Smart Component Selector (`selection_mode = "smart"`)
102
+ 1. Hovering or peel-dragging over inner leaf nodes (`<span>`, `<svg>`, `<strong>`, icon wrappers) automatically promotes the target (`resolveSmartComponent`) to the nearest meaningful UI component (`button`, `link`, `input`/`field`, `card`, `banner`, `dialog`, `form`, `navigation`, `table row`, or bounded `section`).
103
+ 2. Displays a compact 1-line rounded hover pill showing only a plain-language human label (`describeSmartComponent` → `“Complete Order” button`)—omitting CSS selectors, pixel geometry, overlapping layer stacks, wheel-scrubbing interception, and `<kbd>` shortcut badges.
104
+ 3. Clicking or dropping immediately captures the component snapshot (`ElementReference` with `metadata.friendly_label`, `metadata.component_kind`, and `metadata.original_target_selector`), triggers an automatic privacy-redacted surrounding-context screenshot (`captureSurroundingContextScreenshot` with `smart_capture_padding = 84`, minimum `340×220px` clamped to viewport), merges both into a single `.cd-smart-card` in the compact `356px` composer, and exits selection mode immediately so the user can type quick feedback right away.
105
+
106
+ #### B. Staging, QA & Dev Verbose Layer Disambiguation (`selection_mode = "verbose"`)
107
+ 1. User activates the Pin-shaped selector in the top-left corner of the chatbox or drags the book corner.
99
108
  2. ContextDrop collapses the chatbox into the Compact Pinning Bar and enters selection mode (`crosshair` cursor with a cursor-following pushpin marker).
100
109
  3. Hovering over an element displays a primary bounding-box highlight overlay and a live HUD showing `<tag#selector>`, pixel dimensions, and layer depth (`1/5 layers · ↕ scroll`).
101
110
  4. **Disambiguating Overlapping & Cascading Elements:**
102
111
  - **Scroll-Wheel & `↑`/`↓` Arrow Key Depth Cycling:** Scrolling the mouse wheel (`wheel`) or pressing `ArrowUp`/`ArrowDown` (`[`/`]`) smoothly cycles through the candidate stack at that point (`target`, overlapping sibling elements via `document.elementsFromPoint`, direct children, and DOM ancestors) while rendering a dashed ghost outline around the original leaf element.
103
- - **Click-to-Pick Layer Popover:** Clicking a location with multiple cascading or overlapping layers anchors the floating pin and opens a floating Layer & Hierarchy Picker Popover listing all candidate layers at that coordinate with live hover preview on the page (`Shift+Click` or `Enter` pins immediately).
104
- - **Interactive DOM Breadcrumb Bar:** Both the Layer Popover and the Compact Pinning Bar render an interactive ancestor path (`section > div.card > button`) where hovering previews and clicking pins any ancestor or target element directly.
105
- 5. Selection mode remains active so additional elements can be pinned in one session.
106
- 6. Users can exit selection mode explicitly (`Escape` or returning to `Chat`).
112
+ - **Freeze & Pin Transient Menus (`⌥⇧P`):** Pressing `Alt+Shift+P` freezes hover-triggered menus/dropdowns at the current cursor coordinate for layer scrubbing and pinning.
113
+ 5. Selection mode remains active for multi-element pinning (`Space` or click) until exited (`Escape` or returning to `Chat`).
107
114
 
108
115
  **Host Non-Interference:** Click and pointer events in selection mode MUST be intercepted in the capture phase (`preventDefault`, `stopPropagation`, `stopImmediatePropagation`) so underlying application links, buttons, and forms are never triggered.
109
116
 
@@ -240,7 +247,10 @@ ContextDrop.configure do |config|
240
247
  # Environment-based master switch (disables widget, dashboard, and ingestion endpoints when false)
241
248
  config.enabled = ENV.fetch("CONTEXT_DROP_ENABLED", "false") == "true"
242
249
 
243
- # Widget position: :bottom_right, :bottom_left, :top_right, :top_left
250
+ # Host environment attribution (defaults automatically to Rails.env)
251
+ # config.environment = Rails.env
252
+
253
+ # Initial book-corner launcher position: :bottom_right, :bottom_left, :top_right, :top_left
244
254
  config.position = :bottom_right
245
255
 
246
256
  # Attachment storage backend
@@ -257,10 +267,12 @@ ContextDrop.configure do |config|
257
267
  config.allowed_content_types = %w[image/png image/jpeg image/webp image/gif]
258
268
  config.max_image_dimensions = [4096, 4096]
259
269
 
260
- # Widget feature flags
270
+ # Widget feature flags & environment-adaptive selector mode (:auto | :smart | :verbose)
261
271
  config.element_selection = true
272
+ config.selection_mode = :auto
262
273
  config.screenshot_capture = true
263
274
  config.element_capture_padding = 16
275
+ config.smart_capture_padding = 84
264
276
 
265
277
  # DOM selectors excluded from selection and redacted in screenshots
266
278
  config.excluded_selectors = [
@@ -284,10 +296,25 @@ ContextDrop.configure do |config|
284
296
  # Optional lifecycle callback invoked after feedback creation
285
297
  config.on_feedback_created = ->(feedback) { }
286
298
 
287
- # Model Context Protocol (MCP) server settings (Phase 2)
299
+ # Local development BYOK Agentic Sidebar (strictly active only in `development` on 127.0.0.1 / ::1)
300
+ # Disabled by default in v0.2.0; local development defaults to the verbose inspector/feedback modal
301
+ # to focus on external IDE agents connected via the unified MCP hub. Enable if desired:
302
+ config.enable_local_agent = ENV.fetch("CONTEXT_DROP_LOCAL_AGENT_ENABLED", "false") == "true"
303
+
304
+ # Unified Model Context Protocol (MCP) server settings
288
305
  config.mcp_enabled = ENV.fetch("CONTEXT_DROP_MCP_ENABLED", "false") == "true"
289
306
  config.mcp_api_key = ENV["CONTEXT_DROP_MCP_API_KEY"]
290
307
  config.authorize_mcp = nil
308
+ config.mcp_environments = {
309
+ staging: {
310
+ url: ENV["CONTEXT_DROP_STAGING_MCP_URL"],
311
+ api_key: ENV["CONTEXT_DROP_STAGING_MCP_API_KEY"]
312
+ },
313
+ production: {
314
+ url: ENV["CONTEXT_DROP_PRODUCTION_MCP_URL"],
315
+ api_key: ENV["CONTEXT_DROP_PRODUCTION_MCP_API_KEY"]
316
+ }
317
+ }
291
318
  end
292
319
  ```
293
320
 
@@ -376,6 +403,7 @@ end
376
403
  | `message` | `text` | `true` | `nil` | User-submitted feedback message |
377
404
  | `page_url` | `string` | `false` | — | Originating page URL |
378
405
  | `user_agent` | `string` | `true` | `nil` | Browser `User-Agent` |
406
+ | `environment` | `string` | `false` | `"development"` | Originating host environment (`Rails.env` / `config.resolved_environment`) |
379
407
  | `metadata` | `jsonb` / `json` | `false` | `{}` | Contextual metadata (`viewport`, `locale`, `timezone`, custom fields) |
380
408
  | `status` | `string` | `false` | `"new"` | Workflow status (`new`, `reviewed`, `resolved`, `dismissed`) |
381
409
  | `created_at` | `datetime` | `false` | — | Submission timestamp |
@@ -502,24 +530,44 @@ ContextDrop::Feedback.includes(:submitter, :element_references, attachments: { f
502
530
  | `GET` | `/context_drop/dashboard/feedbacks/:id` | Self-hosted Feedback Dashboard detail view | `enabled` + `authorize_dashboard` |
503
531
  | `PATCH` | `/context_drop/dashboard/feedbacks/:id` | Update feedback status from the dashboard | `enabled` + `authorize_dashboard` + CSRF |
504
532
  | `POST` | `/context_drop/mcp` | Model Context Protocol (MCP) JSON-RPC 2.0 endpoint | `mcp_enabled` + `mcp_api_key` / `authorize_mcp` |
533
+ | `GET` | `/context_drop/agent/status` | Local BYOK Agent status, providers, and masked key sources | `enabled` + `development` (never `production`) + Loopback + Same-Origin + `authorize_dashboard` |
534
+ | `POST` | `/context_drop/agent/keys` | Save BYOK provider API key into encrypted server vault | Same as above + CSRF |
535
+ | `DELETE` | `/context_drop/agent/keys/:provider` | Remove stored BYOK provider key from encrypted vault | Same as above + CSRF |
536
+ | `GET` | `/context_drop/agent/feedbacks` | List federated feedbacks across `local` + remote MCP environments | Same as `/agent/status` |
537
+ | `POST` | `/context_drop/agent/chat` | Run bounded agentic turn (read-only workspace tools + staged diffs) | Same as above + CSRF |
538
+ | `POST` | `/context_drop/agent/edits/:id/apply` | Apply human-approved staged unified diff to workspace file | Same as above + CSRF |
539
+ | `POST` | `/context_drop/agent/edits/:id/reject` | Reject and discard a staged file edit | Same as above + CSRF |
540
+ | `POST` | `/context_drop/agent/edits/:id/revert` | Revert a previously applied file edit to its original snapshot | Same as above + CSRF |
505
541
 
506
542
  ---
507
543
 
508
- ## 11. Model Context Protocol (MCP) Server for IDEs & Coding Agents (Phase 2)
544
+ ## 11. Unified Multi-Environment Model Context Protocol (MCP) Hub (`v0.2`)
509
545
 
510
- ContextDrop provides a built-in MCP server (`ContextDrop::MCP::Server`) supporting:
511
- 1. **Local `stdio` Transport (`bin/rails context_drop:mcp`):** Spawns locally from the developer's IDE (`Cursor`, `Claude Code`, `Antigravity`, `Windsurf`, `VS Code`) and reads `ContextDrop::Feedback`, `ContextDrop::Attachment`, and `ContextDrop::ElementReference` directly from the local Rails environment.
512
- 2. **Remote Streamable HTTP Transport (`POST /context_drop/mcp`):** Authenticated via `Authorization: Bearer <CONTEXT_DROP_MCP_API_KEY>` so developers can query staging/production feedback directly from their IDE.
546
+ ContextDrop provides a unified MCP server (`ContextDrop::MCP::Server` + `ContextDrop::MCP::EnvironmentRouter`) so developers register **one** MCP server in their IDE (`bin/rails context_drop:mcp`) to triage every environment:
547
+ 1. **Single Local `stdio` Hub (`bin/rails context_drop:mcp`):** Queries the local Rails database (`environment: "local"`) and transparently federates configured remote HTTP endpoints (`staging`, `production`, etc., configured via `config.mcp_environments`, `CONTEXT_DROP_REMOTE_ENVIRONMENTS`, or `CONTEXT_DROP_<ENV>_MCP_URL` + `CONTEXT_DROP_<ENV>_MCP_API_KEY`).
548
+ 2. **Remote Streamable HTTP Transport (`POST /context_drop/mcp`):** Authenticated via `Authorization: Bearer <CONTEXT_DROP_MCP_API_KEY>` (constant-time `secure_compare`) so the local MCP hub—or remote-only / Docker MCP clients—can securely query deployed environments over HTTPS.
513
549
 
514
550
  **Exposed MCP Tools:**
515
- - `list_feedbacks`: Filter by `status`, `page_url`, `query` (searches `message`, `selector`, `dom_path`, `text_content`), `limit`, `offset`.
516
- - `get_feedback`: Returns the full `Feedback`, all `ElementReference` records, and `Attachment` screenshots/images as base64 MCP `image` content blocks.
517
- - `get_feedback_attachment`: Returns a specific `ContextDrop::Attachment` binary as an MCP `image` content block.
518
- - `update_feedback_status`: Updates a feedback record's `status` (`new`, `reviewed`, `resolved`, `dismissed`).
551
+ - `list_environments`: Lists `local` (with current host `Rails.env`) plus all configured remote environments and reachability metadata.
552
+ - `list_feedbacks`: Filter by `environment` (`"all"`, `"local"`, `"staging"`, `"production"`, etc.), `status`, `page_url`, `query` (searches `message`, `selector`, `dom_path`, `text_content`), `limit`, `offset`. Returns chronologically merged results with `qualified_id` (`local:12`, `staging:42`, `production:98`) and non-blocking `environment_errors` if a remote endpoint is unreachable.
553
+ - `get_feedback`: Accepts either `<id>` + `environment` or a qualified ID (`"production:42"`), returning the full `Feedback`, all `ElementReference` records, and `Attachment` screenshots/images as base64 MCP `image` content blocks.
554
+ - `get_feedback_attachment`: Accepts `<attachment_id>` + `environment` or `"staging:15"`, returning a specific `ContextDrop::Attachment` binary as an MCP `image` content block.
555
+ - `update_feedback_status`: Updates a local or remote feedback record's `status` (`new`, `reviewed`, `resolved`, `dismissed`).
556
+
557
+ ---
558
+
559
+ ## 12. Local BYOK Agentic Sidebar & Defense-in-Depth Safety (`v0.2`)
560
+
561
+ When the host Rails application runs locally in `development`, ContextDrop transforms the feedback surface into a docked Antigravity / VS Code-style **Agentic Coding Sidebar** (`ContextDrop::Agent::Orchestrator`) governed by five strict safety walls:
562
+ 1. **Environment & Loopback Hard Lock:** `/context_drop/agent/*` returns `404 Not Found` whenever `Rails.env.production?` is true, when `!config.local_agent_allowed?`, when `remote_addr` / `remote_ip` / `X-Forwarded-For` is not strict loopback (`127.0.0.1` / `::1`), when `Host` fails loopback DNS-rebinding checks, or when `Origin` / `Sec-Fetch-Site` is cross-origin. All mutations also require Rails CSRF verification and `config.authorize_dashboard`.
563
+ 2. **Server-Side Encrypted BYOK Vault:** Supports `Anthropic`, `Google Gemini`, `OpenAI`, and `Custom OpenAI-Compatible` endpoints. Keys are auto-detected from local server `ENV` (`ANTHROPIC_API_KEY`, `GEMINI_API_KEY`/`GOOGLE_API_KEY`, `OPENAI_API_KEY`, `CONTEXT_DROP_LLM_API_KEY`) or stored server-side encrypted (`AES-256-GCM`, file mode `0600`) in gitignored `tmp/context_drop_byok.enc`. Raw API keys are **never** stored in browser `localStorage`, `sessionStorage`, cookies, or DOM attributes, and `/agent/status` returns only masked tails (`••••••••abcd`).
564
+ 3. **Workspace Root Jail & Secret Denylist (`WorkspaceSandbox`):** Agent workspace tools (`list_workspace_files`, `search_workspace`, `read_workspace_file`, `propose_file_edit`) resolve paths through `File.realpath` strictly inside `Rails.root` and block `.env*`, `config/master.key`, `config/credentials*`, `*.pem`, `*.key`, `tmp/context_drop_byok*`, `.git/config`, and `.git/hooks/*`.
565
+ 4. **No Arbitrary Shell Execution:** No `bash`, `sh`, `system`, or `Open3` tool is exposed to LLM tool calls, eliminating prompt-injection command execution from untrusted user-submitted feedback messages.
566
+ 5. **Human-in-the-Loop Diff Approval:** `propose_file_edit` stages edits in memory and renders an inline unified diff card (`+N / -N`) in the sidebar. Files on disk are modified only when the developer explicitly clicks **Apply Change** (verified via SHA-256 pre-image digest check to prevent clobbering concurrent edits), with 1-click **Revert** support.
519
567
 
520
568
  ---
521
569
 
522
- ## 12. MVP Acceptance Criteria
570
+ ## 13. Acceptance Criteria
523
571
 
524
572
  1. Generated and structured as a mountable Rails Engine (`isolate_namespace ContextDrop`) with engine-owned migrations (`context_drop_feedbacks`, `context_drop_attachments`, `context_drop_element_references`).
525
573
  2. `bin/rails generate context_drop:install` installs the initializer, mounts routes, and copies migrations (`rails context_drop:install:migrations`).