context_drop 0.2.0 → 0.3.1
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 +149 -12
- data/Rakefile +110 -1
- data/app/assets/javascripts/context_drop/context_drop.js +1759 -105
- data/app/controllers/context_drop/application_controller.rb +52 -3
- data/app/controllers/context_drop/configs_controller.rb +10 -1
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +99 -14
- data/app/controllers/context_drop/feedbacks_controller.rb +536 -17
- data/app/helpers/context_drop/dashboard_helper.rb +4 -0
- data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +355 -1
- data/app/javascript/context_drop/api-client.ts +343 -22
- data/app/javascript/context_drop/element-picker.ts +1 -1
- data/app/javascript/context_drop/icons.ts +6 -0
- data/app/javascript/context_drop/screenshot.ts +1 -1
- data/app/javascript/context_drop/styles.ts +311 -0
- data/app/javascript/context_drop/types.ts +141 -6
- data/app/javascript/context_drop/widget.ts +1072 -35
- data/app/models/context_drop/attachment.rb +5 -0
- data/app/models/context_drop/comment.rb +50 -0
- data/app/models/context_drop/feedback.rb +81 -11
- data/app/services/context_drop/ownership_token.rb +114 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +14 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +169 -2
- data/app/views/layouts/context_drop/application.html.erb +131 -7
- data/config/routes.rb +16 -1
- data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
- data/db/migrate/20261116000001_create_context_drop_comments_and_update_statuses.rb +44 -0
- data/lib/context_drop/agent/orchestrator.rb +1 -1
- data/lib/context_drop/configuration.rb +26 -0
- data/lib/context_drop/mcp/dispatcher.rb +2 -1
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +5 -3
- data/lib/context_drop/mcp/server.rb +1 -0
- data/lib/context_drop/mcp/tools/add_feedback_comment.rb +139 -0
- data/lib/context_drop/mcp/tools/get_feedback.rb +45 -6
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +3 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +23 -3
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +5 -3
- data/lib/context_drop/version.rb +1 -1
- metadata +7 -2
|
@@ -26,17 +26,25 @@
|
|
|
26
26
|
--cd-new-border: #bfdbfe;
|
|
27
27
|
--cd-new-text: #1d4ed8;
|
|
28
28
|
|
|
29
|
-
--cd-
|
|
30
|
-
--cd-
|
|
31
|
-
--cd-
|
|
29
|
+
--cd-updated-bg: #fffbeb;
|
|
30
|
+
--cd-updated-border: #fde68a;
|
|
31
|
+
--cd-updated-text: #b45309;
|
|
32
32
|
|
|
33
|
-
--cd-
|
|
34
|
-
--cd-
|
|
35
|
-
--cd-
|
|
33
|
+
--cd-fixed-bg: #eef2ff;
|
|
34
|
+
--cd-fixed-border: #c7d2fe;
|
|
35
|
+
--cd-fixed-text: #4338ca;
|
|
36
|
+
|
|
37
|
+
--cd-reviewed-bg: #f0fdf4;
|
|
38
|
+
--cd-reviewed-border: #bbf7d0;
|
|
39
|
+
--cd-reviewed-text: #15803d;
|
|
36
40
|
|
|
37
41
|
--cd-dismissed-bg: #f8fafc;
|
|
38
42
|
--cd-dismissed-border: #e2e8f0;
|
|
39
43
|
--cd-dismissed-text: #64748b;
|
|
44
|
+
|
|
45
|
+
--cd-deleted-bg: #fef2f2;
|
|
46
|
+
--cd-deleted-border: #fecaca;
|
|
47
|
+
--cd-deleted-text: #b91c1c;
|
|
40
48
|
}
|
|
41
49
|
* { box-sizing: border-box; }
|
|
42
50
|
body {
|
|
@@ -369,9 +377,125 @@
|
|
|
369
377
|
letter-spacing: 0.01em;
|
|
370
378
|
}
|
|
371
379
|
.cd-badge-new { background: var(--cd-new-bg); border-color: var(--cd-new-border); color: var(--cd-new-text); }
|
|
380
|
+
.cd-badge-updated { background: var(--cd-updated-bg); border-color: var(--cd-updated-border); color: var(--cd-updated-text); }
|
|
381
|
+
.cd-badge-fixed { background: var(--cd-fixed-bg); border-color: var(--cd-fixed-border); color: var(--cd-fixed-text); }
|
|
372
382
|
.cd-badge-reviewed { background: var(--cd-reviewed-bg); border-color: var(--cd-reviewed-border); color: var(--cd-reviewed-text); }
|
|
373
|
-
.cd-badge-resolved { background: var(--cd-resolved-bg); border-color: var(--cd-resolved-border); color: var(--cd-resolved-text); }
|
|
374
383
|
.cd-badge-dismissed { background: var(--cd-dismissed-bg); border-color: var(--cd-dismissed-border); color: var(--cd-dismissed-text); }
|
|
384
|
+
.cd-badge-deleted { background: var(--cd-deleted-bg); border-color: var(--cd-deleted-border); color: var(--cd-deleted-text); }
|
|
385
|
+
|
|
386
|
+
/* Comments Thread & Composer */
|
|
387
|
+
.cd-comment-list {
|
|
388
|
+
display: flex;
|
|
389
|
+
flex-direction: column;
|
|
390
|
+
gap: 0.75rem;
|
|
391
|
+
margin-bottom: 1.25rem;
|
|
392
|
+
}
|
|
393
|
+
.cd-comment-item {
|
|
394
|
+
border: 1px solid var(--cd-border-subtle);
|
|
395
|
+
border-radius: 0.5rem;
|
|
396
|
+
padding: 0.875rem 1rem;
|
|
397
|
+
background: var(--cd-surface-recessed);
|
|
398
|
+
}
|
|
399
|
+
.cd-comment-header {
|
|
400
|
+
display: flex;
|
|
401
|
+
align-items: center;
|
|
402
|
+
justify-content: space-between;
|
|
403
|
+
gap: 0.5rem;
|
|
404
|
+
margin-bottom: 0.45rem;
|
|
405
|
+
font-size: 0.75rem;
|
|
406
|
+
}
|
|
407
|
+
.cd-comment-author {
|
|
408
|
+
font-weight: 600;
|
|
409
|
+
color: var(--cd-text);
|
|
410
|
+
display: inline-flex;
|
|
411
|
+
align-items: center;
|
|
412
|
+
gap: 0.35rem;
|
|
413
|
+
}
|
|
414
|
+
.cd-comment-time {
|
|
415
|
+
font-family: var(--cd-font-mono);
|
|
416
|
+
font-size: 0.6875rem;
|
|
417
|
+
color: var(--cd-muted);
|
|
418
|
+
font-variant-numeric: tabular-nums;
|
|
419
|
+
}
|
|
420
|
+
.cd-comment-body {
|
|
421
|
+
font-size: 0.875rem;
|
|
422
|
+
line-height: 1.55;
|
|
423
|
+
color: var(--cd-text);
|
|
424
|
+
white-space: pre-wrap;
|
|
425
|
+
margin: 0;
|
|
426
|
+
}
|
|
427
|
+
.cd-comment-images {
|
|
428
|
+
display: flex;
|
|
429
|
+
flex-wrap: wrap;
|
|
430
|
+
gap: 0.625rem;
|
|
431
|
+
margin-top: 0.625rem;
|
|
432
|
+
}
|
|
433
|
+
.cd-comment-thumb {
|
|
434
|
+
max-width: 220px;
|
|
435
|
+
max-height: 150px;
|
|
436
|
+
object-fit: cover;
|
|
437
|
+
border-radius: 0.375rem;
|
|
438
|
+
border: 1px solid var(--cd-border);
|
|
439
|
+
display: block;
|
|
440
|
+
background: var(--cd-surface);
|
|
441
|
+
}
|
|
442
|
+
.cd-comment-form {
|
|
443
|
+
border: 1px solid var(--cd-border);
|
|
444
|
+
border-radius: 0.5rem;
|
|
445
|
+
background: var(--cd-surface);
|
|
446
|
+
padding: 0.75rem;
|
|
447
|
+
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
448
|
+
}
|
|
449
|
+
.cd-comment-form:focus-within {
|
|
450
|
+
border-color: var(--cd-primary);
|
|
451
|
+
box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.08);
|
|
452
|
+
}
|
|
453
|
+
.cd-comment-textarea {
|
|
454
|
+
width: 100%;
|
|
455
|
+
min-height: 76px;
|
|
456
|
+
border: none;
|
|
457
|
+
outline: none;
|
|
458
|
+
resize: vertical;
|
|
459
|
+
font-family: inherit;
|
|
460
|
+
font-size: 0.875rem;
|
|
461
|
+
line-height: 1.5;
|
|
462
|
+
color: var(--cd-text);
|
|
463
|
+
background: transparent;
|
|
464
|
+
padding: 0.125rem 0.25rem;
|
|
465
|
+
}
|
|
466
|
+
.cd-comment-previews {
|
|
467
|
+
display: flex;
|
|
468
|
+
flex-wrap: wrap;
|
|
469
|
+
gap: 0.5rem;
|
|
470
|
+
margin-top: 0.5rem;
|
|
471
|
+
}
|
|
472
|
+
.cd-comment-preview-chip {
|
|
473
|
+
position: relative;
|
|
474
|
+
display: inline-flex;
|
|
475
|
+
align-items: center;
|
|
476
|
+
gap: 0.375rem;
|
|
477
|
+
padding: 0.25rem 0.5rem 0.25rem 0.25rem;
|
|
478
|
+
border: 1px solid var(--cd-border);
|
|
479
|
+
border-radius: 0.375rem;
|
|
480
|
+
background: var(--cd-surface-recessed);
|
|
481
|
+
font-size: 0.75rem;
|
|
482
|
+
color: var(--cd-text-secondary);
|
|
483
|
+
}
|
|
484
|
+
.cd-comment-preview-chip img {
|
|
485
|
+
width: 28px;
|
|
486
|
+
height: 28px;
|
|
487
|
+
object-fit: cover;
|
|
488
|
+
border-radius: 0.25rem;
|
|
489
|
+
}
|
|
490
|
+
.cd-comment-toolbar {
|
|
491
|
+
display: flex;
|
|
492
|
+
align-items: center;
|
|
493
|
+
justify-content: space-between;
|
|
494
|
+
gap: 0.75rem;
|
|
495
|
+
margin-top: 0.625rem;
|
|
496
|
+
padding-top: 0.625rem;
|
|
497
|
+
border-top: 1px solid var(--cd-border-subtle);
|
|
498
|
+
}
|
|
375
499
|
|
|
376
500
|
.cd-mono {
|
|
377
501
|
font-family: var(--cd-font-mono);
|
data/config/routes.rb
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
ContextDrop::Engine.routes.draw do
|
|
4
|
+
match "config", to: "configs#cors_preflight", via: :options
|
|
5
|
+
match "attachments", to: "configs#cors_preflight", via: :options
|
|
6
|
+
match "feedback", to: "configs#cors_preflight", via: :options
|
|
7
|
+
match "feedback/:id", to: "configs#cors_preflight", via: :options
|
|
8
|
+
match "feedback/:id/comments", to: "configs#cors_preflight", via: :options
|
|
9
|
+
match "feedback/:feedback_id/attachments/:id", to: "configs#cors_preflight", via: :options
|
|
10
|
+
match "health", to: "configs#cors_preflight", via: :options
|
|
11
|
+
|
|
4
12
|
get "config", to: "configs#show"
|
|
5
13
|
get "assets/context_drop.js", to: "configs#widget_bundle"
|
|
6
14
|
post "attachments", to: "attachments#create"
|
|
15
|
+
get "feedback", to: "feedbacks#index"
|
|
7
16
|
post "feedback", to: "feedbacks#create"
|
|
17
|
+
match "feedback/:id", to: "feedbacks#update", via: %i[patch put]
|
|
18
|
+
delete "feedback/:id", to: "feedbacks#destroy"
|
|
19
|
+
post "feedback/:id/comments", to: "feedbacks#create_comment"
|
|
20
|
+
get "feedback/:feedback_id/attachments/:id", to: "feedbacks#attachment"
|
|
8
21
|
get "health", to: "health#show"
|
|
9
22
|
post "mcp", to: "mcp#create"
|
|
10
23
|
|
|
@@ -21,7 +34,9 @@ ContextDrop::Engine.routes.draw do
|
|
|
21
34
|
|
|
22
35
|
namespace :dashboard do
|
|
23
36
|
root to: "feedbacks#index"
|
|
24
|
-
resources :feedbacks, only: %i[index show update]
|
|
37
|
+
resources :feedbacks, only: %i[index show update] do
|
|
38
|
+
post :comments, on: :member, action: :create_comment
|
|
39
|
+
end
|
|
25
40
|
end
|
|
26
41
|
|
|
27
42
|
root to: "dashboard/feedbacks#index"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddDeletedAtToContextDropFeedbacks < ActiveRecord::Migration[7.1]
|
|
4
|
+
def change
|
|
5
|
+
return if column_exists?(:context_drop_feedbacks, :deleted_at)
|
|
6
|
+
|
|
7
|
+
add_column :context_drop_feedbacks, :deleted_at, :datetime, null: true
|
|
8
|
+
add_index :context_drop_feedbacks, :deleted_at
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateContextDropCommentsAndUpdateStatuses < ActiveRecord::Migration[7.1]
|
|
4
|
+
def up
|
|
5
|
+
json_type = connection.adapter_name.downcase.include?("postgres") ? :jsonb : :json
|
|
6
|
+
|
|
7
|
+
create_table :context_drop_comments do |t|
|
|
8
|
+
t.references :feedback,
|
|
9
|
+
null: false,
|
|
10
|
+
foreign_key: { to_table: :context_drop_feedbacks, on_delete: :cascade },
|
|
11
|
+
index: { name: "idx_context_drop_comments_on_feedback_id" }
|
|
12
|
+
t.string :author_type, null: true
|
|
13
|
+
t.string :author_id, null: true
|
|
14
|
+
t.string :author_label, null: true
|
|
15
|
+
t.text :body, null: true
|
|
16
|
+
t.public_send(json_type, :metadata, null: false, default: {})
|
|
17
|
+
|
|
18
|
+
t.timestamps
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
add_reference :context_drop_attachments,
|
|
22
|
+
:comment,
|
|
23
|
+
null: true,
|
|
24
|
+
foreign_key: { to_table: :context_drop_comments, on_delete: :cascade },
|
|
25
|
+
index: { name: "idx_context_drop_attachments_on_comment_id" }
|
|
26
|
+
|
|
27
|
+
execute <<~SQL.squish
|
|
28
|
+
UPDATE context_drop_feedbacks
|
|
29
|
+
SET status = 'fixed'
|
|
30
|
+
WHERE status = 'resolved'
|
|
31
|
+
SQL
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def down
|
|
35
|
+
execute <<~SQL.squish
|
|
36
|
+
UPDATE context_drop_feedbacks
|
|
37
|
+
SET status = 'resolved'
|
|
38
|
+
WHERE status = 'fixed'
|
|
39
|
+
SQL
|
|
40
|
+
|
|
41
|
+
remove_reference :context_drop_attachments, :comment, foreign_key: { to_table: :context_drop_comments }
|
|
42
|
+
drop_table :context_drop_comments
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -53,7 +53,7 @@ module ContextDrop
|
|
|
53
53
|
type: "object",
|
|
54
54
|
properties: {
|
|
55
55
|
environment: { type: "string", description: "Environment filter: 'all' (default), 'local', 'staging', 'production', etc." },
|
|
56
|
-
status: { type: "string", enum: %w[new reviewed
|
|
56
|
+
status: { type: "string", enum: %w[new updated fixed reviewed dismissed], description: "Workflow status filter." },
|
|
57
57
|
page_url: { type: "string", description: "Originating page URL substring filter." },
|
|
58
58
|
query: { type: "string", description: "Free-text search across message and DOM selectors." },
|
|
59
59
|
limit: { type: "integer", description: "Max items (default 15)." }
|
|
@@ -39,11 +39,15 @@ module ContextDrop
|
|
|
39
39
|
:element_capture_padding,
|
|
40
40
|
:smart_capture_padding,
|
|
41
41
|
:excluded_selectors,
|
|
42
|
+
:allowed_origins,
|
|
42
43
|
:current_submitter,
|
|
43
44
|
:authorize_submission,
|
|
44
45
|
:authorize_dashboard,
|
|
45
46
|
:rate_limit,
|
|
47
|
+
:ownership_secret,
|
|
46
48
|
:on_feedback_created,
|
|
49
|
+
:on_feedback_updated,
|
|
50
|
+
:on_feedback_deleted,
|
|
47
51
|
:mcp_enabled,
|
|
48
52
|
:mcp_api_key,
|
|
49
53
|
:authorize_mcp,
|
|
@@ -76,6 +80,7 @@ module ContextDrop
|
|
|
76
80
|
@smart_capture_padding = 84
|
|
77
81
|
|
|
78
82
|
@excluded_selectors = MANDATORY_EXCLUDED_SELECTORS.dup
|
|
83
|
+
@allowed_origins = []
|
|
79
84
|
|
|
80
85
|
@current_submitter = lambda do |controller|
|
|
81
86
|
controller.respond_to?(:current_user, true) ? controller.send(:current_user) : nil
|
|
@@ -91,7 +96,10 @@ module ContextDrop
|
|
|
91
96
|
end
|
|
92
97
|
|
|
93
98
|
@rate_limit = { max_requests: 20, period: 3600 }
|
|
99
|
+
@ownership_secret = nil
|
|
94
100
|
@on_feedback_created = ->(_feedback) {}
|
|
101
|
+
@on_feedback_updated = ->(_feedback) {}
|
|
102
|
+
@on_feedback_deleted = ->(_feedback) {}
|
|
95
103
|
|
|
96
104
|
@mcp_enabled = false
|
|
97
105
|
@mcp_api_key = nil
|
|
@@ -277,6 +285,24 @@ module ContextDrop
|
|
|
277
285
|
(MANDATORY_EXCLUDED_SELECTORS + Array(@excluded_selectors).map(&:to_s)).uniq
|
|
278
286
|
end
|
|
279
287
|
|
|
288
|
+
def origin_allowed?(origin_header)
|
|
289
|
+
origin = origin_header.to_s.strip
|
|
290
|
+
return false if origin.empty?
|
|
291
|
+
|
|
292
|
+
normalized_origin = origin.chomp("/")
|
|
293
|
+
Array(@allowed_origins).any? do |rule|
|
|
294
|
+
case rule
|
|
295
|
+
when Regexp
|
|
296
|
+
rule.match?(normalized_origin)
|
|
297
|
+
when String
|
|
298
|
+
normalized_rule = rule.strip.chomp("/")
|
|
299
|
+
!normalized_rule.empty? && normalized_rule != "*" && normalized_rule.casecmp?(normalized_origin)
|
|
300
|
+
else
|
|
301
|
+
false
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
280
306
|
def resolve_submitter(controller)
|
|
281
307
|
return nil unless @current_submitter.respond_to?(:call)
|
|
282
308
|
|
|
@@ -12,7 +12,8 @@ module ContextDrop
|
|
|
12
12
|
"list_feedbacks" => ContextDrop::MCP::Tools::ListFeedbacks,
|
|
13
13
|
"get_feedback" => ContextDrop::MCP::Tools::GetFeedback,
|
|
14
14
|
"get_feedback_attachment" => ContextDrop::MCP::Tools::GetFeedbackAttachment,
|
|
15
|
-
"update_feedback_status" => ContextDrop::MCP::Tools::UpdateFeedbackStatus
|
|
15
|
+
"update_feedback_status" => ContextDrop::MCP::Tools::UpdateFeedbackStatus,
|
|
16
|
+
"add_feedback_comment" => ContextDrop::MCP::Tools::AddFeedbackComment
|
|
16
17
|
}.freeze
|
|
17
18
|
|
|
18
19
|
PROMPTS = {
|
|
@@ -38,7 +38,9 @@ module ContextDrop
|
|
|
38
38
|
feedback = ContextDrop::Feedback
|
|
39
39
|
.includes(:submitter, :element_references, :attachments)
|
|
40
40
|
.find_by(id: feedback_id)
|
|
41
|
-
|
|
41
|
+
if !feedback || (feedback.respond_to?(:deleted?) && feedback.deleted?)
|
|
42
|
+
raise ContextDrop::Error, "Feedback ##{feedback_id} not found"
|
|
43
|
+
end
|
|
42
44
|
|
|
43
45
|
env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
|
|
44
46
|
qualified = ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id)
|
|
@@ -75,7 +77,7 @@ module ContextDrop
|
|
|
75
77
|
1. Locate the Rails route and controller action corresponding to `#{feedback.page_url}` in `config/routes.rb` and `app/controllers/`.
|
|
76
78
|
2. Search the view templates (`app/views/`, ViewComponents, or frontend components) for the attached DOM selectors (`#{feedback.element_references.map(&:selector).join(', ')}`) and structural DOM paths (`#{feedback.element_references.map(&:dom_path).compact.join(', ')}`).
|
|
77
79
|
3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
|
|
78
|
-
4. Propose and verify a fix, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "
|
|
80
|
+
4. Propose and verify a fix, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "fixed"`) once complete.
|
|
79
81
|
PROMPT
|
|
80
82
|
|
|
81
83
|
message_content = [{ type: "text", text: instructions }]
|
|
@@ -140,7 +142,7 @@ module ContextDrop
|
|
|
140
142
|
1. Locate the Rails route and controller action corresponding to `#{fb['page_url']}` in `config/routes.rb` and `app/controllers/`.
|
|
141
143
|
2. Search the view templates (`app/views/`, ViewComponents, or frontend components) for the attached DOM selectors (`#{els.map { |e| e['selector'] }.join(', ')}`).
|
|
142
144
|
3. Inspect any attached screenshots (`get_feedback` with `id: "#{qualified}"`) to verify the visual layout issue.
|
|
143
|
-
4. Propose and verify a fix locally, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "
|
|
145
|
+
4. Propose and verify a fix locally, then call `update_feedback_status` (`id: "#{qualified}"`, `status: "fixed"`) once complete.
|
|
144
146
|
PROMPT
|
|
145
147
|
|
|
146
148
|
image_blocks = Array(tool_res[:content]).select { |b| b.is_a?(Hash) && b[:type].to_s == "image" }
|
|
@@ -7,6 +7,7 @@ require_relative "tools/list_feedbacks"
|
|
|
7
7
|
require_relative "tools/get_feedback"
|
|
8
8
|
require_relative "tools/get_feedback_attachment"
|
|
9
9
|
require_relative "tools/update_feedback_status"
|
|
10
|
+
require_relative "tools/add_feedback_comment"
|
|
10
11
|
require_relative "prompts/investigate_feedback"
|
|
11
12
|
require_relative "dispatcher"
|
|
12
13
|
require_relative "stdio_runner"
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
module MCP
|
|
5
|
+
module Tools
|
|
6
|
+
class AddFeedbackComment
|
|
7
|
+
DEFINITION = {
|
|
8
|
+
name: "add_feedback_comment",
|
|
9
|
+
description: "Add a follow-up comment to a ContextDrop feedback record (optionally transitioning its status, defaulting to 'updated' unless specified).",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
required: %w[id body],
|
|
13
|
+
properties: {
|
|
14
|
+
id: {
|
|
15
|
+
type: %w[integer string],
|
|
16
|
+
description: "The ID of the ContextDrop::Feedback record, or a qualified '<environment>:<id>' string."
|
|
17
|
+
},
|
|
18
|
+
environment: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Optional environment name ('local', 'staging', 'production', etc.)."
|
|
21
|
+
},
|
|
22
|
+
body: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: "Comment text."
|
|
25
|
+
},
|
|
26
|
+
author_label: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Optional display label for the comment author (defaults to 'AI Agent')."
|
|
29
|
+
},
|
|
30
|
+
status: {
|
|
31
|
+
type: "string",
|
|
32
|
+
enum: %w[new updated fixed reviewed dismissed],
|
|
33
|
+
description: "Optional target workflow status (defaults to 'updated')."
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
def self.call(args = {})
|
|
40
|
+
params = args.is_a?(Hash) ? args.transform_keys(&:to_s) : {}
|
|
41
|
+
raw_id = params["id"] || params["feedback_id"]
|
|
42
|
+
body = params["body"].to_s.strip
|
|
43
|
+
author_label = params["author_label"].to_s.strip.presence || "AI Agent"
|
|
44
|
+
next_status = params["status"].to_s.strip.presence || "updated"
|
|
45
|
+
|
|
46
|
+
return error_result("Missing required parameter: id") if raw_id.nil? || raw_id.to_s.strip.empty?
|
|
47
|
+
return error_result("Missing required parameter: body") if body.empty?
|
|
48
|
+
|
|
49
|
+
unless ContextDrop::Feedback::STATUSES.include?(next_status)
|
|
50
|
+
return error_result(
|
|
51
|
+
"Invalid status '#{next_status}'. Must be one of: #{ContextDrop::Feedback::STATUSES.join(', ')}"
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
target_env, feedback_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_id, params["environment"])
|
|
56
|
+
|
|
57
|
+
unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
|
|
58
|
+
remote_cfg = ContextDrop::MCP::EnvironmentRouter.remote_config_for(target_env)
|
|
59
|
+
return error_result("Unknown remote environment '#{target_env}'") unless remote_cfg
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
remote_args = {
|
|
63
|
+
"id" => feedback_id,
|
|
64
|
+
"body" => body,
|
|
65
|
+
"author_label" => author_label,
|
|
66
|
+
"status" => next_status
|
|
67
|
+
}
|
|
68
|
+
res = ContextDrop::MCP::RemoteClient.call_tool(target_env, remote_cfg, "add_feedback_comment", remote_args)
|
|
69
|
+
return res if res[:isError]
|
|
70
|
+
|
|
71
|
+
updated_blocks = Array(res[:content]).map do |block|
|
|
72
|
+
if block.is_a?(Hash) && block[:type].to_s == "text"
|
|
73
|
+
begin
|
|
74
|
+
parsed = JSON.parse(block[:text].to_s)
|
|
75
|
+
if parsed.is_a?(Hash)
|
|
76
|
+
parsed["environment"] = target_env
|
|
77
|
+
parsed["qualified_id"] = ContextDrop::MCP::EnvironmentRouter.qualify_id(target_env, parsed["feedback_id"] || feedback_id)
|
|
78
|
+
next block.merge(text: JSON.pretty_generate(parsed))
|
|
79
|
+
end
|
|
80
|
+
rescue JSON::ParserError
|
|
81
|
+
# Keep original block
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
block
|
|
85
|
+
end
|
|
86
|
+
return { content: updated_blocks, isError: false }
|
|
87
|
+
rescue ContextDrop::MCP::RemoteClient::RemoteError => e
|
|
88
|
+
return error_result(e.message)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
feedback = ContextDrop::Feedback.find_by(id: feedback_id)
|
|
93
|
+
if !feedback || (feedback.respond_to?(:deleted?) && feedback.deleted?)
|
|
94
|
+
return error_result("Feedback ##{feedback_id} not found")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
comment = nil
|
|
98
|
+
ContextDrop::Feedback.transaction do
|
|
99
|
+
comment = feedback.comments.create!(
|
|
100
|
+
author_type: "Agent",
|
|
101
|
+
author_label: author_label,
|
|
102
|
+
body: body,
|
|
103
|
+
metadata: {}
|
|
104
|
+
)
|
|
105
|
+
feedback.update!(status: next_status)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
env_name = ContextDrop::MCP::EnvironmentRouter.record_environment(feedback)
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: JSON.pretty_generate(
|
|
115
|
+
id: comment.id,
|
|
116
|
+
feedback_id: feedback.id,
|
|
117
|
+
qualified_id: ContextDrop::MCP::EnvironmentRouter.qualify_id(env_name, feedback.id),
|
|
118
|
+
environment: env_name,
|
|
119
|
+
author_label: comment.display_author_label,
|
|
120
|
+
body: comment.body,
|
|
121
|
+
status: feedback.status,
|
|
122
|
+
created_at: comment.created_at&.iso8601
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
isError: false
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def self.error_result(msg)
|
|
131
|
+
{
|
|
132
|
+
content: [{ type: "text", text: JSON.generate(error: msg) }],
|
|
133
|
+
isError: true
|
|
134
|
+
}
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -24,6 +24,10 @@ module ContextDrop
|
|
|
24
24
|
include_images: {
|
|
25
25
|
type: "boolean",
|
|
26
26
|
description: "When true (default), includes attached screenshots and images as base64 MCP image content blocks."
|
|
27
|
+
},
|
|
28
|
+
include_deleted: {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
description: "When true, allows retrieving a soft-deleted feedback record. Defaults to false."
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
}
|
|
@@ -35,6 +39,7 @@ module ContextDrop
|
|
|
35
39
|
return error_result("Missing required parameter: id") if raw_id.nil? || raw_id.to_s.strip.empty?
|
|
36
40
|
|
|
37
41
|
include_images = params.key?("include_images") ? !!params["include_images"] : true
|
|
42
|
+
include_deleted = params["include_deleted"] == true || %w[true 1 yes].include?(params["include_deleted"].to_s.strip.downcase)
|
|
38
43
|
target_env, feedback_id = ContextDrop::MCP::EnvironmentRouter.parse_target(raw_id, params["environment"])
|
|
39
44
|
|
|
40
45
|
unless ContextDrop::MCP::EnvironmentRouter.local_target?(target_env)
|
|
@@ -43,14 +48,16 @@ module ContextDrop
|
|
|
43
48
|
return error_result("Unknown remote environment '#{target_env}'")
|
|
44
49
|
end
|
|
45
50
|
|
|
46
|
-
return fetch_remote_feedback(target_env, remote_cfg, feedback_id, include_images: include_images)
|
|
51
|
+
return fetch_remote_feedback(target_env, remote_cfg, feedback_id, include_images: include_images, include_deleted: include_deleted)
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
feedback = ContextDrop::Feedback
|
|
50
|
-
.includes(:submitter, :element_references, :attachments)
|
|
55
|
+
.includes(:submitter, :element_references, :attachments, comments: :attachments)
|
|
51
56
|
.find_by(id: feedback_id)
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
if !feedback || (!include_deleted && feedback.respond_to?(:deleted?) && feedback.deleted?)
|
|
59
|
+
return error_result("Feedback ##{feedback_id} not found")
|
|
60
|
+
end
|
|
54
61
|
|
|
55
62
|
payload = serialize_feedback(feedback)
|
|
56
63
|
content_blocks = [
|
|
@@ -65,6 +72,14 @@ module ContextDrop
|
|
|
65
72
|
img_block = build_image_content_block(att)
|
|
66
73
|
content_blocks << img_block if img_block
|
|
67
74
|
end
|
|
75
|
+
if feedback.respond_to?(:comments)
|
|
76
|
+
feedback.comments.each do |comment|
|
|
77
|
+
comment.attachments.each do |att|
|
|
78
|
+
img_block = build_image_content_block(att)
|
|
79
|
+
content_blocks << img_block if img_block
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
68
83
|
end
|
|
69
84
|
|
|
70
85
|
{
|
|
@@ -73,11 +88,13 @@ module ContextDrop
|
|
|
73
88
|
}
|
|
74
89
|
end
|
|
75
90
|
|
|
76
|
-
def self.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true)
|
|
77
|
-
|
|
91
|
+
def self.fetch_remote_feedback(env_name, remote_cfg, feedback_id, include_images: true, include_deleted: false)
|
|
92
|
+
remote_args = {
|
|
78
93
|
"id" => feedback_id,
|
|
79
94
|
"include_images" => include_images
|
|
80
|
-
}
|
|
95
|
+
}
|
|
96
|
+
remote_args["include_deleted"] = true if include_deleted
|
|
97
|
+
res = ContextDrop::MCP::RemoteClient.call_tool(env_name, remote_cfg, "get_feedback", remote_args)
|
|
81
98
|
return res if res[:isError]
|
|
82
99
|
|
|
83
100
|
updated_blocks = Array(res[:content]).map do |block|
|
|
@@ -119,6 +136,8 @@ module ContextDrop
|
|
|
119
136
|
metadata: feedback.metadata || {},
|
|
120
137
|
created_at: feedback.created_at&.iso8601,
|
|
121
138
|
updated_at: feedback.updated_at&.iso8601,
|
|
139
|
+
deleted: (feedback.respond_to?(:deleted?) ? feedback.deleted? : false),
|
|
140
|
+
deleted_at: (feedback.respond_to?(:deleted_at_value) ? feedback.deleted_at_value&.iso8601 : nil),
|
|
122
141
|
element_references: feedback.element_references.map do |el|
|
|
123
142
|
{
|
|
124
143
|
id: el.id,
|
|
@@ -147,6 +166,26 @@ module ContextDrop
|
|
|
147
166
|
byte_size: attached ? att.file.byte_size : nil,
|
|
148
167
|
created_at: att.created_at&.iso8601
|
|
149
168
|
}
|
|
169
|
+
end,
|
|
170
|
+
comments: (feedback.respond_to?(:comments) ? feedback.comments : []).map do |comment|
|
|
171
|
+
{
|
|
172
|
+
id: comment.id,
|
|
173
|
+
author_label: comment.display_author_label,
|
|
174
|
+
author_type: comment.author_type,
|
|
175
|
+
body: comment.body,
|
|
176
|
+
attachments: comment.attachments.map do |att|
|
|
177
|
+
attached = att.respond_to?(:file) && att.file.attached?
|
|
178
|
+
{
|
|
179
|
+
id: att.id,
|
|
180
|
+
attachment_type: att.attachment_type,
|
|
181
|
+
filename: attached ? att.file.filename.to_s : nil,
|
|
182
|
+
content_type: attached ? att.file.content_type : nil,
|
|
183
|
+
byte_size: attached ? att.file.byte_size : nil,
|
|
184
|
+
created_at: att.created_at&.iso8601
|
|
185
|
+
}
|
|
186
|
+
end,
|
|
187
|
+
created_at: comment.created_at&.iso8601
|
|
188
|
+
}
|
|
150
189
|
end
|
|
151
190
|
}
|
|
152
191
|
end
|
|
@@ -45,6 +45,9 @@ module ContextDrop
|
|
|
45
45
|
|
|
46
46
|
attachment = ContextDrop::Attachment.includes(:element_reference).find_by(id: att_id)
|
|
47
47
|
return error_result("Attachment ##{att_id} not found") unless attachment
|
|
48
|
+
if attachment.respond_to?(:feedback) && attachment.feedback.respond_to?(:deleted?) && attachment.feedback.deleted?
|
|
49
|
+
return error_result("Attachment ##{att_id} not found")
|
|
50
|
+
end
|
|
48
51
|
|
|
49
52
|
env_name = ContextDrop::MCP::EnvironmentRouter.host_environment
|
|
50
53
|
attached = attachment.respond_to?(:file) && attachment.file.attached?
|