Commit 6421994
committed
refactor(chat): clean up highlight-to-chat selections
Correctness:
- Stop reporting fabricated line numbers for rich-markdown selections.
`doc.textBetween` counts ProseMirror block boundaries, not markdown source
lines, so the chip label and the agent prompt both claimed line ranges that
don't exist in the file. Line info is now emitted only by Monaco.
- Bound a table_selection's rendered markdown by characters, not just row and
column counts — 500 wide rows dwarfed the 20k-char file-selection budget.
Rows are emitted until the budget is spent, and the content says what was
omitted.
- Complete `areContextsEqual` for both selection kinds, so re-adding the same
selection dedupes while a different passage of an already-referenced file
registers as new.
Consistency:
- Carry the resource display name on the context instead of recovering it by
regex from the chip label, deleting fileNameFromSelectionLabel and
tableNameFromSelectionLabel.
- Replace the user-visible `#k3f9` hash disambiguator with a readable ordinal
applied at insert time (`Sales (3 rows) (2)`), via a shared
prepareContextForInsert used by both the add-to-chat and paste paths.
- Fold MothershipPendingContextStorage into MothershipHandoffStorage as a
chip-only handoff (optional message), removing the parallel storage class,
the second drain effect, and its StrictMode guard ref.
- Replace `window.location.assign` with `router.push`, matching the existing
"Troubleshoot in Chat" handoff.
- Collapse three near-duplicate synchronous copy branches in table-grid into
shared buildTableSelectionContext / writeLoadedRowsWithChip helpers, also
reused by the add-to-chat handler.
- Trim multi-paragraph inline comments to TSDoc stating each reason once.
Tests: new coverage for the character budget, the label ordinal, selection
equality, and chip-only handoff accumulation; each verified to fail when its
fix is reverted.1 parent 27dbd17 commit 6421994
24 files changed
Lines changed: 663 additions & 447 deletions
File tree
- apps/sim
- app/workspace/[workspaceId]
- files/components/file-viewer
- rich-markdown-editor
- home
- components
- chat-context-kind-registry
- user-input/components
- prompt-editor
- hooks
- tables/[tableId]/components/table-grid
- w/[workflowId]/components/panel/components/copilot/components/user-input
- hooks
- lib
- copilot/chat
- core/utils
- mothership
- stores/panel
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
1133 | 1132 | | |
1134 | 1133 | | |
1135 | 1134 | | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
1136 | 1142 | | |
1137 | 1143 | | |
1138 | 1144 | | |
1139 | 1145 | | |
1140 | 1146 | | |
1141 | 1147 | | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | 1148 | | |
1147 | 1149 | | |
1148 | 1150 | | |
1149 | | - | |
| 1151 | + | |
| 1152 | + | |
1150 | 1153 | | |
1151 | | - | |
1152 | | - | |
1153 | 1154 | | |
1154 | 1155 | | |
1155 | 1156 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
395 | 394 | | |
396 | 395 | | |
397 | 396 | | |
398 | | - | |
| 397 | + | |
| 398 | + | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| |||
Lines changed: 7 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
16 | 14 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
| |||
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/chip-clipboard-codec.ts
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| |||
Lines changed: 22 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
482 | 483 | | |
483 | 484 | | |
484 | 485 | | |
| |||
487 | 488 | | |
488 | 489 | | |
489 | 490 | | |
490 | | - | |
| 491 | + | |
491 | 492 | | |
492 | | - | |
493 | 493 | | |
494 | | - | |
| 494 | + | |
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
926 | | - | |
927 | | - | |
928 | | - | |
929 | | - | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
934 | | - | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
935 | 931 | | |
936 | 932 | | |
937 | 933 | | |
938 | | - | |
| 934 | + | |
939 | 935 | | |
940 | | - | |
941 | 936 | | |
942 | | - | |
943 | | - | |
944 | | - | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
945 | 940 | | |
946 | 941 | | |
947 | 942 | | |
| |||
1038 | 1033 | | |
1039 | 1034 | | |
1040 | 1035 | | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
1049 | 1040 | | |
1050 | 1041 | | |
1051 | 1042 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 22 | | |
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
30 | 26 | | |
31 | 27 | | |
32 | | - | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
| |||
335 | 330 | | |
336 | 331 | | |
337 | 332 | | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
343 | 341 | | |
344 | 342 | | |
345 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
346 | 349 | | |
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
370 | 359 | | |
371 | 360 | | |
372 | 361 | | |
373 | | - | |
374 | | - | |
| 362 | + | |
| 363 | + | |
375 | 364 | | |
376 | 365 | | |
377 | 366 | | |
| |||
396 | 385 | | |
397 | 386 | | |
398 | 387 | | |
399 | | - | |
400 | | - | |
401 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
402 | 391 | | |
403 | 392 | | |
404 | | - | |
405 | | - | |
| 393 | + | |
| 394 | + | |
406 | 395 | | |
407 | 396 | | |
408 | 397 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
325 | 326 | | |
326 | 327 | | |
327 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
328 | 333 | | |
329 | 334 | | |
330 | 335 | | |
| |||
3231 | 3236 | | |
3232 | 3237 | | |
3233 | 3238 | | |
| 3239 | + | |
3234 | 3240 | | |
3235 | 3241 | | |
3236 | 3242 | | |
3237 | 3243 | | |
3238 | 3244 | | |
3239 | 3245 | | |
3240 | 3246 | | |
| 3247 | + | |
3241 | 3248 | | |
3242 | 3249 | | |
3243 | 3250 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
| 158 | + | |
| 159 | + | |
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
| |||
0 commit comments