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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +218 -49
  3. data/SPEC.md +74 -26
  4. data/app/assets/javascripts/context_drop/context_drop.js +5227 -652
  5. data/app/controllers/context_drop/agent_controller.rb +170 -0
  6. data/app/controllers/context_drop/configs_controller.rb +2 -1
  7. data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +62 -2
  8. data/app/controllers/context_drop/feedbacks_controller.rb +13 -3
  9. data/app/controllers/context_drop/mcp_controller.rb +2 -1
  10. data/app/helpers/context_drop/dashboard_helper.rb +52 -0
  11. data/app/helpers/context_drop/widget_helper.rb +11 -1
  12. data/app/javascript/context_drop/__tests__/widget.test.ts +731 -92
  13. data/app/javascript/context_drop/api-client.ts +130 -11
  14. data/app/javascript/context_drop/element-picker.ts +247 -30
  15. data/app/javascript/context_drop/icons.ts +24 -0
  16. data/app/javascript/context_drop/markdown.ts +146 -0
  17. data/app/javascript/context_drop/sanitizer.ts +413 -2
  18. data/app/javascript/context_drop/screenshot.ts +102 -8
  19. data/app/javascript/context_drop/styles.ts +1528 -252
  20. data/app/javascript/context_drop/types.ts +147 -0
  21. data/app/javascript/context_drop/widget.ts +2629 -288
  22. data/app/models/context_drop/feedback.rb +34 -5
  23. data/app/views/context_drop/dashboard/feedbacks/index.html.erb +166 -60
  24. data/app/views/context_drop/dashboard/feedbacks/show.html.erb +178 -47
  25. data/app/views/layouts/context_drop/application.html.erb +416 -70
  26. data/config/routes.rb +11 -0
  27. data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
  28. data/lib/context_drop/agent/key_store.rb +290 -0
  29. data/lib/context_drop/agent/llm_client.rb +413 -0
  30. data/lib/context_drop/agent/orchestrator.rb +314 -0
  31. data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
  32. data/lib/context_drop/configuration.rb +216 -3
  33. data/lib/context_drop/mcp/dispatcher.rb +71 -29
  34. data/lib/context_drop/mcp/environment_router.rb +115 -0
  35. data/lib/context_drop/mcp/prompts/investigate_feedback.rb +87 -8
  36. data/lib/context_drop/mcp/remote_client.rb +120 -0
  37. data/lib/context_drop/mcp/server.rb +9 -2
  38. data/lib/context_drop/mcp/tools/get_feedback.rb +50 -4
  39. data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +26 -4
  40. data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
  41. data/lib/context_drop/mcp/tools/list_feedbacks.rb +174 -22
  42. data/lib/context_drop/mcp/tools/update_feedback_status.rb +45 -4
  43. data/lib/context_drop/version.rb +1 -1
  44. data/lib/context_drop.rb +8 -2
  45. data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
  46. metadata +13 -2
@@ -1,6 +1,13 @@
1
1
  import type {
2
+ AgentChatRequestPayload,
3
+ AgentChatResponse,
4
+ AgentKeysUpdatePayload,
5
+ AgentKeysUpdateResponse,
6
+ AgentStatusResponse,
7
+ CrossEnvFeedbackListResponse,
2
8
  FeedbackSubmissionPayload,
3
9
  FeedbackSubmissionResponse,
10
+ ProposedFileEdit,
4
11
  WidgetConfig
5
12
  } from "./types.ts";
6
13
 
@@ -146,6 +153,17 @@ export class ContextDropApiClient {
146
153
  );
147
154
  }
148
155
 
