context_drop 0.1.4 → 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 +184 -107
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +5121 -651
- 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/feedbacks_controller.rb +13 -3
- data/app/controllers/context_drop/mcp_controller.rb +2 -1
- data/app/helpers/context_drop/widget_helper.rb +11 -1
- data/app/javascript/context_drop/__tests__/widget.test.ts +661 -89
- data/app/javascript/context_drop/api-client.ts +130 -11
- data/app/javascript/context_drop/element-picker.ts +185 -33
- 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 +2591 -290
- data/app/models/context_drop/feedback.rb +23 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +5 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +10 -0
- data/app/views/layouts/context_drop/application.html.erb +1 -0
- 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 +11 -1
|
@@ -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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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(
|
|
226
|
+
headers: this.buildJsonHeaders(csrfToken),
|
|
227
|
+
body: JSON.stringify(payload)
|
|
187
228
|
});
|
|
188
|
-
};
|
|
189
229
|
|
|
190
|
-
return this.executeWithCsrfRetry(makeRequest, "
|
|
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;
|
|
@@ -136,6 +141,10 @@ export class ElementPicker {
|
|
|
136
141
|
return this.isScrubbingLayers;
|
|
137
142
|
}
|
|
138
143
|
|
|
144
|
+
private isSmartMode(): boolean {
|
|
145
|
+
return (this.callbacks.getSelectionMode ? this.callbacks.getSelectionMode() : "verbose") === "smart";
|
|
146
|
+
}
|
|
147
|
+
|
|
139
148
|
public getActiveCandidate(): ElementCandidateInfo | null {
|
|
140
149
|
return this.candidateStack[this.activeCandidateIndex] || null;
|
|
141
150
|
}
|
|
@@ -144,11 +153,12 @@ export class ElementPicker {
|
|
|
144
153
|
return [...this.candidateStack];
|
|
145
154
|
}
|
|
146
155
|
|
|
147
|
-
public start(): void {
|
|
156
|
+
public start(options?: { suppressCursorPin?: boolean }): void {
|
|
148
157
|
if (this.active || typeof document === "undefined" || typeof window === "undefined") {
|
|
149
158
|
return;
|
|
150
159
|
}
|
|
151
160
|
this.active = true;
|
|
161
|
+
this.suppressCursorPin = Boolean(options?.suppressCursorPin);
|
|
152
162
|
this.isScrubbingLayers = false;
|
|
153
163
|
this.wheelAccumulator = 0;
|
|
154
164
|
this.lastWheelStepAt = 0;
|
|
@@ -161,7 +171,7 @@ export class ElementPicker {
|
|
|
161
171
|
|
|
162
172
|
this.previousCursor = document.body ? document.body.style.cursor : "";
|
|
163
173
|
if (document.body) {
|
|
164
|
-
document.body.style.cursor = "crosshair";
|
|
174
|
+
document.body.style.cursor = this.suppressCursorPin ? "grabbing" : "crosshair";
|
|
165
175
|
}
|
|
166
176
|
|
|
167
177
|
this.mountSelectionUi();
|
|
@@ -181,9 +191,10 @@ export class ElementPicker {
|
|
|
181
191
|
window.addEventListener("resize", this.boundScrollOrResize, { passive: true });
|
|
182
192
|
}
|
|
183
193
|
|
|
184
|
-
public stop(): void {
|
|
194
|
+
public stop(options?: { silent?: boolean }): void {
|
|
185
195
|
if (!this.active) return;
|
|
186
196
|
this.active = false;
|
|
197
|
+
this.suppressCursorPin = false;
|
|
187
198
|
this.isScrubbingLayers = false;
|
|
188
199
|
this.wheelAccumulator = 0;
|
|
189
200
|
this.candidateStack = [];
|
|
@@ -212,14 +223,43 @@ export class ElementPicker {
|
|
|
212
223
|
|
|
213
224
|
this.unmountSelectionUi();
|
|
214
225
|
this.notifyStateChange();
|
|
215
|
-
|
|
226
|
+
if (!options?.silent) {
|
|
227
|
+
this.callbacks.onExit();
|
|
228
|
+
}
|
|
216
229
|
}
|
|
217
230
|
|
|
218
|
-
public highlightAtPoint(x: number, y: number): void {
|
|
231
|
+
public highlightAtPoint(x: number, y: number, event?: Event): void {
|
|
219
232
|
if (!this.active || typeof document === "undefined") return;
|
|
220
233
|
this.lastPointerX = x;
|
|
221
234
|
this.lastPointerY = y;
|
|
222
|
-
this.updateCandidatesFromPoint(x, 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;
|
|
223
263
|
}
|
|
224
264
|
|
|
225
265
|
public focusCandidateElement(el: Element): void {
|
|
@@ -288,6 +328,7 @@ export class ElementPicker {
|
|
|
288
328
|
|
|
289
329
|
const badge = document.createElement("div");
|
|
290
330
|
const badgeTop = rect.top < 26 ? "4px" : "-22px";
|
|
331
|
+
const smartMode = this.isSmartMode();
|
|
291
332
|
badge.style.cssText = [
|
|
292
333
|
"position: absolute",
|
|
293
334
|
`top: ${badgeTop}`,
|
|
@@ -295,23 +336,27 @@ export class ElementPicker {
|
|
|
295
336
|
"display: inline-flex",
|
|
296
337
|
"align-items: center",
|
|
297
338
|
"gap: 4px",
|
|
298
|
-
"padding: 2px
|
|
339
|
+
"padding: 2px 7px",
|
|
299
340
|
"border-radius: 9999px",
|
|
300
341
|
"background: #c2410c",
|
|
301
342
|
"color: #faf9f6",
|
|
302
343
|
"border: 1px solid #faf9f6",
|
|
303
|
-
|
|
344
|
+
smartMode
|
|
345
|
+
? "font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"
|
|
346
|
+
: "font-family: ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
304
347
|
"font-size: 10px",
|
|
305
|
-
"font-weight:
|
|
348
|
+
"font-weight: 600",
|
|
306
349
|
"font-variant-numeric: tabular-nums",
|
|
307
350
|
"line-height: 1.2",
|
|
308
|
-
"max-width:
|
|
351
|
+
"max-width: 180px",
|
|
309
352
|
"overflow: hidden",
|
|
310
353
|
"text-overflow: ellipsis",
|
|
311
354
|
"white-space: nowrap",
|
|
312
355
|
"box-shadow: 0 4px 10px -2px rgba(17, 19, 24, 0.25)"
|
|
313
356
|
].join(";");
|
|
314
|
-
badge.textContent =
|
|
357
|
+
badge.textContent = smartMode
|
|
358
|
+
? entry.friendlyLabel || "Selected area"
|
|
359
|
+
: `#${index + 1} ${entry.selector}`;
|
|
315
360
|
|
|
316
361
|
markerFrame.appendChild(badge);
|
|
317
362
|
this.pinnedMarkersContainerEl?.appendChild(markerFrame);
|
|
@@ -637,6 +682,22 @@ export class ElementPicker {
|
|
|
637
682
|
return;
|
|
638
683
|
}
|
|
639
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
|
+
|
|
640
701
|
// Preserve depth & inline stack when pointer stays inside the exact same primary leaf element
|
|
641
702
|
if (this.leafElement === primary && this.candidateStack.length > 0) {
|
|
642
703
|
return;
|
|
@@ -683,9 +744,13 @@ export class ElementPicker {
|
|
|
683
744
|
}
|
|
684
745
|
|
|
685
746
|
if (this.pinMarkerEl) {
|
|
686
|
-
this.
|
|
687
|
-
|
|
688
|
-
|
|
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
|
+
}
|
|
689
754
|
}
|
|
690
755
|
|
|
691
756
|
this.updateCandidatesFromPoint(event.clientX, event.clientY, event);
|
|
@@ -716,6 +781,64 @@ export class ElementPicker {
|
|
|
716
781
|
return kbd;
|
|
717
782
|
}
|
|
718
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
|
+
|
|
719
842
|
private renderCompactHudContent(
|
|
720
843
|
currentCandidate: ElementCandidateInfo,
|
|
721
844
|
rect: { width: number; height: number }
|
|
@@ -724,6 +847,7 @@ export class ElementPicker {
|
|
|
724
847
|
this.hudEl.innerHTML = "";
|
|
725
848
|
this.hudEl.style.width = "auto";
|
|
726
849
|
this.hudEl.style.maxWidth = "min(440px, calc(100vw - 20px))";
|
|
850
|
+
this.hudEl.style.borderRadius = "10px";
|
|
727
851
|
|
|
728
852
|
const total = this.candidateStack.length;
|
|
729
853
|
const pos = this.activeCandidateIndex + 1;
|
|
@@ -831,15 +955,25 @@ export class ElementPicker {
|
|
|
831
955
|
|
|
832
956
|
const clickHint = document.createElement("span");
|
|
833
957
|
clickHint.style.cssText = "display: inline-flex; align-items: center; gap: 4px;";
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
+
}
|
|
843
977
|
coachRow.appendChild(clickHint);
|
|
844
978
|
|
|
845
979
|
if (total > 1) {
|
|
@@ -1168,16 +1302,20 @@ export class ElementPicker {
|
|
|
1168
1302
|
this.overlayEl.style.height = `${rect.height}px`;
|
|
1169
1303
|
|
|
1170
1304
|
this.hudEl.style.display = "block";
|
|
1171
|
-
if (this.
|
|
1305
|
+
if (this.isSmartMode()) {
|
|
1306
|
+
this.renderSmartHudContent(currentCandidate);
|
|
1307
|
+
} else if (this.isScrubbingLayers && this.candidateStack.length > 1) {
|
|
1308
|
+
this.hudEl.style.borderRadius = "10px";
|
|
1172
1309
|
this.renderScrubbingHudContent(currentCandidate, rect);
|
|
1173
1310
|
} else {
|
|
1174
1311
|
this.renderCompactHudContent(currentCandidate, rect);
|
|
1175
1312
|
}
|
|
1176
1313
|
this.positionHudElement(rect);
|
|
1177
1314
|
|
|
1178
|
-
// Show ghost leaf outline when inspecting an ancestor
|
|
1315
|
+
// Show ghost leaf outline only in verbose inspector mode when inspecting an ancestor/overlap layer
|
|
1179
1316
|
if (this.leafOutlineEl) {
|
|
1180
1317
|
if (
|
|
1318
|
+
!this.isSmartMode() &&
|
|
1181
1319
|
this.activeCandidateIndex > 0 &&
|
|
1182
1320
|
this.leafElement &&
|
|
1183
1321
|
this.leafElement !== currentCandidate.element
|
|
@@ -1287,6 +1425,7 @@ export class ElementPicker {
|
|
|
1287
1425
|
}
|
|
1288
1426
|
|
|
1289
1427
|
private commitCandidateSelection(el: Element, x: number, y: number): void {
|
|
1428
|
+
const smartMode = this.isSmartMode();
|
|
1290
1429
|
const existingPinned = this.findPinnedIndex(el);
|
|
1291
1430
|
if (existingPinned && this.callbacks.onUnselect) {
|
|
1292
1431
|
this.callbacks.onUnselect(existingPinned.entry.clientRef, el);
|
|
@@ -1294,14 +1433,22 @@ export class ElementPicker {
|
|
|
1294
1433
|
this.isScrubbingLayers = false;
|
|
1295
1434
|
this.refreshPinnedMarkers();
|
|
1296
1435
|
this.flashSelectionPulse("unpinned");
|
|
1297
|
-
|
|
1436
|
+
if (!smartMode) {
|
|
1437
|
+
this.showCursorToast(existingPinned.entry.selector, "unpinned", x, y);
|
|
1438
|
+
}
|
|
1298
1439
|
this.updateOverlayPosition();
|
|
1299
1440
|
this.notifyStateChange();
|
|
1300
1441
|
return;
|
|
1301
1442
|
}
|
|
1302
1443
|
|
|
1303
1444
|
const excluded = this.callbacks.getExcludedSelectors();
|
|
1304
|
-
const
|
|
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);
|
|
1305
1452
|
if (!snapshot) return;
|
|
1306
1453
|
|
|
1307
1454
|
this.callbacks.onSelect(snapshot, el);
|
|
@@ -1309,19 +1456,24 @@ export class ElementPicker {
|
|
|
1309
1456
|
this.isScrubbingLayers = false;
|
|
1310
1457
|
this.refreshPinnedMarkers();
|
|
1311
1458
|
|
|
1312
|
-
|
|
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()) {
|
|
1313
1462
|
this.stop();
|
|
1314
1463
|
return;
|
|
1315
1464
|
}
|
|
1316
1465
|
|
|
1317
1466
|
this.flashSelectionPulse("pinned");
|
|
1318
|
-
|
|
1467
|
+
if (!smartMode) {
|
|
1468
|
+
this.showCursorToast(snapshot.selector, "pinned", x, y);
|
|
1469
|
+
}
|
|
1319
1470
|
this.updateOverlayPosition();
|
|
1320
1471
|
this.notifyStateChange();
|
|
1321
1472
|
}
|
|
1322
1473
|
|
|
1323
1474
|
private handleWheelCapture(event: WheelEvent): void {
|
|
1324
1475
|
if (!this.active) return;
|
|
1476
|
+
if (this.isSmartMode()) return;
|
|
1325
1477
|
if (this.isInternalUiEvent(event)) return;
|
|
1326
1478
|
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
1327
1479
|
|
|
@@ -1448,14 +1600,14 @@ export class ElementPicker {
|
|
|
1448
1600
|
return;
|
|
1449
1601
|
}
|
|
1450
1602
|
|
|
1451
|
-
if (event.key === "ArrowUp" || event.key === "[") {
|
|
1603
|
+
if (!this.isSmartMode() && (event.key === "ArrowUp" || event.key === "[")) {
|
|
1452
1604
|
event.preventDefault();
|
|
1453
1605
|
event.stopPropagation();
|
|
1454
1606
|
this.cycleDepth(1, true);
|
|
1455
1607
|
return;
|
|
1456
1608
|
}
|
|
1457
1609
|
|
|
1458
|
-
if (event.key === "ArrowDown" || event.key === "]") {
|
|
1610
|
+
if (!this.isSmartMode() && (event.key === "ArrowDown" || event.key === "]")) {
|
|
1459
1611
|
event.preventDefault();
|
|
1460
1612
|
event.stopPropagation();
|
|
1461
1613
|
this.cycleDepth(-1, true);
|
|
@@ -35,3 +35,27 @@ export const ICON_CHECK = `<svg viewBox="0 0 16 16" width="12" height="12" fill=
|
|
|
35
35
|
|
|
36
36
|
export const ICON_CHAT = `<svg viewBox="0 0 20 20" width="15" height="15" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4h12a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H8l-4 3v-3H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z"/></svg>`;
|
|
37
37
|
|
|
38
|
+
export const ICON_SIDEBAR = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="3.5" width="15" height="13" rx="2"/><line x1="12" y1="3.5" x2="12" y2="16.5"/></svg>`;
|
|
39
|
+
|
|
40
|
+
export const ICON_CODE_PROMPT = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2.5" y="3.5" width="15" height="13" rx="2"/><polyline points="6.5 8 9.2 10 6.5 12"/><line x1="10.8" y1="12" x2="13.8" y2="12"/></svg>`;
|
|
41
|
+
|
|
42
|
+
export const ICON_KEY = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="7" cy="12" r="3.5"/><path d="M9.6 9.4L16.5 2.5"/><path d="M14 5l2.2 2.2"/><path d="M12 7l1.8 1.8"/></svg>`;
|
|
43
|
+
|
|
44
|
+
export const ICON_FILE_CODE = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M11.5 2.5H5.5a1.5 1.5 0 0 0-1.5 1.5v12a1.5 1.5 0 0 0 1.5 1.5h9a1.5 1.5 0 0 0 1.5-1.5V7l-4.5-4.5z"/><polyline points="11.5 2.5 11.5 7 16 7"/><polyline points="8.2 10.5 6.5 12 8.2 13.5"/><polyline points="11.8 10.5 13.5 12 11.8 13.5"/></svg>`;
|
|
45
|
+
|
|
46
|
+
export const ICON_SEARCH = `<svg viewBox="0 0 20 20" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="9" cy="9" r="5.5"/><line x1="13" y1="13" x2="17" y2="17"/></svg>`;
|
|
47
|
+
|
|
48
|
+
export const ICON_PLUS = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="8" y1="3.5" x2="8" y2="12.5"/><line x1="3.5" y1="8" x2="12.5" y2="8"/></svg>`;
|
|
49
|
+
|
|
50
|
+
export const ICON_UNDO = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="5.5 4.5 2.5 7.5 5.5 10.5"/><path d="M2.5 7.5h7.2a3.8 3.8 0 0 1 0 7.6H8.5"/></svg>`;
|
|
51
|
+
|
|
52
|
+
export const ICON_INBOX = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 11.5L5.2 4.5h9.6l1.7 7v4a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1v-4z"/><path d="M3.5 11.5h3.8l1.2 2h3l1.2-2h3.8"/></svg>`;
|
|
53
|
+
|
|
54
|
+
export const ICON_SHIELD = `<svg viewBox="0 0 20 20" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 2.5l6 2.3v4.7c0 4.1-2.6 6.8-6 8-3.4-1.2-6-3.9-6-8V4.8l6-2.3z"/></svg>`;
|
|
55
|
+
|
|
56
|
+
export const ICON_PUSH_LAYOUT = `<svg viewBox="0 0 16 16" width="13" height="13" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="2.5" width="12" height="11" rx="1.8"/><line x1="9.5" y1="2.5" x2="9.5" y2="13.5"/><polyline points="6.5 6.2 4.7 8 6.5 9.8"/></svg>`;
|
|
57
|
+
|
|
58
|
+
export const ICON_SUN = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="10" cy="10" r="3.75"/><line x1="10" y1="2" x2="10" y2="4"/><line x1="10" y1="16" x2="10" y2="18"/><line x1="2" y1="10" x2="4" y2="10"/><line x1="16" y1="10" x2="18" y2="10"/><line x1="4.34" y1="4.34" x2="5.75" y2="5.75"/><line x1="14.25" y1="14.25" x2="15.66" y2="15.66"/><line x1="4.34" y1="15.66" x2="5.75" y2="14.25"/><line x1="14.25" y1="5.75" x2="15.66" y2="4.34"/></svg>`;
|
|
59
|
+
|
|
60
|
+
export const ICON_MOON = `<svg viewBox="0 0 20 20" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17.2 12.8A7.5 7.5 0 0 1 7.2 2.8a7.5 7.5 0 1 0 10 10z"/></svg>`;
|
|
61
|
+
|