ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / .github / skills / auto-perf-optimize / scripts / chat-session-switch-smoke.mts 937 строк · изменён 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
import { chromium, type Browser , type CDPSession , type Page } from 'playwright-core' ;
import { spawn, type ChildProcess } from 'node:child_process' ;
import { createWriteStream } from 'node:fs' ;
import { mkdir, rm, writeFile } from
http
os
path
process
setTimeout delay
StopWatch
prepareUserDataProfile
root path meta dirname
codeScript process platform path root path root
chatViewSelector
chatInputElementSelector
chatInputEditorSelector
chatResponseSelector
chatResponseLoadingSelector
chatResponseCompleteSelector
sessionItemSelector
activeChatInputMarker
activeChatInputSelector
activeChatInputEditorMarker
activeChatInputEditorSelector
selector text
global
driver SmokeTestDriver
label
jsHeapUsedSize
jsHeapTotalSize
runtimeUsedSize
runtimeTotalSize
snapshot
snapshotBytes
index
prompt
contentType
responseText
help
verbose
reuse
skipPrelaunch
heapSnapshots
heapSnapshotLabels Set
keepOpen
temporaryUserData
port
switchIterations
responseTimeout
firstResponseTimeout
settleMs
workspace
outputDir
userDataDir
seedUserDataDir
extensionDir
usedSize
totalSize
firstToLastUsedBytes
postFirstSwitchUsedBytes
postFirstSwitchUsedBytesPerIteration
child ChildProcess
failedBeforeConnect Error
signal NodeJS Signals
contentType
prompt
contentType
prompt
contentType
prompt
options process argv
options help
process
outputDir path options outputDir
extensionDir path options extensionDir path outputDir
ownsCode options reuse
shouldCloseCode ownsCode options keepOpen
outputDir recursive
path outputDir recursive
userDataDir ownsUserDataDir
outputDir
persistentUserDataDir path root
temporaryUserData options temporaryUserData
keepOpen options keepOpen
keepUserData
reuse options reuse
userDataDir options userDataDir
seedUserDataDir options seedUserDataDir
options temporaryUserData options userDataDir
launchedCode LaunchedCode
browser Browser
session CDPSession
samples HeapSample
sessions SessionInfo
options reuse options port
launchedCode ownsCode userDataDir extensionDir
browser options port launchedCode failedBeforeConnect
launchedCode
page browser
session page page
session
session
page globalThis driver whenWorkbenchRestored
page path path outputDir
samples session outputDir
i i length i
contentType prompt i
i
page
page
page path path outputDir
responseText page prompt
sessions index i prompt contentType responseText
page path path outputDir
outputDir samples sessions options switchIterations
samples session outputDir
page
page path path outputDir
samples session outputDir
warmup warmup warmup
s s length s
page s
page
iteration iteration options switchIterations iteration
label iteration
s s length s
page s
page
page path path outputDir
samples session outputDir
outputDir samples sessions options switchIterations
outputDir samples sessions options switchIterations
samples outputDir
error
outputDir samples sessions options switchIterations error
error
session
shouldCloseCode
browser bs bs
browser
launchedCode shouldCloseCode
launchedCode child
launchedCode
launchedCode child
ownsUserDataDir
userDataDir recursive force maxRetries
dirs userDataDir extensionDir LaunchedCode
args
options workspace
error Error
connected
terminating
failedBeforeConnect resolve failBeforeConnect resolve
child codeScript args
cwd root
env options skipPrelaunch process env process env
detached options keepOpen
shell process platform
stdio options keepOpen options verbose
options keepOpen
child
options verbose options keepOpen
child stdout data process stdout
child stderr data process stderr
child error
child code signal
connected terminating
options reuse code signal
child
failedBeforeConnect
connected
signal
terminating
child signal
port launchFailure Error Browser
endpoint
i i i
port launchFailure
chromium endpoint
launchFailure
promise launchFailure Error
launchFailure
promise
promise
launchFailure error error
launchFailure Error
launchError
launchFailure
resolve
launchError
launchError
child ChildProcess timeoutMs
child exitCode child signalCode
resolve
timer timeoutMs
timer
child
timer
port
port
port
browser Browser Page
i i i
pages browser context context
page pages
hasDriver page globalThis driver whenWorkbenchRestored
hasDriver
page
page Page
page
shortcut process platform
page keyboard shortcut
page
inputEditor page
inputEditor force
inputEditor page
inputEditor chatInputElementSelector state timeout
inputEditor
inputEditor
activeChatInputSelector
page Page
page selector document selector element
element
rect element
rect width rect height
chatInputEditorSelector
page Page
page selector document selector element
element
rect element
rect width rect height
chatInputEditorSelector timeout
page Page Locator
page editorSelector marker
document element element marker
editors document editorSelector element element HTMLElement
element
rect element
rect width rect height
activeEditor editors editor editor classList editor document activeElement
inputEditor activeEditor editors a b a bottom b bottom
inputEditor
inputEditor marker
editorSelector chatInputEditorSelector marker activeChatInputEditorMarker
page activeChatInputEditorSelector
inputEditor Locator
stopWatch StopWatch
stopWatch
inputEditor editor editor classList editor
inputEditor Locator
inputEditor editor inputSelector marker
document element element marker
input editor inputSelector
input
input marker
inputSelector chatInputElementSelector marker activeChatInputMarker
page Page message
inputSelector page
page selector text
globalThis driver
globalThis driver selector text
selector inputSelector
text message
page Page
page
page keyboard process platform
page keyboard
page Page
shortcut
page keyboard shortcut
page
inputEditor page
inputEditor force
inputEditor
inputEditor
page Page message
responseCountBefore page chatResponseSelector
textBefore page
page
page message
page keyboard
page
responseSelector loadingSelector count textBefore tb
element Element
contentElement element element
contentElement contentElement innerText contentElement textContent
responses document responseSelector
latestText responses
responses length count
loadingResponse document loadingSelector
loadingResponse
latestText latestText tb
responseSelector chatResponseSelector loadingSelector chatResponseLoadingSelector count responseCountBefore textBefore
timeout options firstResponseTimeout
page
completeSelector loadingSelector countBefore textBefore tb
element Element
contentElement element element
contentElement contentElement innerText contentElement textContent
completedResponses document completeSelector
loadingResponses document loadingSelector
latestText completedResponses
latestText latestText loadingResponses length completedResponses length countBefore latestText tb
completeSelector chatResponseCompleteSelector loadingSelector chatResponseLoadingSelector countBefore responseCountBefore textBefore
timeout options responseTimeout
options settleMs
page
page Page
page responseSelector
response document responseSelector
contentElement response response
contentElement contentElement innerText contentElement textContent
chatResponseSelector
page Page
dialogBlocker page
stopWatch StopWatch
stopWatch
visible dialogBlocker dialogBlocker
visible
page keyboard
page Page
page
page keyboard process platform
page keyboard delay
page keyboard
page
sessionItems page sessionItemSelector
page Page sessionIndex
page
sessionItems page sessionItemSelector
count sessionItems
count
targetIndex Math sessionIndex count
targetItem sessionItems targetIndex
title targetItem
targetItem
page Page
stopWatch StopWatch
stopWatch
isSettled page responseSelector viewSelector loadingSelector
chatView document viewSelector
chatView
responses chatView responseSelector
loading chatView loadingSelector
responses length loading length
responseSelector
viewSelector chatViewSelector
loadingSelector
isSettled
cdpSession CDPSession outputDir label HeapSample
cdpSession
performanceMetrics cdpSession
runtimeHeapUsage cdpSession
snapshot label path outputDir
snapshotBytes snapshot cdpSession snapshot
sample HeapSample
label
jsHeapUsedSize performanceMetrics
jsHeapTotalSize performanceMetrics
runtimeUsedSize runtimeHeapUsage usedSize
runtimeTotalSize runtimeHeapUsage totalSize
snapshot
snapshotBytes
sample
cdpSession CDPSession
cdpSession
cdpSession
cdpSession CDPSession Map
response cdpSession
response metrics metric metric name metric value
cdpSession CDPSession HeapUsage
cdpSession
cdpSession CDPSession file
path file recursive
stream file
snapshotBytes
pendingWrite
event chunk
snapshotBytes Buffer event chunk
pendingWrite pendingWrite resolve reject
stream event chunk error error error
cdpSession onChunk
cdpSession reportProgress
pendingWrite
cdpSession onChunk
resolve reject
stream reject
stream resolve
snapshotBytes
label
options heapSnapshots options heapSnapshotLabels options heapSnapshotLabels label
samples HeapSample outputDir
sample samples
heapSize sample runtimeUsedSize sample jsHeapUsedSize
trend samples
trend postFirstSwitchUsedBytes
outputDir samples HeapSample sessions SessionInfo switchIterations error
path outputDir
createdAt
workspace options workspace
switchIterations
sessionsCreated sessions length
sessions
error error error error stack error stack error
analysis samples
samples
samples HeapSample MemoryTrend
sizedSamples samples sample sample runtimeUsedSize sample jsHeapUsedSize
firstSize sizedSamples
lastSize sizedSamples
switchSamples samples sample sample label
firstSwitchSize switchSamples runtimeUsedSize switchSamples jsHeapUsedSize
lastSwitchSize switchSamples runtimeUsedSize switchSamples jsHeapUsedSize
postFirstSwitchUsedBytes firstSwitchSize lastSwitchSize switchSamples length lastSwitchSize firstSwitchSize
firstToLastUsedBytes firstSize lastSize samples length lastSize firstSize
postFirstSwitchUsedBytes
postFirstSwitchUsedBytesPerIteration postFirstSwitchUsedBytes postFirstSwitchUsedBytes switchSamples length
bytes
bytes
units
value bytes
unitIndex
value unitIndex units length
value
unitIndex
bytes
bytes
url
resolve reject
request http url response
response
response response statusCode
request
request
request reject
args Options
timestamp
parsed Options
help
verbose
reuse
skipPrelaunch
heapSnapshots
heapSnapshotLabels
keepOpen
temporaryUserData
port
switchIterations
responseTimeout
firstResponseTimeout
settleMs
workspace root
outputDir path root timestamp
userDataDir
seedUserDataDir
extensionDir
i i args length i
arg args i
arg arg
parsed help
arg
parsed verbose
arg
parsed reuse
arg
parsed skipPrelaunch
arg
parsed heapSnapshots
arg
parsed arg length
arg
parsed args i arg
arg
parsed keepOpen
arg
parsed temporaryUserData
arg
key inlineValue arg
value inlineValue args i key
key
parsed port key value
parsed switchIterations key value
parsed responseTimeout key value
parsed firstResponseTimeout key value
parsed settleMs key value
parsed workspace path value
parsed outputDir value
parsed userDataDir value
parsed seedUserDataDir value
parsed extensionDir value
parsed
opts Options value
opts heapSnapshotLabels
label value
trimmedLabel label
trimmedLabel
opts heapSnapshotLabels trimmedLabel
arg
index arg
index arg arg index arg index
args index flag
value args index
value
value
flag value min
parsed value
Number parsed parsed min
parsed
'node:fs/promises'
;
import
from
'node:http'
;
import
from
'node:os'
;
import
from
'node:path'
;
import
from
'node:process'
;
import
{
as
}
from
'node:timers/promises'
;
import
{
}
from
'../../../../src/vs/base/common/stopwatch.ts'
;
import
{
}
from
'./userDataProfile.mts'
;
const
=
.
resolve
(
import
.
.
,
'..'
,
'..'
,
'..'
,
'..'
)
;
const
=
.
===
'win32'
?
.
join
(
,
'scripts'
,
'code.bat'
)
:
.
join
(
,
'scripts'
,
'code.sh'
)
;
const
=
'div[id="workbench.panel.chat"]'
;
const
=
'.native-edit-context, textarea'
;
const
=
` ${ chatViewSelector} .interactive-input-part .monaco-editor[role="code"] `
;
const
=
` ${ chatViewSelector} .interactive-item-container.interactive-response `
;
const
=
` ${ chatResponseSelector} .chat-response-loading `
;
const
=
` ${ chatResponseSelector} :not(.chat-response-loading) `
;
const
=
'.agent-session-item'
;
const
=
'data-session-switch-smoke-input'
;
const
=
` [ ${ activeChatInputMarker} ="true"] `
;
const
=
'data-session-switch-smoke-input-editor'
;
const
=
` [ ${ activeChatInputEditorMarker} ="true"] `
;
interface
SmokeTestDriver
{
whenWorkbenchRestored
(
)
:
Promise
<
void
>
;
typeInEditor
(
:
string
,
:
string
)
:
Promise
<
void
>
;
}
declare
{
var
:
|
undefined
;
}
interface
HeapSample
{
:
string
;
:
number
|
undefined
;
:
number
|
undefined
;
:
number
|
undefined
;
:
number
|
undefined
;
:
string
|
undefined
;
:
number
|
undefined
;
}
interface
SessionInfo
{
:
number
;
:
string
;
:
string
;
:
string
|
undefined
;
}
interface
Options
{
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
<
string
>
|
undefined
;
:
boolean
;
:
boolean
;
:
number
;
:
number
;
:
number
;
:
number
;
:
number
;
:
string
;
:
string
;
:
string
|
undefined
;
:
string
|
undefined
;
:
string
|
undefined
;
}
interface
HeapUsage
{
:
number
;
:
number
;
}
interface
MemoryTrend
{
:
number
|
undefined
;
:
number
|
undefined
;
:
number
|
undefined
;
}
interface
LaunchedCode
{
:
;
:
Promise
<
>
;
markConnected
(
)
:
void
;
terminate
(
:
.
)
:
boolean
;
}
const
SESSION_PROMPTS
=
[
{
:
'codeblocks'
,
:
'Write a short TypeScript function that reverses a linked list. Include the type definition. Reply ONLY with the code in a fenced code block, no explanation.'
,
}
,
{
:
'markdown'
,
:
'List 5 best practices for writing maintainable CSS, using markdown headers, bullet points, and bold text. Keep it under 200 words.'
,
}
,
{
:
'terminal'
,
:
'Show me 3 useful git commands for inspecting history. Format each as a fenced shell code block with a one-line comment above it.'
,
}
,
]
;
const
=
parseArgs
(
.
.
slice
(
2
)
)
;
if
(
.
)
{
printHelp
(
)
;
.
exit
(
0
)
;
}
await
main
(
)
;
async
function
main
(
)
:
Promise
<
void
>
{
const
=
.
resolve
(
.
)
;
const
=
.
resolve
(
.
??
.
join
(
,
'extensions'
)
)
;
const
=
!
.
;
const
=
&&
!
.
;
await
mkdir
(
,
{
:
true
}
)
;
await
mkdir
(
.
join
(
,
'heap'
)
,
{
:
true
}
)
;
const
{
,
}
=
await
prepareUserDataProfile
(
{
,
:
.
join
(
,
'.build'
,
'auto-perf-optimize'
,
'user-data'
)
,
:
.
,
:
.
,
:
false
,
:
.
,
:
.
,
:
.
,
}
)
;
if
(
!
.
&&
.
===
undefined
)
{
console
.
log
(
` [code] using persistent user-data-dir: ${ userDataDir} `
)
;
}
let
:
|
undefined
;
let
:
|
undefined
;
let
:
|
undefined
;
const
:
[
]
=
[
]
;
const
:
[
]
=
[
]
;
try
{
if
(
!
.
&&
await
isCDPAvailable
(
.
)
)
{
throw
new
Error
(
` Port ${ options. port} already has a CDP endpoint. Stop that process, pass --port <free port>, or pass --reuse. `
)
;
}
=
?
launchCode
(
{
,
}
)
:
undefined
;
=
await
connectToCode
(
.
,
?.
)
;
?.
markConnected
(
)
;
const
=
await
findWorkbenchPage
(
)
;
=
await
.
context
(
)
.
newCDPSession
(
)
;
await
.
send
(
'Performance.enable'
)
;
await
.
send
(
'HeapProfiler.enable'
)
;
await
.
evaluate
(
(
)
=>
.
?.
?.
(
)
)
;
await
.
screenshot
(
{
:
.
join
(
,
'01-workbench.png'
)
}
)
;
.
push
(
await
sampleHeap
(
,
,
'01-restored'
)
)
;
console
.
log
(
'\n=== Phase 1: Creating sessions with different content types ==='
)
;
for
(
let
=
0
;
<
SESSION_PROMPTS
.
;
++
)
{
const
{
,
}
=
SESSION_PROMPTS
[
]
;
console
.
log
(
` \n--- Creating session ${ i + 1 } ( ${ contentType} ) --- `
)
;
if
(
===
0
)
{
await
openChat
(
)
;
}
else
{
await
createNewChatSession
(
)
;
}
await
.
screenshot
(
{
:
.
join
(
,
` 02-session- ${ i + 1 } -before-send.png `
)
}
)
;
const
=
await
sendAndWaitForResponse
(
,
)
;
.
push
(
{
:
,
,
,
}
)
;
await
.
screenshot
(
{
:
.
join
(
,
` 02-session- ${ i + 1 } -response.png `
)
}
)
;
console
.
log
(
` Session ${ i + 1 } ( ${ contentType} ): response received ( ${ responseText?. length ?? 0 } chars) `
)
;
}
await
writeSummary
(
,
,
,
.
)
;
.
push
(
await
sampleHeap
(
,
,
'02-sessions-created'
)
)
;
console
.
log
(
'\n=== Phase 2: Showing sessions sidebar ==='
)
;
await
showSessionsSidebar
(
)
;
await
delay
(
1000
)
;
await
.
screenshot
(
{
:
.
join
(
,
'03-sessions-sidebar.png'
)
}
)
;
.
push
(
await
sampleHeap
(
,
,
'03-sidebar-shown'
)
)
;
console
.
log
(
'\n=== Phase 3: Switching between sessions ==='
)
;
console
.
log
(
'\n--- Warmup: 3 switch cycles ---'
)
;
for
(
let
=
0
;
<
3
;
++
)
{
for
(
let
=
0
;
<
SESSION_PROMPTS
.
;
++
)
{
await
clickSessionInList
(
,
)
;
await
waitForSessionContentToLoad
(
)
;
await
delay
(
300
)
;
}
}
console
.
log
(
'Warmup complete'
)
;
for
(
let
=
1
;
<=
.
;
++
)
{
const
=
String
(
)
.
padStart
(
2
,
'0'
)
;
console
.
log
(
` \n--- Switch iteration ${ iteration} --- `
)
;
for
(
let
=
0
;
<
SESSION_PROMPTS
.
;
++
)
{
await
clickSessionInList
(
,
)
;
await
waitForSessionContentToLoad
(
)
;
await
delay
(
300
)
;
}
await
.
screenshot
(
{
:
.
join
(
,
` 04-switch- ${ label} .png `
)
}
)
;
.
push
(
await
sampleHeap
(
,
,
` 04-switch- ${ label} `
)
)
;
await
writeSummary
(
,
,
,
.
)
;
}
await
writeSummary
(
,
,
,
.
)
;
printSummary
(
,
)
;
}
catch
(
)
{
await
writeSummary
(
,
,
,
.
,
)
;
throw
;
}
finally
{
await
?.
detach
(
)
.
catch
(
(
)
=>
undefined
)
;
if
(
)
{
await
?.
newBrowserCDPSession
(
)
.
then
(
=>
.
send
(
'Browser.close'
)
)
.
catch
(
(
)
=>
undefined
)
;
}
await
?.
close
(
)
.
catch
(
(
)
=>
undefined
)
;
if
(
&&
)
{
if
(
!
await
waitForChildExit
(
.
,
10000
)
)
{
.
terminate
(
'SIGTERM'
)
;
await
waitForChildExit
(
.
,
5000
)
;
}
}
if
(
)
{
await
rm
(
,
{
:
true
,
:
true
,
:
3
}
)
.
catch
(
(
)
=>
undefined
)
;
}
}
}
function
launchCode
(
:
{
:
string
;
:
string
}
)
:
{
const
=
[
'--enable-smoke-test-driver'
,
'--disable-workspace-trust'
,
` --remote-debugging-port= ${ options. port} `
,
` --user-data-dir= ${ dirs. userDataDir} `
,
` --extensions-dir= ${ dirs. extensionDir} `
,
'--skip-welcome'
,
'--skip-release-notes'
,
.
,
]
;
let
failBeforeConnect
:
(
:
)
=>
void
=
(
)
=>
undefined
;
let
=
false
;
let
=
false
;
const
=
new
Promise < Error>
(
=>
=
)
;
const
=
spawn
(
,
,
{
:
,
:
.
?
{
...
.
,
VSCODE_SKIP_PRELAUNCH
:
'1'
}
:
.
,
:
.
,
:
.
===
'win32'
,
:
.
?
'ignore'
:
.
?
'inherit'
:
[
'ignore'
,
'pipe'
,
'pipe'
]
,
}
)
;
if
(
.
)
{
.
unref
(
)
;
}
if
(
!
.
&&
!
.
)
{
.
?.
on
(
'data'
,
=>
.
.
write
(
` [code] ${ data} `
)
)
;
.
?.
on
(
'data'
,
=>
.
.
write
(
` [code] ${ data} `
)
)
;
}
.
once
(
'error'
,
=>
{
failBeforeConnect
(
new
Error
(
` Failed to launch Code from ${ codeScript} : ${ error. message} `
)
)
;
}
)
;
.
once
(
'exit'
,
(
,
)
=>
{
if
(
!
&&
!
)
{
failBeforeConnect
(
new
Error
(
` Code exited before the script connected to CDP. code= ${ code} signal= ${ signal} `
)
)
;
}
if
(
!
.
&&
!==
0
&&
!==
'SIGTERM'
)
{
console
.
error
(
` [code] exited with code ${ code} signal ${ signal} `
)
;
}
}
)
;
return
{
,
,
markConnected
:
(
)
=>
=
true
,
terminate
:
=>
{
=
true
;
return
.
kill
(
)
;
}
,
}
;
}
async
function
connectToCode
(
:
number
,
?
:
Promise
<
>
)
:
Promise
<
>
{
const
=
` http://127.0.0.1: ${ port} `
;
for
(
let
=
0
;
<
120
;
++
)
{
try
{
await
raceLaunchFailure
(
waitForCDPEndpoint
(
)
,
)
;
return
await
.
connectOverCDP
(
)
;
}
catch
{
await
throwIfLaunchFailed
(
)
;
await
delay
(
500
)
;
}
}
throw
new
Error
(
` Timed out waiting for Code to expose CDP on ${ endpoint} `
)
;
}
async
function
raceLaunchFailure < T >
(
:
Promise
<
T
>
,
:
Promise
<
>
|
undefined
)
:
Promise
<
T
>
{
if
(
!
)
{
return
;
}
return
Promise
.
race
(
[
,
.
then
(
=>
Promise
.
reject
(
)
)
,
]
)
;
}
async
function
throwIfLaunchFailed
(
:
Promise
<
>
|
undefined
)
:
Promise
<
void
>
{
const
=
await
Promise
.
race
(
[
,
new
Promise < undefined >
(
=>
queueMicrotask
(
(
)
=>
resolve
(
undefined
)
)
)
,
]
)
;
if
(
)
{
throw
;
}
}
function
waitForChildExit
(
:
,
:
number
)
:
Promise
<
boolean
>
{
if
(
.
!==
null
||
.
!==
null
)
{
return
Promise
.
resolve
(
true
)
;
}
return
new
Promise
(
=>
{
const
=
setTimeout
(
(
)
=>
resolve
(
false
)
,
)
;
.
unref
(
)
;
.
once
(
'exit'
,
(
)
=>
{
clearTimeout
(
)
;
resolve
(
true
)
;
}
)
;
}
)
;
}
async
function
isCDPAvailable
(
:
number
)
:
Promise
<
boolean
>
{
return
waitForCDPEndpoint
(
)
.
then
(
(
)
=>
true
,
(
)
=>
false
)
;
}
async
function
waitForCDPEndpoint
(
:
number
)
:
Promise
<
void
>
{
await
getJson
(
` http://127.0.0.1: ${ port} /json/version `
)
;
}
async
function
findWorkbenchPage
(
:
)
:
Promise
<
>
{
for
(
let
=
0
;
<
120
;
++
)
{
const
=
.
contexts
(
)
.
flatMap
(
=>
.
pages
(
)
)
;
for
(
const
of
)
{
const
=
await
.
evaluate
(
(
)
=>
!
!
.
?.
)
.
catch
(
(
)
=>
false
)
;
if
(
)
{
return
;
}
}
await
delay
(
500
)
;
}
throw
new
Error
(
'Timed out waiting for the workbench page and smoke-test driver'
)
;
}
async
function
openChat
(
:
)
:
Promise
<
string
>
{
if
(
!
await
hasVisibleChatInputEditor
(
)
)
{
const
=
.
===
'darwin'
?
'Control+Meta+I'
:
'Control+Alt+I'
;
await
.
.
press
(
)
;
await
waitForVisibleChatInputEditor
(
)
;
}
let
=
await
markChatInputEditor
(
)
;
await
.
click
(
{
:
true
}
)
;
=
await
markChatInputEditor
(
)
;
await
.
locator
(
)
.
first
(
)
.
waitFor
(
{
:
'attached'
,
:
30000
}
)
;
await
waitForInputEditorFocus
(
)
;
await
markActiveChatInput
(
)
;
return
;
}
async
function
hasVisibleChatInputEditor
(
:
)
:
Promise
<
boolean
>
{
return
.
evaluate
(
=>
Array
.
from
(
.
querySelectorAll
(
)
)
.
some
(
=>
{
if
(
!
(
instanceof
HTMLElement
)
)
{
return
false
;
}
const
=
.
getBoundingClientRect
(
)
;
return
.
>
0
&&
.
>
0
;
}
)
,
)
;
}
async
function
waitForVisibleChatInputEditor
(
:
)
:
Promise
<
void
>
{
await
.
waitForFunction
(
=>
Array
.
from
(
.
querySelectorAll
(
)
)
.
some
(
=>
{
if
(
!
(
instanceof
HTMLElement
)
)
{
return
false
;
}
const
=
.
getBoundingClientRect
(
)
;
return
.
>
0
&&
.
>
0
;
}
)
,
,
{
:
30000
}
)
;
}
async
function
markChatInputEditor
(
:
)
:
Promise
<
import
(
'playwright-core'
)
.
>
{
await
.
evaluate
(
(
{
,
}
)
=>
{
.
querySelectorAll
(
` [ ${ marker} ] `
)
.
forEach
(
=>
.
removeAttribute
(
)
)
;
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
.
filter
(
(
)
:
is
=>
{
if
(
!
(
instanceof
HTMLElement
)
)
{
return
false
;
}
const
=
.
getBoundingClientRect
(
)
;
return
.
>
0
&&
.
>
0
;
}
)
;
const
=
.
find
(
=>
.
.
contains
(
'focused'
)
||
.
contains
(
.
)
)
;
const
=
??
.
toSorted
(
(
,
)
=>
.
getBoundingClientRect
(
)
.
-
.
getBoundingClientRect
(
)
.
)
.
at
(
-
1
)
;
if
(
!
)
{
throw
new
Error
(
'Visible Chat input editor not found'
)
;
}
.
setAttribute
(
,
'true'
)
;
}
,
{
:
,
:
}
)
;
return
.
locator
(
)
;
}
async
function
waitForInputEditorFocus
(
:
import
(
'playwright-core'
)
.
)
:
Promise
<
void
>
{
const
=
.
create
(
)
;
while
(
.
elapsed
(
)
<
5000
)
{
if
(
await
.
evaluate
(
=>
.
.
contains
(
'focused'
)
||
!
!
.
querySelector
(
':focus'
)
)
)
{
return
;
}
await
delay
(
50
)
;
}
throw
new
Error
(
'Timed out waiting for Chat input editor focus'
)
;
}
async
function
markActiveChatInput
(
:
import
(
'playwright-core'
)
.
)
:
Promise
<
void
>
{
await
.
evaluate
(
(
,
{
,
}
)
=>
{
.
querySelectorAll
(
` [ ${ marker} ] `
)
.
forEach
(
=>
.
removeAttribute
(
)
)
;
const
=
.
querySelector
(
)
;
if
(
!
)
{
throw
new
Error
(
'Chat input not found'
)
;
}
.
setAttribute
(
,
'true'
)
;
}
,
{
:
,
:
}
)
;
}
async
function
typeInChat
(
:
,
:
string
)
:
Promise
<
void
>
{
const
=
await
openChat
(
)
;
await
.
evaluate
(
(
{
,
}
)
=>
{
if
(
!
.
)
{
throw
new
Error
(
'Smoke-test driver not found'
)
;
}
return
.
.
typeInEditor
(
,
)
;
}
,
{
:
,
:
.
replace
(
/ \r ? \n / g
,
' '
)
,
}
)
;
}
async
function
clearChatInput
(
:
)
:
Promise
<
void
>
{
await
openChat
(
)
;
await
.
.
press
(
.
===
'darwin'
?
'Meta+A'
:
'Control+A'
)
;
await
.
.
press
(
'Backspace'
)
;
}
async
function
createNewChatSession
(
:
)
:
Promise
<
void
>
{
const
=
'Control+L'
;
await
.
.
press
(
)
;
await
delay
(
500
)
;
await
waitForVisibleChatInputEditor
(
)
;
const
=
await
markChatInputEditor
(
)
;
await
.
click
(
{
:
true
}
)
;
await
waitForInputEditorFocus
(
)
;
await
markActiveChatInput
(
)
;
}
async
function
sendAndWaitForResponse
(
:
,
:
string
)
:
Promise
<
string
|
undefined
>
{
const
=
await
.
locator
(
)
.
count
(
)
;
const
=
await
getLatestChatResponseText
(
)
;
await
clearChatInput
(
)
;
await
typeInChat
(
,
)
;
await
.
.
press
(
'Enter'
)
;
await
.
waitForFunction
(
(
{
,
,
,
:
}
)
=>
{
const
getResponseText
=
(
:
|
undefined
)
=>
{
const
=
?.
querySelector
(
':scope > .value'
)
??
;
return
instanceof
HTMLElement
?
.
.
trim
(
)
:
?.
?.
trim
(
)
;
}
;
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
;
const
=
getResponseText
(
.
at
(
-
1
)
)
;
if
(
.
>
)
{
return
true
;
}
const
=
.
querySelector
(
)
;
if
(
)
{
return
true
;
}
if
(
!
!
&&
!==
?.
trim
(
)
)
{
return
true
;
}
return
false
;
}
,
{
:
,
:
,
:
,
}
,
{
:
.
}
)
;
await
.
waitForFunction
(
(
{
,
,
,
:
}
)
=>
{
const
getResponseText
=
(
:
|
undefined
)
=>
{
const
=
?.
querySelector
(
':scope > .value'
)
??
;
return
instanceof
HTMLElement
?
.
.
trim
(
)
:
?.
?.
trim
(
)
;
}
;
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
;
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
;
const
=
getResponseText
(
.
at
(
-
1
)
)
;
return
!
!
&&
!==
'Working'
&&
.
===
0
&&
(
.
>
||
!==
?.
trim
(
)
)
;
}
,
{
:
,
:
,
:
,
}
,
{
:
.
}
)
;
await
delay
(
.
)
;
return
getLatestChatResponseText
(
)
;
}
async
function
getLatestChatResponseText
(
:
)
:
Promise
<
string
|
undefined
>
{
return
.
evaluate
(
=>
{
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
.
at
(
-
1
)
;
const
=
?.
querySelector
(
':scope > .value'
)
??
;
return
instanceof
HTMLElement
?
.
:
?.
??
undefined
;
}
,
)
;
}
async
function
dismissDialogs
(
:
)
:
Promise
<
void
>
{
const
=
.
locator
(
'.monaco-dialog-modal-block'
)
;
const
=
.
create
(
)
;
while
(
.
elapsed
(
)
<
3000
)
{
const
=
await
.
count
(
)
>
0
&&
await
.
first
(
)
.
isVisible
(
)
.
catch
(
(
)
=>
false
)
;
if
(
!
)
{
return
;
}
console
.
log
(
'[dialog] dismissing modal dialog via Escape'
)
;
await
.
.
press
(
'Escape'
)
;
await
delay
(
300
)
;
}
}
async
function
showSessionsSidebar
(
:
)
:
Promise
<
void
>
{
await
dismissDialogs
(
)
;
await
.
.
press
(
.
===
'darwin'
?
'Meta+Shift+P'
:
'Control+Shift+P'
)
;
await
delay
(
300
)
;
await
.
.
type
(
'Show Sessions'
,
{
:
30
}
)
;
await
delay
(
500
)
;
await
.
.
press
(
'Enter'
)
;
await
delay
(
1000
)
;
await
dismissDialogs
(
)
;
const
=
await
.
locator
(
)
.
count
(
)
;
console
.
log
(
` [sessions] sidebar shown, ${ sessionItems} session items visible `
)
;
}
async
function
clickSessionInList
(
:
,
:
number
)
:
Promise
<
void
>
{
await
dismissDialogs
(
)
;
const
=
.
locator
(
)
;
const
=
await
.
count
(
)
;
if
(
===
0
)
{
throw
new
Error
(
'No session items found in the sessions list'
)
;
}
const
=
.
min
(
,
-
1
)
;
const
=
.
nth
(
)
;
const
=
await
.
textContent
(
)
;
console
.
log
(
` [sessions] clicking session ${ sessionIndex} (list index ${ targetIndex} / ${ count} ): " ${ title?. substring ( 0 , 60 ) } ..." `
)
;
await
.
click
(
)
;
await
delay
(
300
)
;
}
async
function
waitForSessionContentToLoad
(
:
)
:
Promise
<
void
>
{
const
=
.
create
(
)
;
while
(
.
elapsed
(
)
<
15000
)
{
const
=
await
.
evaluate
(
(
{
,
,
}
)
=>
{
const
=
.
querySelector
(
)
;
if
(
!
)
{
return
false
;
}
const
=
.
querySelectorAll
(
)
;
const
=
.
querySelectorAll
(
)
;
return
.
>
0
&&
.
===
0
;
}
,
{
:
'.interactive-item-container.interactive-response'
,
:
,
:
'.interactive-item-container.chat-response-loading'
,
}
)
;
if
(
)
{
return
;
}
await
delay
(
100
)
;
}
console
.
log
(
'[sessions] warning: timed out waiting for session content to load'
)
;
}
async
function
sampleHeap
(
:
,
:
string
,
:
string
)
:
Promise
<
>
{
await
forceGarbageCollection
(
)
;
const
=
await
getPerformanceMetrics
(
)
;
const
=
await
getRuntimeHeapUsage
(
)
;
const
=
shouldTakeHeapSnapshot
(
)
?
.
join
(
,
'heap'
,
` ${ label} .heapsnapshot `
)
:
undefined
;
const
=
?
await
takeHeapSnapshot
(
,
)
:
undefined
;
const
:
=
{
,
:
.
get
(
'JSHeapUsedSize'
)
,
:
.
get
(
'JSHeapTotalSize'
)
,
:
?.
,
:
?.
,
,
,
}
;
console
.
log
(
` [heap] ${ label} : ${ formatBytes ( sample. runtimeUsedSize ?? sample. jsHeapUsedSize) } used, ${ snapshotBytes === undefined ? 'no snapshot' : ` ${ formatBytes ( snapshotBytes) } snapshot ` } `
)
;
return
;
}
async
function
forceGarbageCollection
(
:
)
:
Promise
<
void
>
{
await
.
send
(
'HeapProfiler.collectGarbage'
)
;
await
.
send
(
'HeapProfiler.collectGarbage'
)
;
}
async
function
getPerformanceMetrics
(
:
)
:
Promise
<
<
string
,
number
>>
{
const
=
await
.
send
(
'Performance.getMetrics'
)
;
return
new
Map
(
.
.
map
(
=>
[
.
,
.
]
)
)
;
}
async
function
getRuntimeHeapUsage
(
:
)
:
Promise
<
|
undefined
>
{
return
.
send
(
'Runtime.getHeapUsage'
)
.
catch
(
(
)
=>
undefined
)
;
}
async
function
takeHeapSnapshot
(
:
,
:
string
)
:
Promise
<
number
>
{
await
mkdir
(
.
dirname
(
)
,
{
:
true
}
)
;
const
=
createWriteStream
(
)
;
let
=
0
;
let
=
Promise
.
resolve
(
)
;
const
onChunk
=
(
:
{
:
string
}
)
=>
{
+=
.
byteLength
(
.
)
;
=
.
then
(
(
)
=>
new
Promise
(
(
,
)
=>
{
.
write
(
.
,
=>
?
reject
(
)
:
resolve
(
)
)
;
}
)
)
;
}
;
.
on
(
'HeapProfiler.addHeapSnapshotChunk'
,
)
;
try
{
await
.
send
(
'HeapProfiler.takeHeapSnapshot'
,
{
:
false
}
)
;
await
;
}
finally
{
.
off
(
'HeapProfiler.addHeapSnapshotChunk'
,
)
;
await
new
Promise < void >
(
(
,
)
=>
{
.
once
(
'error'
,
)
;
.
end
(
)
;
}
)
;
}
return
;
}
function
shouldTakeHeapSnapshot
(
:
string
)
:
boolean
{
return
.
&&
(
!
.
||
.
.
has
(
)
)
;
}
function
printSummary
(
:
[
]
,
:
string
)
:
void
{
console
.
log
(
` \nSummary written to ${ path. join ( outputDir, 'summary.json' ) } `
)
;
for
(
const
of
)
{
const
=
.
??
.
;
console
.
log
(
` ${ sample. label. padEnd ( 32 ) } ${ formatBytes ( heapSize) . padStart ( 10 ) } ${ sample. snapshot ? path. relative ( root, sample. snapshot) : '' } `
)
;
}
const
=
analyzeMemoryTrend
(
)
;
if
(
.
!==
undefined
)
{
console
.
log
(
` Post-first-switch growth: ${ formatSignedBytes ( trend. postFirstSwitchUsedBytes) } ( ${ formatSignedBytes ( trend. postFirstSwitchUsedBytesPerIteration) } /iteration) `
)
;
}
}
async
function
writeSummary
(
:
string
,
:
[
]
,
:
[
]
,
:
number
,
?
:
unknown
)
:
Promise
<
void
>
{
await
writeFile
(
.
join
(
,
'summary.json'
)
,
JSON
.
stringify
(
{
:
new
Date
(
)
.
toISOString
(
)
,
:
.
,
,
:
.
,
,
:
===
undefined
?
undefined
:
String
(
instanceof
Error
&&
.
?
.
:
)
,
:
analyzeMemoryTrend
(
)
,
,
}
,
undefined
,
'\t'
)
)
;
}
function
analyzeMemoryTrend
(
:
[
]
)
:
{
const
=
.
map
(
=>
.
??
.
)
;
const
=
.
at
(
0
)
;
const
=
.
at
(
-
1
)
;
const
=
.
filter
(
=>
.
.
startsWith
(
'04-switch-'
)
)
;
const
=
.
at
(
0
)
?.
??
.
at
(
0
)
?.
;
const
=
.
at
(
-
1
)
?.
??
.
at
(
-
1
)
?.
;
const
=
!==
undefined
&&
!==
undefined
&&
.
>
1
?
-
:
undefined
;
return
{
:
!==
undefined
&&
!==
undefined
&&
.
>
1
?
-
:
undefined
,
,
:
!==
undefined
?
/
(
.
-
1
)
:
undefined
,
}
;
}
function
formatBytes
(
:
number
|
undefined
)
:
string
{
if
(
typeof
!==
'number'
)
{
return
'unknown'
;
}
const
=
[
'B'
,
'KB'
,
'MB'
,
'GB'
]
;
let
=
;
let
=
0
;
while
(
>=
1024
&&
<
.
-
1
)
{
/=
1024
;
++
;
}
return
` ${ value. toFixed ( unitIndex === 0 ? 0 : 1 ) } ${ units[ unitIndex] } `
;
}
function
formatSignedBytes
(
:
number
|
undefined
)
:
string
{
if
(
===
undefined
)
{
return
'unknown'
;
}
return
` ${ bytes >= 0 ? '+' : '-' } ${ formatBytes ( Math. abs ( bytes) ) } `
;
}
function
getJson
(
:
string
)
:
Promise
<
void
>
{
return
new
Promise
(
(
,
)
=>
{
const
=
.
get
(
,
=>
{
.
resume
(
)
;
.
once
(
'end'
,
(
)
=>
.
===
200
?
resolve
(
undefined
)
:
reject
(
new
Error
(
` HTTP ${ response. statusCode} `
)
)
)
;
}
)
;
.
setTimeout
(
1000
,
(
)
=>
{
.
destroy
(
new
Error
(
'Request timed out'
)
)
;
}
)
;
.
once
(
'error'
,
)
;
}
)
;
}
function
parseArgs
(
:
string
[
]
)
:
{
const
=
new
Date
(
)
.
toISOString
(
)
.
replace
(
/ [ :.] / g
,
'-'
)
;
const
:
=
{
:
false
,
:
false
,
:
false
,
:
false
,
:
true
,
:
undefined
,
:
false
,
:
false
,
:
9224
,
:
5
,
:
120000
,
:
30000
,
:
3000
,
:
,
:
.
join
(
,
'.build'
,
'chat-session-switch-smoke'
,
)
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
if
(
===
'--help'
||
===
'-h'
)
{
.
=
true
;
}
else
if
(
===
'--verbose'
)
{
.
=
true
;
}
else
if
(
===
'--reuse'
)
{
.
=
true
;
}
else
if
(
===
'--skip-prelaunch'
)
{
.
=
true
;
}
else
if
(
===
'--no-heap-snapshots'
)
{
.
=
false
;
}
else
if
(
.
startsWith
(
'--heap-snapshot-label='
)
)
{
addHeapSnapshotLabels
(
,
.
slice
(
'--heap-snapshot-label='
.
)
)
;
}
else
if
(
===
'--heap-snapshot-label'
)
{
addHeapSnapshotLabels
(
,
readArgValue
(
,
++
,
)
)
;
}
else
if
(
===
'--keep-open'
)
{
.
=
true
;
}
else
if
(
===
'--temporary-user-data'
)
{
.
=
true
;
}
else
if
(
.
startsWith
(
'--'
)
)
{
const
[
,
]
=
splitArg
(
)
;
const
=
??
readArgValue
(
,
++
,
)
;
switch
(
)
{
case
'--port'
:
.
=
parseIntegerArg
(
,
,
1
)
;
break
;
case
'--switch-iterations'
:
.
=
parseIntegerArg
(
,
,
1
)
;
break
;
case
'--response-timeout'
:
.
=
parseIntegerArg
(
,
,
1
)
;
break
;
case
'--first-response-timeout'
:
.
=
parseIntegerArg
(
,
,
1
)
;
break
;
case
'--settle-ms'
:
.
=
parseIntegerArg
(
,
,
0
)
;
break
;
case
'--workspace'
:
.
=
.
resolve
(
)
;
break
;
case
'--output'
:
.
=
;
break
;
case
'--user-data-dir'
:
.
=
;
break
;
case
'--seed-user-data-dir'
:
.
=
;
break
;
case
'--extensions-dir'
:
.
=
;
break
;
default
:
throw
new
Error
(
` Unknown argument: ${ key} `
)
;
}
}
else
{
throw
new
Error
(
` Unexpected positional argument: ${ arg} `
)
;
}
}
return
;
}
function
addHeapSnapshotLabels
(
:
,
:
string
)
:
void
{
.
??=
new
Set
(
)
;
for
(
const
of
.
split
(
','
)
)
{
const
=
.
trim
(
)
;
if
(
)
{
.
.
add
(
)
;
}
}
}
function
splitArg
(
:
string
)
:
[
string
,
string
|
undefined
]
{
const
=
.
indexOf
(
'='
)
;
return
===
-
1
?
[
,
undefined
]
:
[
.
slice
(
0
,
)
,
.
slice
(
+
1
)
]
;
}
function
readArgValue
(
:
string
[
]
,
:
number
,
:
string
)
:
string
{
const
=
[
]
;
if
(
typeof
!==
'string'
)
{
throw
new
Error
(
` Missing value for ${ flag} `
)
;
}
return
;
}
function
parseIntegerArg
(
:
string
,
:
string
,
:
number
)
:
number
{
const
=
Number
(
)
;
if
(
!
.
isInteger
(
)
||
<
)
{
throw
new
Error
(
` ${ flag} must be an integer greater than or equal to ${ min} . Got: ${ value} `
)
;
}
return
;
}
function
printHelp
(
)
:
void
{
console
.
log
(
[
'Usage: node .github/skills/auto-perf-optimize/scripts/chat-session-switch-smoke.mts [options]'
,
''
,
'Creates multiple Chat sessions with different content types, then repeatedly'
,
'switches between them via the sessions list to verify no memory leaks.'
,
''
,
'Options:'
,
' --workspace <path> Workspace to open. Default: repo root'
,
' --output <path> Output folder. Default: .build/chat-session-switch-smoke/<timestamp>'
,
' --port <number> Remote debugging port. Default: 9224'
,
' --switch-iterations <number> Number of full switch cycles. Default: 5'
,
' --no-heap-snapshots Only record small heap-size metrics'
,
' --heap-snapshot-label <label> Only snapshot matching sample labels. Repeatable or comma-separated'
,
' --reuse Attach to an already-running --enable-smoke-test-driver window'
,
' --skip-prelaunch Set VSCODE_SKIP_PRELAUNCH=1'
,
' --temporary-user-data Use an output-local clean user-data-dir'
,
' --seed-user-data-dir <path> Copy a logged-in profile into a fresh target user-data-dir before launch'
,
' --keep-open Leave launched Code open'
,
' --verbose Show Code stdout/stderr'
,
''
,
'Example:'
,
' node .github/skills/auto-perf-optimize/scripts/chat-session-switch-smoke.mts --switch-iterations 3 --no-heap-snapshots'
,
]
.
join
(
'\n'
)
)
;
}