Commit 796de4d
authored
fix(core): merge IDE context into user prompt (#3980)
* fix(core): merge IDE context into user prompt
IDE mode now wraps editor context in a <system-reminder> block and
prepends it to the current user request instead of inserting a separate
user history entry via addHistory(). This preserves the API history
turn shape and avoids extra user turns in IDE mode.
Key changes:
- IDE context merged into user request via prependToFirstTextPart()
- State update deferred until after arena cancellation check
- escapeClosingSystemReminderTags() hardens against tag injection
including zero-width/control character variants
- forceFullIdeContext reset on stream errors for correct resend
- Context prompt updated to encourage active use of editor context
Refs #3712
* fix(core): restore BaseLlmClient per-model cache clear on session reset
resetChat only cleared GeminiClient's new perModelGeneratorCache but
dropped the BaseLlmClient.clearPerModelGeneratorCache() call that was
present before the refactoring. sideQuery.ts and sessionTitle.ts still
route through BaseLlmClient with the fast model, so stale generators
survived session reset.
* refactor(core): remove duplicated per-model generator code from GeminiClient
The per-model ContentGenerator resolution logic (resolveModelAcrossAuthTypes,
createRetryAuthTypeForModel, createContentGeneratorForModel, perModelGeneratorCache)
was inadvertently duplicated from BaseLlmClient into GeminiClient. This restores
the original one-line delegation to BaseLlmClient.resolveForModel() and removes
~130 lines of redundant code to keep the PR focused on IDE context merging only.
* fix(core): harden IDE context reminder escaping
* fix(core): defer IDE context baseline update
* fix(core): use shared escapeSystemReminderTags in tool scheduler
Aligns the rule-activation envelope scrub with the IDE-context path —
both now route through `escapeSystemReminderTags`, which neutralizes
whitespace, zero-width, and control-character variants of
`<system-reminder>` tag boundaries. The previous narrow regex only
matched the literal `</system-reminder>` sequence, so a rule body
containing `</system-reminder >`, `</ system-reminder>`, or
`</system-reminder>` could still close the envelope mid-content.
* docs(core): clarify request assembly order in IDE merge path
Two adjacent comments described the pre-merge model: one called
the system-reminder block "append" while the code prepends, and the
tryCompressChat note still talked about "the previous context turn"
which no longer exists once IDE context is merged into the user
prompt. Rewrite both to match what the code actually does so future
readers do not get a misleading mental model of prompt assembly or
post-compression resend behavior.
* docs(core): align scheduler scrub comment with shared helper
The block-level comment still labeled the sanitization step as
"closing-tag scrub", which described the old narrow regex. The
shared escapeSystemReminderTags helper now neutralizes opening /
self-closing / obfuscated variants too, so name the helper directly
to keep the rationale and the call site in agreement.
* test(core): cover escapeSystemReminderTags variants in scheduler
The end-to-end scheduler scrub test only exercised a literal
</system-reminder> body. Now that the rule-activation envelope routes
through escapeSystemReminderTags, extend the integration coverage to
the obfuscated closing-tag variants the helper was introduced to
catch (whitespace before/after the slash, ZWSP / WJ / VS-16 inside
the name) and to opening-tag injection. Each case asserts that the
envelope still has exactly one </system-reminder> closer and that the
raw obfuscated form (or unescaped opening tag) does not survive into
the model-facing payload.
Refactor the existing test's mock setup into a shared
runSchedulerWithRule helper so the new it.each variants stay
focused on the assertion shape.
* fix(core): address remaining review feedback
- Add debug log when IDE context parts are empty for diagnosability
- Add safety comment in xml.ts explaining why no fast-path pre-check
is used in getSystemReminderTagKind (zero-width obfuscation bypass)1 parent 3cc66f9 commit 796de4d
8 files changed
Lines changed: 757 additions & 108 deletions
File tree
- packages/core/src
- core
- utils
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
| |||
579 | 588 | | |
580 | 589 | | |
581 | 590 | | |
582 | | - | |
| 591 | + | |
583 | 592 | | |
584 | 593 | | |
585 | 594 | | |
| |||
709 | 718 | | |
710 | 719 | | |
711 | 720 | | |
712 | | - | |
| 721 | + | |
713 | 722 | | |
714 | 723 | | |
715 | 724 | | |
| |||
1135 | 1144 | | |
1136 | 1145 | | |
1137 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1138 | 1150 | | |
1139 | 1151 | | |
1140 | 1152 | | |
1141 | 1153 | | |
1142 | 1154 | | |
1143 | 1155 | | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1148 | 1164 | | |
1149 | | - | |
1150 | | - | |
1151 | 1165 | | |
1152 | 1166 | | |
1153 | 1167 | | |
| |||
1171 | 1185 | | |
1172 | 1186 | | |
1173 | 1187 | | |
1174 | | - | |
1175 | | - | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1176 | 1193 | | |
1177 | 1194 | | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
1178 | 1198 | | |
1179 | 1199 | | |
1180 | 1200 | | |
| |||
1228 | 1248 | | |
1229 | 1249 | | |
1230 | 1250 | | |
1231 | | - | |
| 1251 | + | |
1232 | 1252 | | |
1233 | 1253 | | |
1234 | | - | |
| 1254 | + | |
| 1255 | + | |
1235 | 1256 | | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
1236 | 1263 | | |
1237 | 1264 | | |
1238 | 1265 | | |
| |||
1257 | 1284 | | |
1258 | 1285 | | |
1259 | 1286 | | |
1260 | | - | |
| 1287 | + | |
1261 | 1288 | | |
1262 | 1289 | | |
1263 | 1290 | | |
1264 | 1291 | | |
1265 | 1292 | | |
1266 | 1293 | | |
| 1294 | + | |
1267 | 1295 | | |
1268 | 1296 | | |
1269 | 1297 | | |
| |||
1605 | 1633 | | |
1606 | 1634 | | |
1607 | 1635 | | |
1608 | | - | |
| 1636 | + | |
| 1637 | + | |
1609 | 1638 | | |
1610 | 1639 | | |
1611 | 1640 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5766 | 5766 | | |
5767 | 5767 | | |
5768 | 5768 | | |
5769 | | - | |
5770 | | - | |
5771 | | - | |
5772 | | - | |
5773 | | - | |
| 5769 | + | |
| 5770 | + | |
| 5771 | + | |
| 5772 | + | |
| 5773 | + | |
5774 | 5774 | | |
5775 | | - | |
5776 | | - | |
5777 | | - | |
5778 | | - | |
5779 | | - | |
| 5775 | + | |
5780 | 5776 | | |
5781 | 5777 | | |
5782 | 5778 | | |
| |||
5854 | 5850 | | |
5855 | 5851 | | |
5856 | 5852 | | |
5857 | | - | |
| 5853 | + | |
5858 | 5854 | | |
5859 | 5855 | | |
5860 | 5856 | | |
| 5857 | + | |
| 5858 | + | |
| 5859 | + | |
| 5860 | + | |
| 5861 | + | |
| 5862 | + | |
| 5863 | + | |
| 5864 | + | |
| 5865 | + | |
| 5866 | + | |
| 5867 | + | |
5861 | 5868 | | |
5862 | 5869 | | |
5863 | 5870 | | |
| |||
5869 | 5876 | | |
5870 | 5877 | | |
5871 | 5878 | | |
| 5879 | + | |
| 5880 | + | |
| 5881 | + | |
| 5882 | + | |
| 5883 | + | |
| 5884 | + | |
| 5885 | + | |
| 5886 | + | |
| 5887 | + | |
| 5888 | + | |
| 5889 | + | |
| 5890 | + | |
| 5891 | + | |
| 5892 | + | |
| 5893 | + | |
| 5894 | + | |
| 5895 | + | |
| 5896 | + | |
| 5897 | + | |
| 5898 | + | |
| 5899 | + | |
| 5900 | + | |
| 5901 | + | |
| 5902 | + | |
| 5903 | + | |
| 5904 | + | |
| 5905 | + | |
| 5906 | + | |
| 5907 | + | |
| 5908 | + | |
| 5909 | + | |
| 5910 | + | |
| 5911 | + | |
| 5912 | + | |
| 5913 | + | |
| 5914 | + | |
| 5915 | + | |
| 5916 | + | |
| 5917 | + | |
| 5918 | + | |
| 5919 | + | |
| 5920 | + | |
| 5921 | + | |
| 5922 | + | |
| 5923 | + | |
| 5924 | + | |
| 5925 | + | |
| 5926 | + | |
| 5927 | + | |
| 5928 | + | |
| 5929 | + | |
| 5930 | + | |
| 5931 | + | |
| 5932 | + | |
| 5933 | + | |
| 5934 | + | |
| 5935 | + | |
| 5936 | + | |
| 5937 | + | |
| 5938 | + | |
| 5939 | + | |
| 5940 | + | |
| 5941 | + | |
| 5942 | + | |
| 5943 | + | |
| 5944 | + | |
| 5945 | + | |
| 5946 | + | |
| 5947 | + | |
| 5948 | + | |
| 5949 | + | |
5872 | 5950 | | |
5873 | 5951 | | |
5874 | 5952 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
2077 | 2077 | | |
2078 | 2078 | | |
2079 | 2079 | | |
2080 | | - | |
| 2080 | + | |
2081 | 2081 | | |
2082 | 2082 | | |
2083 | 2083 | | |
| |||
2123 | 2123 | | |
2124 | 2124 | | |
2125 | 2125 | | |
2126 | | - | |
2127 | | - | |
2128 | | - | |
2129 | | - | |
2130 | | - | |
2131 | | - | |
2132 | | - | |
2133 | | - | |
2134 | | - | |
2135 | | - | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
2136 | 2138 | | |
2137 | 2139 | | |
2138 | 2140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
298 | 299 | | |
299 | 300 | | |
300 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
301 | 343 | | |
0 commit comments