context_drop 0.1.3 → 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.
- checksums.yaml +4 -4
- data/README.md +218 -49
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +5227 -652
- data/app/controllers/context_drop/agent_controller.rb +170 -0
- data/app/controllers/context_drop/configs_controller.rb +2 -1
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +62 -2
- data/app/controllers/context_drop/feedbacks_controller.rb +13 -3
- data/app/controllers/context_drop/mcp_controller.rb +2 -1
- data/app/helpers/context_drop/dashboard_helper.rb +52 -0
- data/app/helpers/context_drop/widget_helper.rb +11 -1
- data/app/javascript/context_drop/__tests__/widget.test.ts +731 -92
- data/app/javascript/context_drop/api-client.ts +130 -11
- data/app/javascript/context_drop/element-picker.ts +247 -30
- data/app/javascript/context_drop/icons.ts +24 -0
- data/app/javascript/context_drop/markdown.ts +146 -0
- data/app/javascript/context_drop/sanitizer.ts +413 -2
- data/app/javascript/context_drop/screenshot.ts +102 -8
- data/app/javascript/context_drop/styles.ts +1528 -252
- data/app/javascript/context_drop/types.ts +147 -0
- data/app/javascript/context_drop/widget.ts +2629 -288
- data/app/models/context_drop/feedback.rb +34 -5
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +166 -60
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +178 -47
- data/app/views/layouts/context_drop/application.html.erb +416 -70
- data/config/routes.rb +11 -0
- data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
- data/lib/context_drop/agent/key_store.rb +290 -0
- data/lib/context_drop/agent/llm_client.rb +413 -0
- data/lib/context_drop/agent/orchestrator.rb +314 -0
- data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
- data/lib/context_drop/configuration.rb +216 -3
- data/lib/context_drop/mcp/dispatcher.rb +71 -29
- data/lib/context_drop/mcp/environment_router.rb +115 -0
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +87 -8
- data/lib/context_drop/mcp/remote_client.rb +120 -0
- data/lib/context_drop/mcp/server.rb +9 -2
- data/lib/context_drop/mcp/tools/get_feedback.rb +50 -4
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +26 -4
- data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +174 -22
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +45 -4
- data/lib/context_drop/version.rb +1 -1
- data/lib/context_drop.rb +8 -2
- data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
- metadata +13 -2
data/SPEC.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# ContextDrop — Technical Specification
|
|
2
2
|
|
|
3
|
-
**Status:**
|
|
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
|
|
6
|
-
**License:** MIT
|
|
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
|
|
71
|
+
### 4.1 Book-Corner Fold Launcher & Peel-to-Pin Morph (`v0.2`)
|
|
72
72
|
|
|
73
|
-
ContextDrop
|
|
74
|
-
- **
|
|
75
|
-
- **
|
|
76
|
-
- **
|
|
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
|
|
97
|
+
### 4.4 Environment-Adaptive DOM Element Selection (`smart` vs `verbose`)
|
|
97
98
|
|
|
98
|
-
|
|
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
|
-
- **
|
|
104
|
-
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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)
|
|
544
|
+
## 11. Unified Multi-Environment Model Context Protocol (MCP) Hub (`v0.2`)
|
|
509
545
|
|
|
510
|
-
ContextDrop provides a
|
|
511
|
-
1. **Local `stdio`
|
|
512
|
-
2. **Remote Streamable HTTP Transport (`POST /context_drop/mcp`):** Authenticated via `Authorization: Bearer <CONTEXT_DROP_MCP_API_KEY>` so
|
|
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
|
-
- `
|
|
516
|
-
- `
|
|
517
|
-
- `
|
|
518
|
-
- `
|
|
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
|
-
##
|
|
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`).
|