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-memory-smoke.mts 858 строк · изменён 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
import { chromium, type Browser , type CDPSession , type Locator , type Page } from 'playwright-core' ;
import { spawn, type ChildProcess } from 'node:child_process' ;
import { createWriteStream } from 'node:fs' ;
import mkdir rm writeFile
http
os
path
process
setTimeout timeout
StopWatch
prepareUserDataProfile
root path meta dirname
codeScript process platform path root path root
chatViewSelector
chatInputElementSelector
chatInputEditorSelector
chatResponseSelector
chatResponseLoadingSelector
chatResponseCompleteSelector
activeChatResponseMarker
activeChatInputMarker
activeChatInputSelector
activeChatInputEditorMarker
activeChatInputEditorSelector
selector text
global
driver SmokeTestDriver
label
jsHeapUsedSize
jsHeapTotalSize
runtimeUsedSize
runtimeTotalSize
snapshot
snapshotBytes
iteration
prompt
skippedSend
responseCountBefore
responseCountAfterSend
responseCountAfterSettled
responseStartReason
latestResponseTextBefore
latestResponseText
screenshot
help
verbose
reuse
skipSend
skipPrelaunch
heapSnapshots
heapSnapshotLabels Set
keepUserData
keepOpen
temporaryUserData
port
iterations
responseTimeout
firstResponseTimeout
settleMs
workspace
outputDir
userDataDir
seedUserDataDir
extensionDir
message
draftMessage
runtimeArgs
usedSize
totalSize
firstToLastUsedBytes
postFirstTurnUsedBytes
postFirstTurnUsedBytesPerTurn
child ChildProcess
failedBeforeConnect Error
signal NodeJS Signals
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 options keepUserData
reuse options reuse
userDataDir options userDataDir
seedUserDataDir options seedUserDataDir
options temporaryUserData options userDataDir
launchedCode LaunchedCode
browser Browser
session CDPSession
samples HeapSample
chatTurns ChatTurn
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
page
page path path outputDir
page options draftMessage
page
samples session outputDir
i i options iterations i
label i
message options message i
chatTurn i message
chatTurns chatTurn
page chatTurn options skipSend
chatTurn screenshot path outputDir
page path chatTurn screenshot
chatTurn latestResponseText page
outputDir samples chatTurns
chatTurn latestResponseText page
screenshot path outputDir
page path screenshot
chatTurn screenshot screenshot
page chatTurn options responseTimeout options settleMs
chatTurn screenshot path outputDir
page path chatTurn screenshot
chatTurn responseCountAfterSettled page chatResponseSelector
chatTurn latestResponseText page
samples session outputDir
outputDir samples chatTurns
samples outputDir
error
outputDir samples chatTurns error
error
session
shouldCloseCode
browser browserSession browserSession
browser
launchedCode shouldCloseCode
launchedCode child
launchedCode
launchedCode child
ownsUserDataDir
userDataDir recursive force maxRetries
dirs userDataDir extensionDir LaunchedCode
args
options runtimeArgs
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
page Page message
inputSelector page
page selector text
globalThis driver
globalThis driver selector text
selector inputSelector
text message
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
page
page keyboard process platform
page keyboard
iteration prompt ChatTurn
iteration
prompt
skippedSend
responseCountBefore
responseCountAfterSend
responseCountAfterSettled
responseStartReason
latestResponseText
latestResponseTextBefore
screenshot
page Page chatTurn ChatTurn skipSend
responseCount page chatResponseSelector
chatTurn responseCountBefore responseCount
chatTurn responseCountAfterSend responseCount
chatTurn latestResponseTextBefore page
page
page chatTurn prompt
skipSend
chatTurn skippedSend
page keyboard
chatTurn responseCountAfterSend page chatResponseSelector
responseStartReason page
responseSelector loadingSelector marker count textBefore
element Element
contentElement element element
contentElement contentElement innerText contentElement textContent
element Element
document element element marker
element marker
responses document responseSelector
latestText responses
responses length count
responses
loadingResponse document loadingSelector
loadingResponse
loadingResponse
latestText latestText textBefore
responses
responseSelector chatResponseSelector loadingSelector chatResponseLoadingSelector marker activeChatResponseMarker count responseCount textBefore chatTurn latestResponseTextBefore
timeout options firstResponseTimeout
result result
chatTurn responseStartReason responseStartReason
chatTurn responseCountAfterSend page chatResponseSelector
page Page chatTurn ChatTurn responseTimeout settleMs
chatTurn skippedSend
page
completeSelector loadingSelector countBefore textBefore
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 textBefore
completeSelector chatResponseCompleteSelector loadingSelector chatResponseLoadingSelector countBefore chatTurn responseCountBefore textBefore chatTurn latestResponseTextBefore
timeout responseTimeout
settleMs
page Page
page responseSelector
response document responseSelector
contentElement response response
contentElement contentElement innerText contentElement textContent
chatResponseSelector
value ChatTurn
value value value
value
session CDPSession outputDir label HeapSample
session
performanceMetrics session
runtimeHeapUsage session
snapshot label path outputDir
snapshotBytes snapshot session snapshot
sample
label
jsHeapUsedSize performanceMetrics
jsHeapTotalSize performanceMetrics
runtimeUsedSize runtimeHeapUsage usedSize
runtimeTotalSize runtimeHeapUsage totalSize
snapshot
snapshotBytes
sample
session CDPSession
session
session
session CDPSession Map
response session
response metrics metric metric name metric value
session CDPSession HeapUsage
session
session 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
session onChunk
session reportProgress
pendingWrite
session 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 postFirstTurnUsedBytes
outputDir samples HeapSample chatTurns ChatTurn error
path outputDir
createdAt
workspace options workspace
iterations options iterations
port options port
chatTurns
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
turnSamples samples sample sample label
firstTurnSize turnSamples runtimeUsedSize turnSamples jsHeapUsedSize
lastTurnSize turnSamples runtimeUsedSize turnSamples jsHeapUsedSize
postFirstTurnUsedBytes firstTurnSize lastTurnSize turnSamples length lastTurnSize firstTurnSize
firstToLastUsedBytes firstSize lastSize samples length lastSize firstSize
postFirstTurnUsedBytes
postFirstTurnUsedBytesPerTurn postFirstTurnUsedBytes postFirstTurnUsedBytes turnSamples length
template iteration
template iteration
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
skipSend
skipPrelaunch
heapSnapshots
heapSnapshotLabels
keepUserData
keepOpen
temporaryUserData
port
iterations
responseTimeout
firstResponseTimeout
settleMs
workspace root
outputDir path root timestamp
userDataDir
seedUserDataDir
extensionDir
message
draftMessage
runtimeArgs
i i args length i
arg args i
arg arg
parsed help
arg
parsed verbose
arg
parsed reuse
arg
parsed skipSend
arg
parsed skipPrelaunch
arg
parsed heapSnapshots
arg
parsed arg length
arg
parsed args i arg
arg
parsed keepUserData
arg
parsed keepOpen
arg
parsed temporaryUserData
arg
parsed runtimeArgs arg length
arg
parsed runtimeArgs args i arg
arg
key inlineValue arg
value inlineValue args i key
key
parsed port key value
parsed iterations 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 message value
parsed draftMessage value
parsed
options Options value
options heapSnapshotLabels
label value
trimmedLabel label
trimmedLabel
options 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
tmp path os
{
,
,
}
from
'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
=
'data-chat-memory-smoke-response-started'
;
const
=
'data-chat-memory-smoke-input'
;
const
=
` [ ${ activeChatInputMarker} ="true"] `
;
const
=
'data-chat-memory-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
ChatTurn
{
:
number
;
:
string
;
:
boolean
;
:
number
;
:
number
;
:
number
|
undefined
;
:
'response-count'
|
'loading'
|
'text-change'
|
undefined
;
:
string
|
undefined
;
:
string
|
undefined
;
:
string
|
undefined
;
}
interface
Options
{
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
boolean
;
:
<
string
>
|
undefined
;
:
boolean
;
:
boolean
;
:
boolean
;
:
number
;
:
number
;
:
number
;
:
number
;
:
number
;
:
string
;
:
string
;
:
string
|
undefined
;
:
string
|
undefined
;
:
string
|
undefined
;
:
string
;
:
string
;
:
string
[
]
;
}
interface
HeapUsage
{
:
number
;
:
number
;
}
interface
MemoryTrend
{
:
number
|
undefined
;
:
number
|
undefined
;
:
number
|
undefined
;
}
interface
LaunchedCode
{
:
;
:
Promise
<
>
;
markConnected
(
)
:
void
;
terminate
(
:
.
)
:
boolean
;
}
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'
)
,
:
.
,
:
.
,
:
.
,
:
.
,
:
.
,
:
.
,
}
)
;
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'
)
)
;
await
openChat
(
)
;
await
.
screenshot
(
{
:
.
join
(
,
'02-chat-open.png'
)
}
)
;
await
typeInChat
(
,
.
)
;
await
clearChatInput
(
)
;
.
push
(
await
sampleHeap
(
,
,
'02-chat-opened-and-drafted'
)
)
;
for
(
let
=
1
;
<=
.
;
++
)
{
const
=
String
(
)
.
padStart
(
2
,
'0'
)
;
const
=
expandMessage
(
.
,
)
;
const
=
createChatTurn
(
,
)
;
.
push
(
)
;
await
sendChatMessage
(
,
,
.
,
async
(
)
=>
{
.
=
.
join
(
,
` 03-iteration- ${ label} -submitted.png `
)
;
await
.
screenshot
(
{
:
.
}
)
;
.
=
await
getLatestChatResponseText
(
)
;
await
writeSummary
(
,
,
)
;
}
)
;
.
=
await
getLatestChatResponseText
(
)
;
const
=
.
join
(
,
` 03-iteration- ${ label} -after-send.png `
)
;
await
.
screenshot
(
{
:
}
)
;
.
=
;
await
waitForChatToSettle
(
,
,
.
,
.
)
;
.
=
.
join
(
,
` 03-iteration- ${ label} -settled.png `
)
;
await
.
screenshot
(
{
:
.
}
)
;
.
=
await
.
locator
(
)
.
count
(
)
;
.
=
await
getLatestChatResponseText
(
)
;
.
push
(
await
sampleHeap
(
,
,
` 03-iteration- ${ label} `
)
)
;
}
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
timeout
(
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
timeout
(
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
<
>
{
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
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
waitForInputEditorFocus
(
:
)
:
Promise
<
void
>
{
const
=
.
create
(
)
;
while
(
.
elapsed
(
)
<
5000
)
{
if
(
await
.
evaluate
(
=>
.
.
contains
(
'focused'
)
||
!
!
.
querySelector
(
':focus'
)
)
)
{
return
;
}
await
timeout
(
50
)
;
}
throw
new
Error
(
'Timed out waiting for Chat input editor focus'
)
;
}
async
function
markActiveChatInput
(
:
)
:
Promise
<
void
>
{
await
.
evaluate
(
(
,
{
,
}
)
=>
{
.
querySelectorAll
(
` [ ${ marker} ] `
)
.
forEach
(
=>
.
removeAttribute
(
)
)
;
const
=
.
querySelector
(
)
;
if
(
!
)
{
throw
new
Error
(
'Chat input not found'
)
;
}
.
setAttribute
(
,
'true'
)
;
}
,
{
:
,
:
}
)
;
}
async
function
clearChatInput
(
:
)
:
Promise
<
void
>
{
await
openChat
(
)
;
await
.
.
press
(
.
===
'darwin'
?
'Meta+A'
:
'Control+A'
)
;
await
.
.
press
(
'Backspace'
)
;
}
function
createChatTurn
(
:
number
,
:
string
)
:
{
return
{
,
,
:
false
,
:
0
,
:
0
,
:
undefined
,
:
undefined
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
}
async
function
sendChatMessage
(
:
,
:
,
:
boolean
,
onSubmitted
:
(
)
=>
Promise
<
void
>
)
:
Promise
<
void
>
{
const
=
await
.
locator
(
)
.
count
(
)
;
.
=
;
.
=
;
.
=
await
getLatestChatResponseText
(
)
;
await
clearChatInput
(
)
;
await
typeInChat
(
,
.
)
;
if
(
)
{
.
=
true
;
await
onSubmitted
(
)
;
return
;
}
await
.
.
press
(
'Enter'
)
;
.
=
await
.
locator
(
)
.
count
(
)
;
await
onSubmitted
(
)
;
const
=
await
.
waitForFunction
(
(
{
,
,
,
,
}
)
=>
{
const
getResponseText
=
(
:
|
undefined
)
=>
{
const
=
?.
querySelector
(
':scope > .value'
)
??
;
return
instanceof
HTMLElement
?
.
.
trim
(
)
:
?.
?.
trim
(
)
;
}
;
const
markResponse
=
(
:
|
undefined
)
=>
{
.
querySelectorAll
(
` [ ${ marker} ] `
)
.
forEach
(
=>
.
removeAttribute
(
)
)
;
?.
setAttribute
(
,
'true'
)
;
}
;
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
;
const
=
getResponseText
(
.
at
(
-
1
)
)
;
if
(
.
>
)
{
markResponse
(
.
at
(
-
1
)
)
;
return
'response-count'
;
}
const
=
.
querySelector
(
)
;
if
(
)
{
markResponse
(
)
;
return
'loading'
;
}
if
(
!
!
&&
!==
?.
trim
(
)
)
{
markResponse
(
.
at
(
-
1
)
)
;
return
'text-change'
;
}
return
false
;
}
,
{
:
,
:
,
:
,
:
,
:
.
}
,
{
:
.
}
)
.
then
(
=>
.
jsonValue
(
)
)
;
.
=
validateResponseStartReason
(
)
;
.
=
await
.
locator
(
)
.
count
(
)
;
}
async
function
waitForChatToSettle
(
:
,
:
,
:
number
,
:
number
)
:
Promise
<
void
>
{
if
(
.
)
{
return
;
}
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
timeout
(
)
;
}
async
function
getLatestChatResponseText
(
:
)
:
Promise
<
string
|
undefined
>
{
return
.
evaluate
(
=>
{
const
=
Array
.
from
(
.
querySelectorAll
(
)
)
.
at
(
-
1
)
;
const
=
?.
querySelector
(
':scope > .value'
)
??
;
return
instanceof
HTMLElement
?
.
:
?.
??
undefined
;
}
,
)
;
}
function
validateResponseStartReason
(
:
unknown
)
:
[
'responseStartReason'
]
{
if
(
===
'response-count'
||
===
'loading'
||
===
'text-change'
)
{
return
;
}
throw
new
Error
(
` Unexpected response start reason: ${ String ( value) } `
)
;
}
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-turn growth: ${ formatSignedBytes ( trend. postFirstTurnUsedBytes) } ( ${ formatSignedBytes ( trend. postFirstTurnUsedBytesPerTurn) } /turn) `
)
;
}
}
async
function
writeSummary
(
:
string
,
:
[
]
,
:
[
]
,
?
:
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
(
'03-iteration-'
)
)
;
const
=
.
at
(
0
)
?.
??
.
at
(
0
)
?.
;
const
=
.
at
(
-
1
)
?.
??
.
at
(
-
1
)
?.
;
const
=
!==
undefined
&&
!==
undefined
&&
.
>
1
?
-
:
undefined
;
return
{
:
!==
undefined
&&
!==
undefined
&&
.
>
1
?
-
:
undefined
,
,
:
!==
undefined
?
/
(
.
-
1
)
:
undefined
,
}
;
}
function
expandMessage
(
:
string
,
:
number
)
:
string
{
return
.
replace
(
/ \{ iteration\} / g
,
String
(
)
)
;
}
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
,
:
false
,
:
true
,
:
undefined
,
:
false
,
:
false
,
:
false
,
:
9224
,
:
3
,
:
120000
,
:
30000
,
:
3000
,
:
,
:
.
join
(
,
'.build'
,
'chat-memory-smoke'
,
)
,
:
undefined
,
:
undefined
,
:
undefined
,
:
'For memory-smoke iteration {iteration}, reply with exactly one short sentence.'
,
:
'draft message used by chat memory smoke'
,
:
[
]
,
}
;
for
(
let
=
0
;
<
.
;
++
)
{
const
=
[
]
;
if
(
===
'--help'
||
===
'-h'
)
{
.
=
true
;
}
else
if
(
===
'--verbose'
)
{
.
=
true
;
}
else
if
(
===
'--reuse'
)
{
.
=
true
;
}
else
if
(
===
'--skip-send'
)
{
.
=
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-user-data'
)
{
.
=
true
;
}
else
if
(
===
'--keep-open'
)
{
.
=
true
;
}
else
if
(
===
'--temporary-user-data'
)
{
.
=
true
;
}
else
if
(
.
startsWith
(
'--runtime-arg='
)
)
{
.
.
push
(
.
slice
(
'--runtime-arg='
.
)
)
;
}
else
if
(
===
'--runtime-arg'
)
{
.
.
push
(
readArgValue
(
,
++
,
)
)
;
}
else
if
(
.
startsWith
(
'--'
)
)
{
const
[
,
]
=
splitArg
(
)
;
const
=
??
readArgValue
(
,
++
,
)
;
switch
(
)
{
case
'--port'
:
.
=
parseIntegerArg
(
,
,
1
)
;
break
;
case
'--iterations'
:
.
=
parseIntegerArg
(
,
,
0
)
;
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
;
case
'--message'
:
.
=
;
break
;
case
'--draft-message'
:
.
=
;
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
{
const
=
.
join
(
.
tmpdir
(
)
,
'vscode-chat-memory-smoke'
)
;
console
.
log
(
[
'Usage: node .github/skills/auto-perf-optimize/scripts/chat-memory-smoke.mts [options]'
,
''
,
'Launches Code - OSS, opens Chat with Playwright, runs a small chat scenario, and writes renderer heap snapshots plus summary.json.'
,
''
,
'Options:'
,
' --workspace <path> Workspace to open. Default: repo root'
,
' --output <path> Output folder. Default: .build/chat-memory-smoke/<timestamp>'
,
' --port <number> Remote debugging port. Default: 9224'
,
' --iterations <number> Chat send iterations. Default: 3'
,
' --message <text> Prompt template. Use {iteration} for the loop number'
,
' --skip-send Type prompts but do not press Enter'
,
' --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 for the launched Code process'
,
' --temporary-user-data Use an output-local clean user-data-dir and delete it when the run completes'
,
' --seed-user-data-dir <path> Copy a logged-in profile into a fresh target user-data-dir before launch'
,
' --keep-user-data Preserve the generated temporary user-data-dir'
,
' --keep-open Leave launched Code open'
,
' --runtime-arg <arg> Forward one extra argument to scripts/code.sh. Repeatable'
,
''
,
'Example:'
,
` node .github/skills/auto-perf-optimize/scripts/chat-memory-smoke.mts --iterations 5 --output ${ tmp} `
,
''
,
'Watch/login/retry example:'
,
' node .github/skills/auto-perf-optimize/scripts/chat-memory-smoke.mts --keep-open --iterations 1 --no-heap-snapshots'
,
]
.
join
(
'\n'
)
)
;
}