ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / xtab / test / common / promptCrafting.spec.ts 1190 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
import { assert, describe, expect, it, suite, test } from 'vitest' ;
import { DocumentId } from '../../../../platform/inlineEdits/common/dataTypes/documentId' ;
import { Edits } from '../../../../platform/inlineEdits/common/dataTypes/edit' ;
import { LanguageId } from '../../../../platform/inlineEdits/common/dataTypes/languageId' ;
import { AggressivenessLevel, CurrentFileOptions, DEFAULT_OPTIONS , GlobalBudgetOptions, IncludeLineNumbersOption, PromptingStrategy, PromptOptions, RejectedEditsMemoryMode } from '../../../../platform/inlineEdits/common/dataTypes/xtabPromptOptions' ;
LanguageContextResponse
PromptSectionTokenCounts
ContextKind
StatelessNextEditDocument
IXtabHistoryRejectedEditEntry
TestLanguageDiagnosticsService
Result
LineEdit
StringEdit
Position
OffsetRange
StringText
Uri
LintErrors
constructTaggedFile createTaggedCurrentFileContentUsingPagedClipping expandRangeToPageRange getUserPrompt PromptPieces runGlobalBudgetCascade
PromptTags
CurrentDocument
n StringText
n _ i
s
Math s length
s
nDocLines
docLines nDocLines
r
docLines
computeTokens
r
nDocLines
docLines nDocLines
r
docLines
computeTokens
r
nDocLines
docLines nDocLines
r
docLines
computeTokens
r
nDocLines
docLines nDocLines
r
docLines
computeTokens
r
opts CurrentFileOptions currentFile
currentDocLines
areaAroundCodeToEdit
areaAroundEditWindowLinesRange OffsetRange
s
pageSize
opts CurrentFileOptions
Result
currentDocLines
areaAroundCodeToEdit
areaAroundEditWindowLinesRange
computeTokens
pageSize
opts
taggedCurrentFileContent taggedCurrentFileContent lines
docLines
areaAroundCodeToEdit
result
docLines
areaAroundCodeToEdit
computeTokens
opts maxTokens
result
taggedCurrentFileContent result val
taggedCurrentFileContent
docLines
areaAroundCodeToEdit
result
docLines
areaAroundCodeToEdit
computeTokens
opts maxTokens
result
taggedCurrentFileContent result val
taggedCurrentFileContent
docLines
areaAroundCodeToEdit
result
docLines
areaAroundCodeToEdit
computeTokens
opts maxTokens useLeftoverBudgetFromAbove
result
taggedCurrentFileContent result val
taggedCurrentFileContent
content cursorLine cursorColumn CurrentDocument
content
cursorLine cursorColumn
defaultPromptOptions PromptOptions
currentFile
currentFile
maxTokens
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption None
result
clippedTaggedCurrentDoc areaAroundCodeToEdit result val
clippedTaggedCurrentDoc lines
areaAroundCodeToEdit
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption None
result
clippedTaggedCurrentDoc areaAroundCodeToEdit result val
clippedTaggedCurrentDoc lines
areaAroundCodeToEdit
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption None
result
result val clippedTaggedCurrentDoc lines
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption WithSpaceAfter
result
result val clippedTaggedCurrentDoc lines
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption WithoutSpace
result
result val clippedTaggedCurrentDoc lines
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption None
result
result val clippedTaggedCurrentDoc lines
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers areaAroundCodeToEdit IncludeLineNumbersOption None currentFileContent IncludeLineNumbersOption WithSpaceAfter
result
result val clippedTaggedCurrentDoc lines
content
doc content
result
doc
defaultPromptOptions
currentFile defaultPromptOptions currentFile includeCursorTag includeTags
computeTokens
includeLineNumbers
areaAroundCodeToEdit IncludeLineNumbersOption WithSpaceAfter
currentFileContent IncludeLineNumbersOption WithoutSpace
result
result val areaAroundCodeToEdit
result val clippedTaggedCurrentDoc lines
opts
cursorLine
cursorColumn
strategy PromptingStrategy
includeLineNumbers IncludeLineNumbersOption
includePostScript
eagernessPrompt
aggressivenessLevel AggressivenessLevel
rejectedEditsMemory RejectedEditsMemoryMode
PromptPieces
currentDocLines
docText currentDocLines
documentId DocumentId
currentDocument docText opts cursorLine opts cursorColumn
activeDoc
documentId
LanguageId
currentDocLines
LineEdit empty
docText
StringEdit
promptOptions PromptOptions
promptingStrategy opts strategy
eagernessPrompt opts eagernessPrompt
opts includePostScript includePostScript opts includePostScript
opts rejectedEditsMemory memory rejectedEdits opts rejectedEditsMemory
currentFile
currentFile
maxTokens
opts includeLineNumbers includeLineNumbers opts includeLineNumbers
rejectedEditHistory IXtabHistoryRejectedEditEntry
kind
docId documentId
hunks startLineNumber oldLines newLines
ordinal
currentDocument
activeDoc
currentDocLines
opts aggressivenessLevel AggressivenessLevel Medium
documentId currentDocument
s Math s length
promptOptions
rejectedEditHistory
pieces cursorLine cursorColumn strategy PromptingStrategy PatchBased02
prompt pieces
prompt PromptTags start
prompt PromptTags end
prompt PromptTags
prompt PromptTags
prompt not
prompt not
prompt
prompt not
pieces
cursorLine
cursorColumn
strategy PromptingStrategy PatchBased02
rejectedEditsMemory RejectedEditsMemoryMode DiffWithTags
prompt pieces
prompt
prompt
pieces
cursorLine
cursorColumn
strategy PromptingStrategy PatchBased02WithRecentLineNumbers
rejectedEditsMemory RejectedEditsMemoryMode DiffWithTags
prompt pieces
prompt
prompt
pieces
cursorLine
cursorColumn
strategy PromptingStrategy PatchBased02
rejectedEditsMemory RejectedEditsMemoryMode DiffWithTags
includePostScript
prompt pieces
prompt
prompt
prompt not
pieces cursorLine cursorColumn strategy PromptingStrategy PatchBased02 includePostScript
prompt pieces
prompt PromptTags start
prompt PromptTags end
prompt PromptTags
prompt not
prompt not
prompt not
pieces cursorLine cursorColumn strategy PromptingStrategy PatchBased01
prompt pieces
prompt not PromptTags start
prompt not
prompt not
pieces cursorLine cursorColumn strategy
prompt pieces
prompt
prompt
prompt not PromptTags start
pieces cursorLine cursorColumn strategy PromptingStrategy PatchBased02
prompt pieces
prompt PromptTags
pieces cursorLine cursorColumn strategy PromptingStrategy PatchBased02
prompt pieces
prompt PromptTags
pieces
cursorLine cursorColumn
strategy PromptingStrategy PatchBased02
includeLineNumbers IncludeLineNumbersOption WithSpaceAfter
prompt pieces
prompt PromptTags
pieces
cursorLine cursorColumn
strategy PromptingStrategy PatchBased02
includeLineNumbers IncludeLineNumbersOption WithoutSpace
prompt pieces
prompt PromptTags
pieces
cursorLine cursorColumn
strategy PromptingStrategy PatchBased02
includeLineNumbers IncludeLineNumbersOption None
prompt pieces
prompt PromptTags start PromptTags PromptTags end
test
AggressivenessLevel Medium
AggressivenessLevel High
AggressivenessLevel Low
aggressivenessLevel aggressionTag
pieces
cursorLine
cursorColumn
strategy PromptingStrategy PatchBased02
eagernessPrompt
aggressivenessLevel
prompt pieces
cursorLocation
postScript
prompt cursorLocation
prompt cursorLocation prompt postScript
aggressivenessLevel AggressivenessLevel Medium
prompt not
prompt
prompt
pieces
cursorLine cursorColumn
strategy PromptingStrategy Xtab275AggressivenessHighLow
aggressivenessLevel AggressivenessLevel Medium
prompt pieces
prompt
prompt not
prompt not
pieces
cursorLine cursorColumn
strategy PromptingStrategy Xtab275AggressivenessHighLow
aggressivenessLevel AggressivenessLevel High
prompt pieces
prompt
pieces
cursorLine cursorColumn
strategy PromptingStrategy Xtab275AggressivenessHighLow
aggressivenessLevel AggressivenessLevel Low
prompt pieces
prompt
pieces
cursorLine cursorColumn
strategy PromptingStrategy Xtab275AggressivenessHighLow
aggressivenessLevel AggressivenessLevel High
prompt pieces
prompt
pieces
cursorLine cursorColumn
strategy PromptingStrategy Xtab275Aggressiveness
aggressivenessLevel AggressivenessLevel Medium
prompt pieces
prompt
sectionsSum t PromptSectionTokenCounts
t recentlyViewed t currentFile t lintErrors t editHistory
t areaAroundCodeToEdit t cursorLocation t relatedInformation t postScript
summary PromptingStrategy PatchBased01 PromptingStrategy PatchBased02 strategy
prompt sectionTokens cursorLine cursorColumn strategy
totalMatchesPrompt sectionTokens userPromptTotal prompt
reconciles sectionTokens sectionTokens overhead sectionTokens userPromptTotal
systemPromptZero sectionTokens systemPrompt
assert summary
totalMatchesPrompt reconciles systemPromptZero
totalMatchesPrompt reconciles systemPromptZero
totalMatchesPrompt reconciles systemPromptZero
strategy PromptingStrategy
sectionTokens cursorLine cursorColumn strategy
areaPresent sectionTokens areaAroundCodeToEdit cursorPresent sectionTokens cursorLocation
assert
patchBased01 PromptingStrategy PatchBased01
patchBased02 PromptingStrategy PatchBased02
patchBased01 areaPresent cursorPresent
patchBased02 areaPresent cursorPresent
areaPresent cursorPresent
withPostScript cursorLine cursorColumn strategy PromptingStrategy PatchBased02 sectionTokens
withoutPostScript cursorLine cursorColumn strategy PromptingStrategy PatchBased02 includePostScript sectionTokens
assert
relatedInformation withPostScript relatedInformation
currentFilePresent withPostScript currentFile
postScriptPresent withPostScript postScript
postScriptAbsent withoutPostScript postScript
relatedInformation
currentFilePresent
postScriptPresent
postScriptAbsent
activeDoc StatelessNextEditDocument currentDocument CurrentDocument currentDocLines
currentDocLines
docText currentDocLines
documentId DocumentId
currentDocument docText
activeDoc
documentId
LanguageId
currentDocLines
LineEdit empty
docText
StringEdit
activeDoc currentDocument currentDocLines
globalBudget PromptOptions extra langCtx LanguageContextResponse precomputedCascade ReturnType runGlobalBudgetCascade PromptPieces
activeDoc currentDocument currentDocLines
promptOptions PromptOptions
currentFile currentFile maxTokens
globalBudget
currentDocument
activeDoc
currentDocLines
extra langCtx
AggressivenessLevel Medium
activeDoc id currentDocument
s Math s length
promptOptions
extra precomputedCascade
value LanguageContextResponse
start
end
items
context kind ContextKind Snippet priority uri Uri value
timeStamp
onTimeout
legacy
cascaded
totalTokens
order GlobalBudgetOptions
shares GlobalBudgetOptions
cascaded prompt legacy prompt
cascaded nDiffsInPrompt legacy nDiffsInPrompt
pieces
totalTokens
order
shares GlobalBudgetOptions
pieces
pieces
totalTokens
order
shares GlobalBudgetOptions
pieces
pieces
totalTokens
order GlobalBudgetOptions
shares
currentFile
recentlyViewedDocuments
languageContext
neighborFiles
diffHistory
pieces
pieces
totalTokens
order GlobalBudgetOptions
shares
currentFile
languageContext
recentlyViewedDocuments
neighborFiles
Record
pieces
pieces
totalTokens
order GlobalBudgetOptions
shares
languageContext
recentlyViewedDocuments
neighborFiles
diffHistory
Record
pieces
globalBudget GlobalBudgetOptions extra langCtx LanguageContextResponse
activeDoc
opts PromptOptions globalBudget
activeDoc extra langCtx s Math s length opts globalBudget
cascade
totalTokens GlobalBudgetOptions
order GlobalBudgetOptions
shares GlobalBudgetOptions
cascade finalSurplus
globalBudget GlobalBudgetOptions
totalTokens GlobalBudgetOptions
order GlobalBudgetOptions
shares GlobalBudgetOptions
empty globalBudget
consuming globalBudget langCtx
consuming finalSurplus empty finalSurplus
snippet
globalBudget PromptOptions
totalTokens
order GlobalBudgetOptions
shares GlobalBudgetOptions
internal globalBudget langCtx snippet
cascade globalBudget langCtx snippet
precomputed globalBudget langCtx snippet precomputedCascade cascade
precomputed prompt internal prompt
precomputed nDiffsInPrompt internal nDiffsInPrompt
snippet
globalBudget PromptOptions
totalTokens
order GlobalBudgetOptions
shares GlobalBudgetOptions
cascaded globalBudget langCtx snippet sectionTokens recentlyViewedSubsections
legacy langCtx snippet sectionTokens recentlyViewedSubsections
assert
recentlyViewedFilesZero cascaded recentlyViewedFiles
languageContextPopulated cascaded languageContext
neighborFilesZero cascaded neighborFiles
legacyEqualsCascade legacy cascaded
recentlyViewedFilesZero
languageContextPopulated
neighborFilesZero
legacyEqualsCascade
import
{
}
from
'../../../../platform/inlineEdits/common/dataTypes/languageContext'
;
import
{
}
from
'../../../../platform/inlineEdits/common/dataTypes/promptSectionTokens'
;
import
{
}
from
'../../../../platform/languageServer/common/languageContextService'
;
import
{
}
from
'../../../../platform/inlineEdits/common/statelessNextEditProvider'
;
import
{
}
from
'../../../../platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker'
;
import
{
}
from
'../../../../platform/languages/common/testLanguageDiagnosticsService'
;
import
{
}
from
'../../../../util/common/result'
;
import
{
}
from
'../../../../util/vs/editor/common/core/edits/lineEdit'
;
import
{
}
from
'../../../../util/vs/editor/common/core/edits/stringEdit'
;
import
{
}
from
'../../../../util/vs/editor/common/core/position'
;
import
{
}
from
'../../../../util/vs/editor/common/core/ranges/offsetRange'
;
import
{
}
from
'../../../../util/vs/editor/common/core/text/abstractText'
;
import
{
}
from
'../../../../vscodeTypes'
;
import
{
}
from
'../../common/lintErrors'
;
import
{
,
,
,
,
,
}
from
'../../common/promptCrafting'
;
import
{
}
from
'../../common/tags'
;
import
{
}
from
'../../common/xtabCurrentDocument'
;
function
nLines
(
:
number
)
:
{
return
new
StringText
(
new
Array
(
)
.
fill
(
0
)
.
map
(
(
,
)
=>
` ${ i + 1 } `
)
.
join
(
'\n'
)
)
;
}
function
computeTokens
(
:
string
)
{
return
.
ceil
(
.
/
4
)
;
}
describe
(
'expandRangeToPageRange'
,
(
)
=>
{
const
PAGE_SIZE
=
10
;
const
UNLIM_BUDGET
=
10000
;
const
computeTokens
=
(
:
string
)
=>
0
;
it
(
'expands correctly when budget is only for two touched pages'
,
(
)
=>
{
const
=
47
;
const
=
nLines
(
)
.
getLines
(
)
;
const
=
expandRangeToPageRange
(
,
new
OffsetRange
(
11
,
22
)
,
PAGE_SIZE
,
2
*
PAGE_SIZE
,
,
false
,
false
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
{
"budgetLeft": 0,
"firstPageIdx": 1,
"lastPageIdxIncl": 2,
}
`
)
;
}
)
;
it
(
'expands correctly to the whole document'
,
(
)
=>
{
const
=
47
;
const
=
nLines
(
)
.
getLines
(
)
;
const
=
expandRangeToPageRange
(
,
new
OffsetRange
(
11
,
22
)
,
PAGE_SIZE
,
UNLIM_BUDGET
,
,
false
,
false
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
{
"budgetLeft": 4973,
"firstPageIdx": 0,
"lastPageIdxIncl": 4,
}
`
)
;
}
)
;
it
(
'does not donate leftover above-cursor budget to below-cursor by default'
,
(
)
=>
{
const
=
47
;
const
=
nLines
(
)
.
getLines
(
)
;
const
=
expandRangeToPageRange
(
,
new
OffsetRange
(
0
,
1
)
,
PAGE_SIZE
,
40
,
,
false
,
false
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
{
"budgetLeft": 5,
"firstPageIdx": 0,
"lastPageIdxIncl": 1,
}
`
)
;
}
)
;
it
(
'donates leftover above-cursor budget to below-cursor when enabled'
,
(
)
=>
{
const
=
47
;
const
=
nLines
(
)
.
getLines
(
)
;
const
=
expandRangeToPageRange
(
,
new
OffsetRange
(
0
,
1
)
,
PAGE_SIZE
,
40
,
,
false
,
true
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
{
"budgetLeft": 0,
"firstPageIdx": 0,
"lastPageIdxIncl": 3,
}
`
)
;
}
)
;
}
)
;
suite
(
'Paged clipping - current file'
,
(
)
=>
{
const
:
=
DEFAULT_OPTIONS
.
;
function
createTaggedFile
(
:
string
[
]
,
:
string
,
:
,
computeTokens
:
(
:
string
)
=>
number
,
:
number
,
:
,
)
:
<
string
,
'outOfBudget'
>
{
return
createTaggedCurrentFileContentUsingPagedClipping
(
,
.
split
(
'\n'
)
,
,
,
,
)
.
map
(
=>
.
.
join
(
'\n'
)
)
;
}
test
(
'unlim budget - includes whole context'
,
(
)
=>
{
const
=
nLines
(
40
)
;
const
=
`
<area_around_code_to_edit>
22
23
<code_to_edit>
24
25
<code_to_edit>
26
</area_around_code_to_edit>
`
.
trim
(
)
;
const
=
createTaggedFile
(
.
getLines
(
)
,
,
new
OffsetRange
(
21
,
26
)
,
,
10
,
{
...
,
:
2000
}
)
;
assert
(
.
isOk
(
)
)
;
const
=
.
;
expect
(
)
.
toMatchInlineSnapshot
(
`
"1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<area_around_code_to_edit>
22
23
<code_to_edit>
24
25
<code_to_edit>
26
</area_around_code_to_edit>
27
28
29
30
31
32
33
34
35
36
37
38
39
40"
`
)
;
}
)
;
test
(
'budget of 20'
,
(
)
=>
{
const
=
nLines
(
40
)
;
const
=
`
<area_around_code_to_edit>
22
23
<code_to_edit>
24
25
<code_to_edit>
26
</area_around_code_to_edit>
`
.
trim
(
)
;
const
=
createTaggedFile
(
.
getLines
(
)
,
,
new
OffsetRange
(
21
,
26
)
,
,
10
,
{
...
,
:
20
}
,
)
;
assert
(
.
isOk
(
)
)
;
const
=
.
;
expect
(
)
.
toMatchInlineSnapshot
(
`
"21
<area_around_code_to_edit>
22
23
<code_to_edit>
24
25
<code_to_edit>
26
</area_around_code_to_edit>
27
28
29
30"
`
)
;
}
)
;
test
(
'context above and below get same # of tokens'
,
(
)
=>
{
const
=
nLines
(
40
)
;
const
=
`
<a>
11
12
<b>
13
</b>
14
</a>
`
.
trim
(
)
;
const
=
createTaggedFile
(
.
getLines
(
)
,
,
new
OffsetRange
(
10
,
14
)
,
,
10
,
{
...
,
:
50
,
:
false
}
)
;
assert
(
.
isOk
(
)
)
;
const
=
.
;
expect
(
)
.
toMatchInlineSnapshot
(
`
"<a>
11
12
<b>
13
</b>
14
</a>
15
16
17
18
19
20"
`
)
;
}
)
;
}
)
;
suite
(
'constructTaggedFile'
,
(
)
=>
{
function
createDocument
(
:
string
,
:
number
,
:
number
)
:
{
return
new
CurrentDocument
(
new
StringText
(
)
,
new
Position
(
,
)
)
;
}
const
:
=
{
...
DEFAULT_OPTIONS
,
:
{
...
DEFAULT_OPTIONS
.
,
:
10000
,
}
}
;
suite
(
'includeCursorTag option'
,
(
)
=>
{
test
(
'cursor tag appears in current file content when includeCursorTag is true'
,
(
)
=>
{
const
=
'line1\nline2\nline3\nline4\nline5'
;
const
=
createDocument
(
,
3
,
3
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
1
,
4
)
,
new
OffsetRange
(
0
,
5
)
,
{
...
,
:
{
...
.
,
:
true
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
const
{
,
}
=
.
;
expect
(
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"line1
line2
li<|cursor|>ne3
line4
line5"
`
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
"<|area_around_code_to_edit|>
line1
<|code_to_edit|>
line2
li<|cursor|>ne3
line4
<|/code_to_edit|>
line5
<|/area_around_code_to_edit|>"
`
)
;
}
)
;
test
(
'cursor tag does NOT appear in current file content when includeCursorTag is false'
,
(
)
=>
{
const
=
'line1\nline2\nline3\nline4\nline5'
;
const
=
createDocument
(
,
3
,
3
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
1
,
4
)
,
new
OffsetRange
(
0
,
5
)
,
{
...
,
:
{
...
.
,
:
false
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
const
{
,
}
=
.
;
expect
(
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"line1
line2
line3
line4
line5"
`
)
;
expect
(
)
.
toMatchInlineSnapshot
(
`
"<|area_around_code_to_edit|>
line1
<|code_to_edit|>
line2
li<|cursor|>ne3
line4
<|/code_to_edit|>
line5
<|/area_around_code_to_edit|>"
`
)
;
}
)
;
test
(
'cursor tag appears correctly when cursor is at end of line'
,
(
)
=>
{
const
=
'line1\nline2\nline3'
;
const
=
createDocument
(
,
2
,
6
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
0
,
3
)
,
new
OffsetRange
(
0
,
3
)
,
{
...
,
:
{
...
.
,
:
true
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"line1
line2<|cursor|>
line3"
`
)
;
}
)
;
}
)
;
suite
(
'includeLineNumbers option for currentFileContent'
,
(
)
=>
{
test
(
'includes line numbers with space when WithSpaceAfter'
,
(
)
=>
{
const
=
'line1\nline2\nline3'
;
const
=
createDocument
(
,
2
,
1
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
0
,
3
)
,
new
OffsetRange
(
0
,
3
)
,
{
...
,
:
{
...
.
,
:
false
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"0| line1
1| line2
2| line3"
`
)
;
}
)
;
test
(
'includes line numbers without space when WithoutSpace'
,
(
)
=>
{
const
=
'line1\nline2\nline3'
;
const
=
createDocument
(
,
2
,
1
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
0
,
3
)
,
new
OffsetRange
(
0
,
3
)
,
{
...
,
:
{
...
.
,
:
false
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"0|line1
1|line2
2|line3"
`
)
;
}
)
;
test
(
'no line numbers when None'
,
(
)
=>
{
const
=
'line1\nline2\nline3'
;
const
=
createDocument
(
,
2
,
1
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
0
,
3
)
,
new
OffsetRange
(
0
,
3
)
,
{
...
,
:
{
...
.
,
:
false
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"line1
line2
line3"
`
)
;
}
)
;
}
)
;
suite
(
'combined options'
,
(
)
=>
{
test
(
'line numbers and cursor tag together'
,
(
)
=>
{
const
=
'foo\nbar\nbaz'
;
const
=
createDocument
(
,
2
,
2
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
0
,
3
)
,
new
OffsetRange
(
0
,
3
)
,
{
...
,
:
{
...
.
,
:
true
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"0| foo
1| b<|cursor|>ar
2| baz"
`
)
;
}
)
;
test
(
'different line number options for areaAround vs currentFile'
,
(
)
=>
{
const
=
'line1\nline2\nline3\nline4\nline5'
;
const
=
createDocument
(
,
3
,
1
)
;
const
=
constructTaggedFile
(
,
new
OffsetRange
(
1
,
4
)
,
new
OffsetRange
(
0
,
5
)
,
{
...
,
:
{
...
.
,
:
false
,
:
false
}
}
,
,
{
:
{
:
.
,
:
.
}
}
)
;
assert
(
.
isOk
(
)
)
;
expect
(
.
.
)
.
toMatchInlineSnapshot
(
`
"<|area_around_code_to_edit|>
0| line1
<|code_to_edit|>
1| line2
2| <|cursor|>line3
3| line4
<|/code_to_edit|>
4| line5
<|/area_around_code_to_edit|>"
`
)
;
expect
(
.
.
.
.
join
(
'\n'
)
)
.
toMatchInlineSnapshot
(
`
"0|line1
1|line2
2|line3
3|line4
4|line5"
`
)
;
}
)
;
}
)
;
}
)
;
describe
(
'getUserPrompt'
,
(
)
=>
{
function
createTestPromptPieces
(
:
{
:
number
;
:
number
;
:
|
undefined
;
?
:
;
?
:
boolean
;
?
:
'aggressionHighLow'
;
?
:
;
?
:
;
}
)
:
{
const
=
[
'function foo() {'
,
' const x = 1;'
,
' return x;'
,
'}'
,
''
]
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
.
create
(
'file:///test/file.ts'
)
;
const
=
new
CurrentDocument
(
,
new
Position
(
.
,
.
)
)
;
const
=
new
StatelessNextEditDocument
(
,
undefined
,
.
create
(
'typescript'
)
,
,
.
,
,
new
Edits
(
,
[
]
)
,
)
;
const
:
=
{
...
DEFAULT_OPTIONS
,
:
.
,
:
.
,
...
(
.
!==
undefined
?
{
:
.
}
:
{
}
)
,
...
(
.
!==
undefined
?
{
:
{
:
.
}
}
:
{
}
)
,
:
{
...
DEFAULT_OPTIONS
.
,
:
10000
,
...
(
.
!==
undefined
?
{
:
.
}
:
{
}
)
,
}
,
}
;
const
:
[
]
=
[
{
:
'rejectedEdit'
,
:
,
:
[
{
:
1
,
:
[
' const x = 1;'
]
,
:
[
' const x = 2;'
]
}
]
,
:
0
,
}
]
;
return
new
PromptPieces
(
,
new
OffsetRange
(
1
,
3
)
,
new
OffsetRange
(
0
,
5
)
,
,
[
]
,
,
'<area>some code</area>'
,
undefined
,
.
??
.
,
new
LintErrors
(
,
,
new
TestLanguageDiagnosticsService
(
)
)
,
=>
.
ceil
(
.
/
4
)
,
,
,
undefined
,
undefined
,
)
;
}
test
(
'PatchBased02 appends cursor_position snippet and does not wrap in backticks'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
.
CURSOR_LOCATION
.
)
;
expect
(
)
.
toContain
(
.
CURSOR_LOCATION
.
)
;
expect
(
)
.
toContain
(
.
CURSOR
)
;
expect
(
)
.
toContain
(
' const '
+
.
CURSOR
+
'x = 1;'
)
;
expect
(
)
.
.
toContain
(
'<area>'
)
;
expect
(
)
.
.
toMatch
(
/ ^ ```/
)
;
expect
(
)
.
toContain
(
'developer was working on a section of code'
)
;
expect
(
)
.
.
toContain
(
'<|rejected/|>'
)
;
}
)
;
test
(
'PatchBased02 adds rejected edit annotations only when memory is enabled'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'@@ -1,1 +1,1 @@ <|rejected/|>'
)
;
expect
(
)
.
toContain
(
'are previous suggestions the developer rejected'
)
;
}
)
;
test
(
'rejected edit memory applies independently of the prompting strategy'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<|rejected/|>'
)
;
expect
(
)
.
toContain
(
'previous suggestions the developer rejected'
)
;
}
)
;
test
(
'explains rejection annotations when the standard postscript is disabled'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
:
false
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<|rejected/|>'
)
;
expect
(
)
.
toContain
(
'are previous suggestions the developer rejected'
)
;
expect
(
)
.
.
toContain
(
'Output a modified diff format'
)
;
}
)
;
test
(
'PatchBased02 with includePostScript=false omits postscript'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
false
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
.
CURSOR_LOCATION
.
)
;
expect
(
)
.
toContain
(
.
CURSOR_LOCATION
.
)
;
expect
(
)
.
toContain
(
.
CURSOR
)
;
expect
(
)
.
.
toContain
(
'<area>'
)
;
expect
(
)
.
.
toMatch
(
/ ^ ```/
)
;
expect
(
)
.
.
toContain
(
'developer was working'
)
;
}
)
;
test
(
'PatchBased01 uses basePrompt only (no cursor_position, no area, no backticks)'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
.
toContain
(
.
CURSOR_LOCATION
.
)
;
expect
(
)
.
.
toContain
(
'<area>'
)
;
expect
(
)
.
.
toMatch
(
/ ^ ```/
)
;
}
)
;
test
(
'default strategy appends areaAroundCodeToEdit and wraps in backticks'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
undefined
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<area>some code</area>'
)
;
expect
(
)
.
toMatch
(
/ ^ ```/
)
;
expect
(
)
.
.
toContain
(
.
CURSOR_LOCATION
.
)
;
}
)
;
test
(
'PatchBased02 cursor at beginning of line'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
3
,
:
1
,
:
.
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
.
CURSOR
+
' return x;'
)
;
}
)
;
test
(
'PatchBased02 cursor at end of line'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
1
,
:
17
,
:
.
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'function foo() {'
+
.
CURSOR
)
;
}
)
;
test
(
'PatchBased02 cursor_position line includes line number with space when WithSpaceAfter'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'1| '
+
' const '
+
.
CURSOR
+
'x = 1;'
)
;
}
)
;
test
(
'PatchBased02 cursor_position line includes line number without space when WithoutSpace'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'1|'
+
' const '
+
.
CURSOR
+
'x = 1;'
)
;
}
)
;
test
(
'PatchBased02 cursor_position line has no line number when None'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
.
CURSOR_LOCATION
.
+
'\n'
+
' const '
+
.
CURSOR
+
'x = 1;'
+
'\n'
+
.
CURSOR_LOCATION
.
)
;
}
)
;
.
each
(
[
[
.
,
''
]
,
[
.
,
'<|aggression|>high<|/aggression|>'
]
,
[
.
,
'<|aggression|>low<|/aggression|>'
]
,
]
)
(
'PatchBased02 aggression prompt places the %s tag before the postscript'
,
(
,
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
'aggressionHighLow'
,
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
const
=
` ${ PromptTags. CURSOR_LOCATION . start} \n const ${ PromptTags. CURSOR } x = 1;\n ${ PromptTags. CURSOR_LOCATION . end} `
;
const
=
'The developer was working on a section of code within the `current_file_content`'
;
expect
(
)
.
toContain
(
)
;
expect
(
.
indexOf
(
)
)
.
toBeLessThan
(
.
indexOf
(
)
)
;
if
(
===
.
)
{
expect
(
)
.
.
toContain
(
'<|aggression|>'
)
;
expect
(
)
.
toContain
(
` ${ PromptTags. CURSOR_LOCATION . end} \n\n ${ postScript} `
)
;
}
else
{
expect
(
)
.
toContain
(
` ${ PromptTags. CURSOR_LOCATION . end} \n\n ${ aggressionTag} \n\n ${ postScript} `
)
;
}
}
)
;
describe
(
'Xtab275AggressivenessHighLow'
,
(
)
=>
{
test
(
'medium level does not include aggressive tag'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'Do not skip any lines. Do not be lazy.'
)
;
expect
(
)
.
.
toContain
(
'<|aggressive|>'
)
;
expect
(
)
.
.
toContain
(
'<|/aggressive|>'
)
;
}
)
;
test
(
'high level includes aggressive tag with high'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<|aggressive|>high<|/aggressive|>'
)
;
}
)
;
test
(
'low level includes aggressive tag with low'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<|aggressive|>low<|/aggressive|>'
)
;
}
)
;
test
(
'high level includes xtab275 base postscript text'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'Do not skip any lines. Do not be lazy.'
)
;
}
)
;
}
)
;
describe
(
'Xtab275Aggressiveness'
,
(
)
=>
{
test
(
'medium level includes aggressive tag (unlike HighLow variant)'
,
(
)
=>
{
const
=
createTestPromptPieces
(
{
:
2
,
:
1
,
:
.
,
:
.
,
}
)
;
const
{
}
=
getUserPrompt
(
)
;
expect
(
)
.
toContain
(
'<|aggressive|>medium<|/aggressive|>'
)
;
}
)
;
}
)
;
describe
(
'sectionTokens'
,
(
)
=>
{
const
=
(
:
)
:
number
=>
.
+
.
+
.
+
.
+
.
+
.
+
.
+
.
;
test
(
'total matches the assembled prompt, counts reconcile, and systemPrompt is left at 0 across strategies'
,
(
)
=>
{
const
=
[
.
,
.
,
undefined
]
.
map
(
=>
{
const
{
,
}
=
getUserPrompt
(
createTestPromptPieces
(
{
:
2
,
:
9
,
}
)
)
;
return
{
:
.
===
computeTokens
(
)
,
:
sectionsSum
(
)
+
.
===
.
,
:
.
===
0
,
}
;
}
)
;
.
deepStrictEqual
(
,
[
{
:
true
,
:
true
,
:
true
}
,
{
:
true
,
:
true
,
:
true
}
,
{
:
true
,
:
true
,
:
true
}
,
]
)
;
}
)
;
test
(
'reports the strategy-dependent tail section (area vs cursor) mutually exclusively'
,
(
)
=>
{
const
tailShape
=
(
:
|
undefined
)
=>
{
const
{
}
=
getUserPrompt
(
createTestPromptPieces
(
{
:
2
,
:
9
,
}
)
)
;
return
{
:
.
>
0
,
:
.
>
0
}
;
}
;
.
deepStrictEqual
(
{
:
tailShape
(
.
)
,
:
tailShape
(
.
)
,
default
:
tailShape
(
undefined
)
,
}
,
{
:
{
:
false
,
:
false
}
,
:
{
:
false
,
:
true
}
,
default
:
{
:
true
,
:
false
}
,
}
,
)
;
}
)
;
test
(
'reports 0 for absent optional sections and non-zero for present ones'
,
(
)
=>
{
const
=
getUserPrompt
(
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
}
)
)
.
;
const
=
getUserPrompt
(
createTestPromptPieces
(
{
:
2
,
:
9
,
:
.
,
:
false
}
)
)
.
;
.
deepStrictEqual
(
{
:
.
,
:
.
>
0
,
:
.
>
0
,
:
.
,
}
,
{
:
0
,
:
true
,
:
true
,
:
0
,
}
,
)
;
}
)
;
}
)
;
}
)
;
describe
(
'getUserPrompt — globalBudget cascade'
,
(
)
=>
{
function
makeActiveDoc
(
)
:
{
:
;
:
;
:
string
[
]
}
{
const
=
[
'function foo() {'
,
' const x = 1;'
,
' return x;'
,
'}'
,
''
]
;
const
=
new
StringText
(
.
join
(
'\n'
)
)
;
const
=
.
create
(
'file:///test/file.ts'
)
;
const
=
new
CurrentDocument
(
,
new
Position
(
2
,
1
)
)
;
const
=
new
StatelessNextEditDocument
(
,
undefined
,
.
create
(
'typescript'
)
,
,
.
,
,
new
Edits
(
,
[
]
)
,
)
;
return
{
,
,
}
;
}
function
makePieces
(
:
[
'globalBudget'
]
,
?
:
{
?
:
;
?
:
<
typeof
>
}
)
:
{
const
{
,
,
}
=
makeActiveDoc
(
)
;
const
:
=
{
...
DEFAULT_OPTIONS
,
:
{
...
DEFAULT_OPTIONS
.
,
:
10000
}
,
,
}
;
return
new
PromptPieces
(
,
new
OffsetRange
(
1
,
3
)
,
new
OffsetRange
(
0
,
5
)
,
,
[
]
,
,
'<area>some code</area>'
,
?.
,
.
,
new
LintErrors
(
.
,
,
new
TestLanguageDiagnosticsService
(
)
)
,
=>
.
ceil
(
.
/
4
)
,
,
[
]
,
undefined
,
?.
,
)
;
}
function
makeLangCtxWithSnippet
(
:
string
)
:
{
return
{
:
0
,
:
0
,
:
[
{
:
{
:
.
,
:
1
,
:
.
parse
(
'file:///test/ctx.ts'
)
,
}
,
:
0
,
:
false
,
}
]
,
}
;
}
test
(
'produces the same prompt as legacy path when budgets are large'
,
(
)
=>
{
const
=
getUserPrompt
(
makePieces
(
undefined
)
)
;
const
=
getUserPrompt
(
makePieces
(
{
:
100000
,
:
.
DEFAULT_ORDER
,
:
.
DEFAULT_SHARES
,
}
)
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
)
.
toBe
(
.
)
;
}
)
;
test
(
'throws when neighborFiles is ordered before recentlyViewedDocuments'
,
(
)
=>
{
const
=
makePieces
(
{
:
1000
,
:
[
'neighborFiles'
,
'recentlyViewedDocuments'
,
'languageContext'
,
'diffHistory'
]
,
:
.
DEFAULT_SHARES
,
}
)
;
expect
(
(
)
=>
getUserPrompt
(
)
)
.
toThrow
(
/ 'recentlyViewedDocuments' before 'neighborFiles' /
)
;
}
)
;
test
(
'throws on duplicate part in order'
,
(
)
=>
{
const
=
makePieces
(
{
:
1000
,
:
[
'recentlyViewedDocuments'
,
'recentlyViewedDocuments'
,
'neighborFiles'
,
'languageContext'
,
'diffHistory'
]
,
:
.
DEFAULT_SHARES
,
}
)
;
expect
(
(
)
=>
getUserPrompt
(
)
)
.
toThrow
(
/ duplicate part 'recentlyViewedDocuments' /
)
;
}
)
;
test
(
'throws when shares do not sum to ~1'
,
(
)
=>
{
const
=
makePieces
(
{
:
1000
,
:
.
DEFAULT_ORDER
,
:
{
:
0.5
,
:
0.5
,
:
0.5
,
:
0.5
,
:
0.5
,
}
,
}
)
;
expect
(
(
)
=>
getUserPrompt
(
)
)
.
toThrow
(
/ shares across order must sum to ~1 /
)
;
}
)
;
test
(
'throws when shares is missing an entry for a part in order'
,
(
)
=>
{
const
=
makePieces
(
{
:
1000
,
:
.
DEFAULT_ORDER
,
:
{
:
0.2
,
:
0.4
,
:
0.2
,
:
0.2
,
}
as
<
'currentFile'
|
'languageContext'
|
'recentlyViewedDocuments'
|
'neighborFiles'
|
'diffHistory'
,
number
>
,
}
)
;
expect
(
(
)
=>
getUserPrompt
(
)
)
.
toThrow
(
/ shares is missing entry for 'diffHistory' /
)
;
}
)
;
test
(
'throws when shares is missing an entry for currentFile'
,
(
)
=>
{
const
=
makePieces
(
{
:
1000
,
:
.
DEFAULT_ORDER
,
:
{
:
0.25
,
:
0.25
,
:
0.25
,
:
0.25
,
}
as
<
'currentFile'
|
'languageContext'
|
'recentlyViewedDocuments'
|
'neighborFiles'
|
'diffHistory'
,
number
>
,
}
)
;
expect
(
(
)
=>
getUserPrompt
(
)
)
.
toThrow
(
/ shares is missing entry for 'currentFile' /
)
;
}
)
;
function
runCascade
(
:
,
?
:
{
?
:
}
)
{
const
{
}
=
makeActiveDoc
(
)
;
const
:
=
{
...
DEFAULT_OPTIONS
,
}
;
return
runGlobalBudgetCascade
(
,
[
]
,
?.
,
=>
.
ceil
(
.
/
4
)
,
,
undefined
,
,
[
]
)
;
}
test
(
'finalSurplus carries the full unused pool when no cascade part consumes budget'
,
(
)
=>
{
const
=
runCascade
(
{
:
.
DEFAULT_TOTAL_TOKENS
,
:
.
DEFAULT_ORDER
,
:
.
DEFAULT_SHARES
,
}
)
;
expect
(
.
)
.
toBe
(
6000
)
;
}
)
;
test
(
'finalSurplus shrinks by what the cascade consumes, so the current file reuses less leftover'
,
(
)
=>
{
const
:
=
{
:
.
DEFAULT_TOTAL_TOKENS
,
:
.
DEFAULT_ORDER
,
:
.
DEFAULT_SHARES
,
}
;
const
=
runCascade
(
)
;
const
=
runCascade
(
,
{
:
makeLangCtxWithSnippet
(
'const ctxMarker = 1;\n'
.
repeat
(
40
)
)
}
)
;
expect
(
.
)
.
toBeLessThan
(
.
)
;
}
)
;
test
(
'precomputedCascade produces an identical prompt to computing the cascade internally'
,
(
)
=>
{
const
=
'const sharedCtxMarker = 42;'
;
const
:
[
'globalBudget'
]
=
{
:
100000
,
:
.
DEFAULT_ORDER
,
:
.
DEFAULT_SHARES
,
}
;
const
=
getUserPrompt
(
makePieces
(
,
{
:
makeLangCtxWithSnippet
(
)
}
)
)
;
const
=
runCascade
(
,
{
:
makeLangCtxWithSnippet
(
)
}
)
;
const
=
getUserPrompt
(
makePieces
(
,
{
:
makeLangCtxWithSnippet
(
)
,
:
}
)
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
)
.
toBe
(
.
)
;
}
)
;
test
(
'reports the recently-viewed subsection token breakdown, matching the legacy path'
,
(
)
=>
{
const
=
'const sharedCtxMarker = 42;'
;
const
:
[
'globalBudget'
]
=
{
:
100000
,
:
.
DEFAULT_ORDER
,
:
.
DEFAULT_SHARES
,
}
;
const
=
getUserPrompt
(
makePieces
(
,
{
:
makeLangCtxWithSnippet
(
)
}
)
)
.
.
;
const
=
getUserPrompt
(
makePieces
(
undefined
,
{
:
makeLangCtxWithSnippet
(
)
}
)
)
.
.
;
.
deepStrictEqual
(
{
:
.
===
0
,
:
.
>
0
,
:
.
===
0
,
:
JSON
.
stringify
(
)
===
JSON
.
stringify
(
)
,
}
,
{
:
true
,
:
true
,
:
true
,
:
true
,
}
,
)
;
}
)
;
}
)
;