156
+ private buildJsonHeaders(csrfToken: string | null): Record<string, string> {
157
+ const headers: Record<string, string> = {
158
+ "Content-Type": "application/json",
159
+ Accept: "application/json"
160
+ };
161
+ if (csrfToken) {
162
+ headers["X-CSRF-Token"] = csrfToken;
163
+ }
164
+ return headers;
165
+ }
166
+
149
167
  public async uploadAttachment(file: Blob, filename: string): Promise<{ signed_blob_id: string }> {
150
168
  const makeRequest = async (csrfToken: string | null) => {
151
169
  const formData = new FormData();
@@ -170,23 +188,124 @@ export class ContextDropApiClient {
170
188
  }
171
189
 
172
190
  public async submitFeedback(payload: FeedbackSubmissionPayload): Promise<FeedbackSubmissionResponse> {
173
- const makeRequest = async (csrfToken: string | null) => {
174
- const headers: Record<string, string> = {
175
- "Content-Type": "application/json",
191
+ const makeRequest = async (csrfToken: string | null) =>
192
+ fetch(`${this.baseUrl}/feedback`, {
193
+ method: "POST",
194
+ credentials: "same-origin",
195
+ headers: this.buildJsonHeaders(csrfToken),
196
+ body: JSON.stringify({ feedback: payload })
197
+ });
198
+
199
+ return this.executeWithCsrfRetry(makeRequest, "Submission failed");
200
+ }
201
+
202
+ public async fetchAgentStatus(): Promise<AgentStatusResponse> {
203
+ const response = await fetch(`${this.baseUrl}/agent/status`, {
204
+ method: "GET",
205
+ credentials: "same-origin",
206
+ headers: {
176
207
  Accept: "application/json"
177
- };
178
- if (csrfToken) {
179
- headers["X-CSRF-Token"] = csrfToken;
180
208
  }
209
+ });
210
+
211
+ if (!response.ok) {
212
+ const errBody = await response.json().catch(() => ({}));
213
+ throw new Error(
214
+ (errBody as { error?: string }).error || `Failed to load agent status (${response.status})`
215
+ );
216
+ }
217
+
218
+ return (await response.json()) as AgentStatusResponse;
219
+ }
181
220
 
182
- return fetch(`${this.baseUrl}/feedback`, {
221
+ public async saveAgentKeys(payload: AgentKeysUpdatePayload): Promise<AgentKeysUpdateResponse> {
222
+ const makeRequest = async (csrfToken: string | null) =>
223
+ fetch(`${this.baseUrl}/agent/keys`, {
183
224
  method: "POST",
184
225
  credentials: "same-origin",
185
- headers,
186
- body: JSON.stringify({ feedback: payload })
226
+ headers: this.buildJsonHeaders(csrfToken),
227
+ body: JSON.stringify(payload)
187
228
  });
188
- };
189
229
 
190
- return this.executeWithCsrfRetry(makeRequest, "Submission failed");
230
+ return this.executeWithCsrfRetry(makeRequest, "Failed to save BYOK settings");
231
+ }
232
+
233
+ public async deleteAgentKeys(provider: string = "all"): Promise<AgentKeysUpdateResponse> {
234
+ const makeRequest = async (csrfToken: string | null) =>
235
+ fetch(`${this.baseUrl}/agent/keys?provider=${encodeURIComponent(provider)}`, {
236
+ method: "DELETE",
237
+ credentials: "same-origin",
238
+ headers: this.buildJsonHeaders(csrfToken)
239
+ });
240
+
241
+ return this.executeWithCsrfRetry(makeRequest, "Failed to clear BYOK key");
242
+ }
243
+
244
+ public async fetchAgentFeedbacks(
245
+ environment: string = "all",
246
+ status: string = "new"
247
+ ): Promise<CrossEnvFeedbackListResponse> {
248
+ const qs = `environment=${encodeURIComponent(environment)}&status=${encodeURIComponent(status)}`;
249
+ const response = await fetch(`${this.baseUrl}/agent/feedbacks?${qs}`, {
250
+ method: "GET",
251
+ credentials: "same-origin",
252
+ headers: {
253
+ Accept: "application/json"
254
+ }
255
+ });
256
+
257
+ if (!response.ok) {
258
+ const errBody = await response.json().catch(() => ({}));
259
+ throw new Error(
260
+ (errBody as { error?: string }).error || `Failed to load feedbacks (${response.status})`
261
+ );
262
+ }
263
+
264
+ return (await response.json()) as CrossEnvFeedbackListResponse;
265
+ }
266
+
267
+ public async sendAgentChat(payload: AgentChatRequestPayload): Promise<AgentChatResponse> {
268
+ const makeRequest = async (csrfToken: string | null) =>
269
+ fetch(`${this.baseUrl}/agent/chat`, {
270
+ method: "POST",
271
+ credentials: "same-origin",
272
+ headers: this.buildJsonHeaders(csrfToken),
273
+ body: JSON.stringify(payload)
274
+ });
275
+
276
+ return this.executeWithCsrfRetry(makeRequest, "Agent request failed");
277
+ }
278
+
279
+ public async applyEdit(editId: string): Promise<{ edit: ProposedFileEdit }> {
280
+ const makeRequest = async (csrfToken: string | null) =>
281
+ fetch(`${this.baseUrl}/agent/edits/${encodeURIComponent(editId)}/apply`, {
282
+ method: "POST",
283
+ credentials: "same-origin",
284
+ headers: this.buildJsonHeaders(csrfToken)
285
+ });
286
+
287
+ return this.executeWithCsrfRetry(makeRequest, "Failed to apply file edit");
288
+ }
289
+
290
+ public async rejectEdit(editId: string): Promise<{ edit: ProposedFileEdit }> {
291
+ const makeRequest = async (csrfToken: string | null) =>
292
+ fetch(`${this.baseUrl}/agent/edits/${encodeURIComponent(editId)}/reject`, {
293
+ method: "POST",
294
+ credentials: "same-origin",
295
+ headers: this.buildJsonHeaders(csrfToken)
296
+ });
297
+
298
+ return this.executeWithCsrfRetry(makeRequest, "Failed to reject file edit");
299
+ }
300
+
301
+ public async revertEdit(editId: string): Promise<{ edit: ProposedFileEdit }> {
302
+ const makeRequest = async (csrfToken: string | null) =>
303
+ fetch(`${this.baseUrl}/agent/edits/${encodeURIComponent(editId)}/revert`, {
304
+ method: "POST",
305
+ credentials: "same-origin",
306
+ headers: this.buildJsonHeaders(csrfToken)
307
+ });
308
+
309
+ return this.executeWithCsrfRetry(makeRequest, "Failed to revert file edit");
191
310
  }
192
311
  }
@@ -1,10 +1,12 @@
1
- import type { ElementCandidateInfo, ElementReferenceSnapshot } from "./types.ts";
1
+ import type { ElementCandidateInfo, ElementReferenceSnapshot, SelectionMode } from "./types.ts";
2
2
  import {
3
3
  captureElementSnapshot,
4
+ computeSelector,
4
5
  describeElementCandidate,
5
6
  isSelectableElement,
6
7
  resolveAncestorChain,
7
- resolveCandidateStack
8
+ resolveCandidateStack,
9
+ resolveSmartComponent
8
10
  } from "./sanitizer.ts";
9
11
  import {
10
12
  ICON_CHECK,
@@ -16,6 +18,7 @@ import {
16
18
  export interface PinnedElementEntry {
17
19
  clientRef: string;
18
20
  selector: string;
21
+ friendlyLabel?: string;
19
22
  element: Element;
20
23
  }
21
24
 
@@ -38,6 +41,7 @@ export interface ElementPickerCallbacks {
38
41
  onExit: () => void;
39
42
  canSelectMore: () => boolean;
40
43
  getExcludedSelectors: () => string[];
44
+ getSelectionMode?: () => SelectionMode;
41
45
  getPinnedElements?: () => PinnedElementEntry[];
42
46
  onStateChange?: (state: ElementPickerStateSnapshot) => void;
43
47
  }
@@ -78,6 +82,7 @@ function isPointInsideRect(
78
82
 
79
83
  export class ElementPicker {
80
84
  private active: boolean = false;
85
+ private suppressCursorPin: boolean = false;
81
86
  private isScrubbingLayers: boolean = false;
82
87
  private scrubOriginX: number = 0;
83
88
  private scrubOriginY: number = 0;
@@ -108,6 +113,7 @@ export class ElementPicker {
108
113
  private boundMouseMove: (e: MouseEvent) => void;
109
114
  private boundClickCapture: (e: MouseEvent) => void;
110
115
  private boundPointerCapture: (e: Event) => void;
116
+ private boundBlurSuppression: (e: Event) => void;
111
117
  private boundWheelCapture: (e: WheelEvent) => void;
112
118
  private boundKeyDown: (e: KeyboardEvent) => void;
113
119
  private boundScrollOrResize: () => void;
@@ -117,6 +123,7 @@ export class ElementPicker {
117
123
  this.boundMouseMove = this.handleMouseMove.bind(this);
118
124
  this.boundClickCapture = this.handleClickCapture.bind(this);
119
125
  this.boundPointerCapture = this.handlePointerSuppression.bind(this);
126
+ this.boundBlurSuppression = this.handleBlurSuppression.bind(this);
120
127
  this.boundWheelCapture = this.handleWheelCapture.bind(this);
121
128
  this.boundKeyDown = this.handleKeyDown.bind(this);
122
129
  this.boundScrollOrResize = this.handleViewportScrollOrResize.bind(this);
@@ -134,6 +141,10 @@ export class ElementPicker {
134
141
  return this.isScrubbingLayers;
135
142
  }
136
143
 
144
+ private isSmartMode(): boolean {
145
+ return (this.callbacks.getSelectionMode ? this.callbacks.getSelectionMode() : "verbose") === "smart";
146
+ }
147
+
137
148
  public getActiveCandidate(): ElementCandidateInfo | null {
138
149
  return this.candidateStack[this.activeCandidateIndex] || null;
139
150
  }
@@ -142,11 +153,12 @@ export class ElementPicker {
142
153
  return [...this.candidateStack];
143
154
  }
144
155
 
145
- public start(): void {
156
+ public start(options?: { suppressCursorPin?: boolean }): void {
146
157
  if (this.active || typeof document === "undefined" || typeof window === "undefined") {
147
158
  return;
148
159
  }
149
160
  this.active = true;
161
+ this.suppressCursorPin = Boolean(options?.suppressCursorPin);
150
162
  this.isScrubbingLayers = false;
151
163
  this.wheelAccumulator = 0;
152
164
  this.lastWheelStepAt = 0;
@@ -159,7 +171,7 @@ export class ElementPicker {
159
171
 
160
172
  this.previousCursor = document.body ? document.body.style.cursor : "";
161
173
  if (document.body) {
162
- document.body.style.cursor = "crosshair";
174
+ document.body.style.cursor = this.suppressCursorPin ? "grabbing" : "crosshair";
163
175
  }
164
176
 
165
177
  this.mountSelectionUi();
@@ -171,15 +183,18 @@ export class ElementPicker {
171
183
  window.addEventListener("mousedown", this.boundPointerCapture, { capture: true });
172
184
  window.addEventListener("mouseup", this.boundPointerCapture, { capture: true });
173
185
  window.addEventListener("click", this.boundClickCapture, { capture: true });
186
+ window.addEventListener("blur", this.boundBlurSuppression, { capture: true });
187
+ window.addEventListener("focusout", this.boundBlurSuppression, { capture: true });
174
188
  window.addEventListener("wheel", this.boundWheelCapture, { capture: true, passive: false });
175
189
  window.addEventListener("keydown", this.boundKeyDown, { capture: true });
176
190
  window.addEventListener("scroll", this.boundScrollOrResize, { capture: true, passive: true });
177
191
  window.addEventListener("resize", this.boundScrollOrResize, { passive: true });
178
192
  }
179
193
 
180
- public stop(): void {
194
+ public stop(options?: { silent?: boolean }): void {
181
195
  if (!this.active) return;
182
196
  this.active = false;
197
+ this.suppressCursorPin = false;
183
198
  this.isScrubbingLayers = false;
184
199
  this.wheelAccumulator = 0;
185
200
  this.candidateStack = [];
@@ -198,6 +213,8 @@ export class ElementPicker {
198
213
  window.removeEventListener("mousedown", this.boundPointerCapture, { capture: true });
199
214
  window.removeEventListener("mouseup", this.boundPointerCapture, { capture: true });
200
215
  window.removeEventListener("click", this.boundClickCapture, { capture: true });
216
+ window.removeEventListener("blur", this.boundBlurSuppression, { capture: true });
217
+ window.removeEventListener("focusout", this.boundBlurSuppression, { capture: true });
201
218
  window.removeEventListener("wheel", this.boundWheelCapture, { capture: true });
202
219
  window.removeEventListener("keydown", this.boundKeyDown, { capture: true });
203
220
  window.removeEventListener("scroll", this.boundScrollOrResize, { capture: true });
@@ -206,7 +223,43 @@ export class ElementPicker {
206
223
 
207
224
  this.unmountSelectionUi();
208
225
  this.notifyStateChange();
209
- this.callbacks.onExit();
226
+ if (!options?.silent) {
227
+ this.callbacks.onExit();
228
+ }
229
+ }
230
+
231
+ public highlightAtPoint(x: number, y: number, event?: Event): void {
232
+ if (!this.active || typeof document === "undefined") return;
233
+ this.lastPointerX = x;
234
+ this.lastPointerY = y;
235
+ this.updateCandidatesFromPoint(x, y, event);
236
+ this.updateOverlayPosition();
237
+ this.notifyStateChange();
238
+ }
239
+
240
+ public clearCandidateHighlight(): void {
241
+ if (!this.active) return;
242
+ this.leafElement = null;
243
+ this.candidateStack = [];
244
+ this.activeCandidateIndex = 0;
245
+ this.isScrubbingLayers = false;
246
+ if (this.overlayEl) this.overlayEl.style.display = "none";
247
+ if (this.hudEl) this.hudEl.style.display = "none";
248
+ if (this.leafOutlineEl) this.leafOutlineEl.style.display = "none";
249
+ if (this.pinMarkerEl) this.pinMarkerEl.style.display = "none";
250
+ this.notifyStateChange();
251
+ }
252
+
253
+ public commitActiveCandidate(x?: number, y?: number): boolean {
254
+ if (!this.active) return false;
255
+ const candidate = this.getActiveCandidate();
256
+ if (!candidate) return false;
257
+ this.commitCandidateSelection(
258
+ candidate.element,
259
+ x ?? this.lastPointerX ?? 80,
260
+ y ?? this.lastPointerY ?? 80
261
+ );
262
+ return true;
210
263
  }
211
264
 
212
265
  public focusCandidateElement(el: Element): void {
@@ -275,6 +328,7 @@ export class ElementPicker {
275
328
 
276
329
  const badge = document.createElement("div");
277
330
  const badgeTop = rect.top < 26 ? "4px" : "-22px";
331
+ const smartMode = this.isSmartMode();
278
332
  badge.style.cssText = [
279
333
  "position: absolute",
280
334
  `top: ${badgeTop}`,
@@ -282,23 +336,27 @@ export class ElementPicker {
282
336
  "display: inline-flex",
283
337
  "align-items: center",
284
338
  "gap: 4px",
285
- "padding: 2px 6px",
339
+ "padding: 2px 7px",
286
340
  "border-radius: 9999px",
287
341
  "background: #c2410c",
288
342
  "color: #faf9f6",
289
343
  "border: 1px solid #faf9f6",
290
- "font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
344
+ smartMode
345
+ ? "font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
346
+ : "font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
291
347
  "font-size: 10px",
292
- "font-weight: 700",
348
+ "font-weight: 600",
293
349
  "font-variant-numeric: tabular-nums",
294
350
  "line-height: 1.2",
295
- "max-width: 160px",
351
+ "max-width: 180px",
296
352
  "overflow: hidden",
297
353
  "text-overflow: ellipsis",
298
354
  "white-space: nowrap",
299
355
  "box-shadow: 0 4px 10px -2px rgba(17, 19, 24, 0.25)"
300
356
  ].join(";");
301
- badge.textContent = `#${index + 1} ${entry.selector}`;
357
+ badge.textContent = smartMode
358
+ ? entry.friendlyLabel || "Selected area"
359
+ : `#${index + 1} ${entry.selector}`;
302
360
 
303
361
  markerFrame.appendChild(badge);
304
362
  this.pinnedMarkersContainerEl?.appendChild(markerFrame);
@@ -624,6 +682,22 @@ export class ElementPicker {
624
682
  return;
625
683
  }
626
684
 
685
+ if (this.isSmartMode()) {
686
+ const smartComponent = resolveSmartComponent(primary, excluded) || primary;
687
+ if (
688
+ this.leafElement === primary &&
689
+ this.candidateStack.length === 1 &&
690
+ this.candidateStack[0].element === smartComponent
691
+ ) {
692
+ return;
693
+ }
694
+ this.leafElement = primary;
695
+ this.candidateStack = [describeElementCandidate(smartComponent, "target", 0, excluded)];
696
+ this.activeCandidateIndex = 0;
697
+ this.isScrubbingLayers = false;
698
+ return;
699
+ }
700
+
627
701
  // Preserve depth & inline stack when pointer stays inside the exact same primary leaf element
628
702
  if (this.leafElement === primary && this.candidateStack.length > 0) {
629
703
  return;
@@ -670,9 +744,13 @@ export class ElementPicker {
670
744
  }
671
745
 
672
746
  if (this.pinMarkerEl) {
673
- this.pinMarkerEl.style.display = "inline-flex";
674
- this.pinMarkerEl.style.left = `${event.clientX}px`;
675
- this.pinMarkerEl.style.top = `${event.clientY}px`;
747
+ if (this.suppressCursorPin) {
748
+ this.pinMarkerEl.style.display = "none";
749
+ } else {
750
+ this.pinMarkerEl.style.display = "inline-flex";
751
+ this.pinMarkerEl.style.left = `${event.clientX}px`;
752
+ this.pinMarkerEl.style.top = `${event.clientY}px`;
753
+ }
676
754
  }
677
755
 
678
756
  this.updateCandidatesFromPoint(event.clientX, event.clientY, event);
@@ -703,6 +781,64 @@ export class ElementPicker {
703
781
  return kbd;
704
782
  }
705
783
 
784
+ private renderSmartHudContent(currentCandidate: ElementCandidateInfo): void {
785
+ if (!this.hudEl) return;
786
+ this.hudEl.innerHTML = "";
787
+ this.hudEl.style.width = "auto";
788
+ this.hudEl.style.maxWidth = "min(360px, calc(100vw - 20px))";
789
+ this.hudEl.style.borderRadius = "9999px";
790
+
791
+ const pinnedInfo = this.findPinnedIndex(currentCandidate.element);
792
+ const pill = document.createElement("div");
793
+ pill.setAttribute("data-context-drop-ui", "smart-hud-pill");
794
+ pill.style.cssText = [
795
+ "display: inline-flex",
796
+ "align-items: center",
797
+ "gap: 7px",
798
+ "padding: 6px 12px",
799
+ "white-space: nowrap"
800
+ ].join(";");
801
+
802
+ const iconDot = document.createElement("span");
803
+ iconDot.style.cssText = [
804
+ "display: inline-flex",
805
+ "align-items: center",
806
+ "justify-content: center",
807
+ "width: 14px",
808
+ "height: 14px",
809
+ "color: #ffedd5",
810
+ "flex-shrink: 0"
811
+ ].join(";");
812
+ iconDot.innerHTML = ICON_PIN;
813
+ pill.appendChild(iconDot);
814
+
815
+ const nameSpan = document.createElement("span");
816
+ nameSpan.textContent = currentCandidate.friendlyLabel || "Page area";
817
+ nameSpan.style.cssText = [
818
+ "font-size: 12px",
819
+ "font-weight: 600",
820
+ "color: #faf9f6",
821
+ "max-width: 210px",
822
+ "overflow: hidden",
823
+ "text-overflow: ellipsis",
824
+ "white-space: nowrap"
825
+ ].join(";");
826
+ pill.appendChild(nameSpan);
827
+
828
+ const actionHint = document.createElement("span");
829
+ actionHint.textContent = this.suppressCursorPin
830
+ ? pinnedInfo
831
+ ? "· Release to remove"
832
+ : "· Release to select"
833
+ : pinnedInfo
834
+ ? "· Click to remove"
835
+ : "· Click to select";
836
+ actionHint.style.cssText = "font-size: 11px; color: #cbd5e1; flex-shrink: 0;";
837
+ pill.appendChild(actionHint);
838
+
839
+ this.hudEl.appendChild(pill);
840
+ }
841
+
706
842
  private renderCompactHudContent(
707
843
  currentCandidate: ElementCandidateInfo,
708
844
  rect: { width: number; height: number }
@@ -711,6 +847,7 @@ export class ElementPicker {
711
847
  this.hudEl.innerHTML = "";
712
848
  this.hudEl.style.width = "auto";
713
849
  this.hudEl.style.maxWidth = "min(440px, calc(100vw - 20px))";
850
+ this.hudEl.style.borderRadius = "10px";
714
851
 
715
852
  const total = this.candidateStack.length;
716
853
  const pos = this.activeCandidateIndex + 1;
@@ -817,13 +954,26 @@ export class ElementPicker {
817
954
  ].join(";");
818
955
 
819
956
  const clickHint = document.createElement("span");
820
- const clickStrong = document.createElement("strong");
821
- clickStrong.style.cssText = pinnedInfo
822
- ? "color: #ffedd5; font-weight: 600;"
823
- : "color: #faf9f6; font-weight: 600;";
824
- clickStrong.textContent = "Click";
825
- clickHint.appendChild(clickStrong);
826
- clickHint.appendChild(this.createSpanEl(pinnedInfo ? " to unpin" : " to pin"));
957
+ clickHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
958
+ if (this.suppressCursorPin) {
959
+ const releaseStrong = document.createElement("strong");
960
+ releaseStrong.style.cssText = pinnedInfo
961
+ ? "color: #ffedd5; font-weight: 600;"
962
+ : "color: #faf9f6; font-weight: 600;";
963
+ releaseStrong.textContent = "Release";
964
+ clickHint.appendChild(releaseStrong);
965
+ clickHint.appendChild(this.createSpanEl(pinnedInfo ? " to unpin" : " to pin"));
966
+ } else {
967
+ clickHint.appendChild(this.createKbdEl("Space"));
968
+ clickHint.appendChild(this.createSpanEl("or"));
969
+ const clickStrong = document.createElement("strong");
970
+ clickStrong.style.cssText = pinnedInfo
971
+ ? "color: #ffedd5; font-weight: 600;"
972
+ : "color: #faf9f6; font-weight: 600;";
973
+ clickStrong.textContent = "Click";
974
+ clickHint.appendChild(clickStrong);
975
+ clickHint.appendChild(this.createSpanEl(pinnedInfo ? " to unpin" : " to pin"));
976
+ }
827
977
  coachRow.appendChild(clickHint);
828
978
 
829
979
  if (total > 1) {
@@ -847,6 +997,8 @@ export class ElementPicker {
847
997
 
848
998
  const escHint = document.createElement("span");
849
999
  escHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
1000
+ escHint.appendChild(this.createKbdEl("⌥⇧P"));
1001
+ escHint.appendChild(this.createSpanEl("freeze · "));
850
1002
  escHint.appendChild(this.createKbdEl("Esc"));
851
1003
  escHint.appendChild(this.createSpanEl("done"));
852
1004
  coachRow.appendChild(escHint);
@@ -1076,8 +1228,10 @@ export class ElementPicker {
1076
1228
 
1077
1229
  const keysHint = document.createElement("span");
1078
1230
  keysHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
1079
- keysHint.appendChild(this.createKbdEl("Enter"));
1231
+ keysHint.appendChild(this.createKbdEl("Space"));
1080
1232
  keysHint.appendChild(this.createSpanEl("pin · "));
1233
+ keysHint.appendChild(this.createKbdEl("⌥⇧P"));
1234
+ keysHint.appendChild(this.createSpanEl("freeze · "));
1081
1235
  keysHint.appendChild(this.createKbdEl("Esc"));
1082
1236
  keysHint.appendChild(this.createSpanEl("done"));
1083
1237
 
@@ -1148,16 +1302,20 @@ export class ElementPicker {
1148
1302
  this.overlayEl.style.height = `${rect.height}px`;
1149
1303
 
1150
1304
  this.hudEl.style.display = "block";
1151
- if (this.isScrubbingLayers && this.candidateStack.length > 1) {
1305
+ if (this.isSmartMode()) {
1306
+ this.renderSmartHudContent(currentCandidate);
1307
+ } else if (this.isScrubbingLayers && this.candidateStack.length > 1) {
1308
+ this.hudEl.style.borderRadius = "10px";
1152
1309
  this.renderScrubbingHudContent(currentCandidate, rect);
1153
1310
  } else {
1154
1311
  this.renderCompactHudContent(currentCandidate, rect);
1155
1312
  }
1156
1313
  this.positionHudElement(rect);
1157
1314
 
1158
- // Show ghost leaf outline when inspecting an ancestor or overlapping layer
1315
+ // Show ghost leaf outline only in verbose inspector mode when inspecting an ancestor/overlap layer
1159
1316
  if (this.leafOutlineEl) {
1160
1317
  if (
1318
+ !this.isSmartMode() &&
1161
1319
  this.activeCandidateIndex > 0 &&
1162
1320
  this.leafElement &&
1163
1321
  this.leafElement !== currentCandidate.element
@@ -1267,6 +1425,7 @@ export class ElementPicker {
1267
1425
  }
1268
1426
 
1269
1427
  private commitCandidateSelection(el: Element, x: number, y: number): void {
1428
+ const smartMode = this.isSmartMode();
1270
1429
  const existingPinned = this.findPinnedIndex(el);
1271
1430
  if (existingPinned && this.callbacks.onUnselect) {
1272
1431
  this.callbacks.onUnselect(existingPinned.entry.clientRef, el);
@@ -1274,14 +1433,22 @@ export class ElementPicker {
1274
1433
  this.isScrubbingLayers = false;
1275
1434
  this.refreshPinnedMarkers();
1276
1435
  this.flashSelectionPulse("unpinned");
1277
- this.showCursorToast(existingPinned.entry.selector, "unpinned", x, y);
1436
+ if (!smartMode) {
1437
+ this.showCursorToast(existingPinned.entry.selector, "unpinned", x, y);
1438
+ }
1278
1439
  this.updateOverlayPosition();
1279
1440
  this.notifyStateChange();
1280
1441
  return;
1281
1442
  }
1282
1443
 
1283
1444
  const excluded = this.callbacks.getExcludedSelectors();
1284
- const snapshot = captureElementSnapshot(el, excluded);
1445
+ const extraMeta: Record<string, unknown> = {
1446
+ selection_mode: smartMode ? "smart" : "verbose"
1447
+ };
1448
+ if (smartMode && this.leafElement && this.leafElement !== el) {
1449
+ extraMeta.original_target_selector = computeSelector(this.leafElement);
1450
+ }
1451
+ const snapshot = captureElementSnapshot(el, excluded, undefined, extraMeta);
1285
1452
  if (!snapshot) return;
1286
1453
 
1287
1454
  this.callbacks.onSelect(snapshot, el);
@@ -1289,19 +1456,24 @@ export class ElementPicker {
1289
1456
  this.isScrubbingLayers = false;
1290
1457
  this.refreshPinnedMarkers();
1291
1458
 
1292
- if (!this.callbacks.canSelectMore()) {
1459
+ // In Production ("smart") click-select mode, immediately return to the quick feedback card
1460
+ // instead of keeping the user inside a multi-pin inspector loop.
1461
+ if ((smartMode && !this.suppressCursorPin) || !this.callbacks.canSelectMore()) {
1293
1462
  this.stop();
1294
1463
  return;
1295
1464
  }
1296
1465
 
1297
1466
  this.flashSelectionPulse("pinned");
1298
- this.showCursorToast(snapshot.selector, "pinned", x, y);
1467
+ if (!smartMode) {
1468
+ this.showCursorToast(snapshot.selector, "pinned", x, y);
1469
+ }
1299
1470
  this.updateOverlayPosition();
1300
1471
  this.notifyStateChange();
1301
1472
  }
1302
1473
 
1303
1474
  private handleWheelCapture(event: WheelEvent): void {
1304
1475
  if (!this.active) return;
1476
+ if (this.isSmartMode()) return;
1305
1477
  if (this.isInternalUiEvent(event)) return;
1306
1478
  if (event.altKey || event.ctrlKey || event.metaKey) return;
1307
1479
 
@@ -1351,6 +1523,20 @@ export class ElementPicker {
1351
1523
  }
1352
1524
  }
1353
1525
 
1526
+ private handleBlurSuppression(event: Event): void {
1527
+ if (!this.active) return;
1528
+ if (this.isInternalUiEvent(event)) {
1529
+ return;
1530
+ }
1531
+
1532
+ // Freeze DOM states: suppress blur / focusout on host elements while picker is active
1533
+ // so transient popovers, tooltips, flyout menus, and modals remain open
1534
+ event.stopPropagation();
1535
+ if (typeof event.stopImmediatePropagation === "function") {
1536
+ event.stopImmediatePropagation();
1537
+ }
1538
+ }
1539
+
1354
1540
  private handleClickCapture(event: MouseEvent): void {
1355
1541
  if (!this.active) return;
1356
1542
  if (this.isInternalUiEvent(event)) {
@@ -1383,14 +1569,45 @@ export class ElementPicker {
1383
1569
  return;
1384
1570
  }
1385
1571
 
1386
- if (event.key === "ArrowUp" || event.key === "[") {
1572
+ // Alt+Shift+P / Option+Shift+P toggle / exit Freeze & Pin mode
1573
+ if (
1574
+ event.altKey &&
1575
+ event.shiftKey &&
1576
+ (event.code === "KeyP" || event.key.toLowerCase() === "p")
1577
+ ) {
1578
+ event.preventDefault();
1579
+ event.stopPropagation();
1580
+ this.stop();
1581
+ return;
1582
+ }
1583
+
1584
+ // Space key freezes & pins the currently hovered element without triggering mouse clicks
1585
+ if (event.key === " " || event.key === "Spacebar" || event.code === "Space") {
1586
+ if (this.isInternalUiEvent(event)) return;
1587
+ const candidate = this.getActiveCandidate();
1588
+ if (candidate) {
1589
+ event.preventDefault();
1590
+ event.stopPropagation();
1591
+ if (typeof event.stopImmediatePropagation === "function") {
1592
+ event.stopImmediatePropagation();
1593
+ }
1594
+ this.commitCandidateSelection(
1595
+ candidate.element,
1596
+ this.lastPointerX || 80,
1597
+ this.lastPointerY || 80
1598
+ );
1599
+ }
1600
+ return;
1601
+ }
1602
+
1603
+ if (!this.isSmartMode() && (event.key === "ArrowUp" || event.key === "[")) {
1387
1604
  event.preventDefault();
1388
1605
  event.stopPropagation();
1389
1606
  this.cycleDepth(1, true);
1390
1607
  return;
1391
1608
  }
1392
1609
 
1393
- if (event.key === "ArrowDown" || event.key === "]") {
1610
+ if (!this.isSmartMode() && (event.key === "ArrowDown" || event.key === "]")) {
1394
1611
  event.preventDefault();
1395
1612
  event.stopPropagation();
1396
1613
  this.cycleDepth(-1, true);