@engineeros/connector 0.9.2 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/acp-client.mjs +381 -373
- package/src/agent-harness.mjs +196 -183
- package/src/codex-app-server.mjs +139 -0
- package/src/runner.mjs +1368 -1324
package/src/runner.mjs
CHANGED
|
@@ -1,1324 +1,1368 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
lstat,
|
|
4
|
-
mkdir,
|
|
5
|
-
readFile,
|
|
6
|
-
readdir,
|
|
7
|
-
stat,
|
|
8
|
-
writeFile,
|
|
9
|
-
} from "node:fs/promises";
|
|
10
|
-
import os from "node:os";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import { promisify } from "node:util";
|
|
13
|
-
import { deflateRaw } from "node:zlib";
|
|
14
|
-
import { launchAcpAgent } from "./acp-client.mjs";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
".
|
|
27
|
-
".
|
|
28
|
-
".
|
|
29
|
-
".
|
|
30
|
-
".
|
|
31
|
-
".
|
|
32
|
-
".
|
|
33
|
-
".
|
|
34
|
-
".
|
|
35
|
-
".
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
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
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
assignment.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
execution.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
assignment.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
committed.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
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
|
-
const
|
|
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
|
-
await run(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
"
|
|
224
|
-
"
|
|
225
|
-
"
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
const
|
|
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
|
-
const
|
|
286
|
-
const
|
|
287
|
-
const
|
|
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
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
assignment.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const
|
|
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
|
-
const
|
|
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
|
-
...pathLines(
|
|
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
|
-
const
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
execution.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
callbacks.
|
|
515
|
-
|
|
516
|
-
const
|
|
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
|
-
if (event
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (event
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (event.type === "
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
return
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
event.
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return { kind: "
|
|
639
|
-
}
|
|
640
|
-
if (event.type === "acp.
|
|
641
|
-
return {
|
|
642
|
-
kind: "
|
|
643
|
-
message:
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
if (
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
if (
|
|
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
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const
|
|
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
|
-
if (
|
|
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
|
-
const
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const
|
|
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
|
-
child.
|
|
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
|
-
if (
|
|
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
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
for (const
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1267
|
-
|
|
1268
|
-
if (
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
.
|
|
1280
|
-
.
|
|
1281
|
-
.
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
.
|
|
1287
|
-
.
|
|
1288
|
-
.
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import {
|
|
3
|
+
lstat,
|
|
4
|
+
mkdir,
|
|
5
|
+
readFile,
|
|
6
|
+
readdir,
|
|
7
|
+
stat,
|
|
8
|
+
writeFile,
|
|
9
|
+
} from "node:fs/promises";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { promisify } from "node:util";
|
|
13
|
+
import { deflateRaw } from "node:zlib";
|
|
14
|
+
import { launchAcpAgent } from "./acp-client.mjs";
|
|
15
|
+
import { launchCodexAppServer } from "./codex-app-server.mjs";
|
|
16
|
+
import {
|
|
17
|
+
buildAgentHarnessPrompt,
|
|
18
|
+
normalizeAgentStructuredOutput,
|
|
19
|
+
} from "./agent-harness.mjs";
|
|
20
|
+
|
|
21
|
+
const deflate = promisify(deflateRaw);
|
|
22
|
+
const MAX_ARCHIVE_BYTES = 25 * 1024 * 1024;
|
|
23
|
+
const MAX_SHAREABLE_FILE_BYTES = 5 * 1024 * 1024;
|
|
24
|
+
const MAX_WORKSPACE_FILES = 5_000;
|
|
25
|
+
const EXCLUDED_DIRECTORIES = new Set([
|
|
26
|
+
".agents",
|
|
27
|
+
".claude",
|
|
28
|
+
".codex",
|
|
29
|
+
".engineeros",
|
|
30
|
+
".forge",
|
|
31
|
+
".gemini",
|
|
32
|
+
".git",
|
|
33
|
+
".next",
|
|
34
|
+
".pytest_cache",
|
|
35
|
+
".ruff_cache",
|
|
36
|
+
".venv",
|
|
37
|
+
"__pycache__",
|
|
38
|
+
"build",
|
|
39
|
+
"coverage",
|
|
40
|
+
"dist",
|
|
41
|
+
"node_modules",
|
|
42
|
+
"target",
|
|
43
|
+
"vendor",
|
|
44
|
+
]);
|
|
45
|
+
const EXCLUDED_PATH_PREFIXES = [".github/skills/"];
|
|
46
|
+
const EXCLUDED_FILE_EXTENSIONS = new Set([
|
|
47
|
+
".7z",
|
|
48
|
+
".a",
|
|
49
|
+
".bin",
|
|
50
|
+
".class",
|
|
51
|
+
".dll",
|
|
52
|
+
".dylib",
|
|
53
|
+
".exe",
|
|
54
|
+
".gz",
|
|
55
|
+
".jar",
|
|
56
|
+
".lib",
|
|
57
|
+
".o",
|
|
58
|
+
".obj",
|
|
59
|
+
".pyc",
|
|
60
|
+
".pyo",
|
|
61
|
+
".rar",
|
|
62
|
+
".so",
|
|
63
|
+
".tar",
|
|
64
|
+
".tgz",
|
|
65
|
+
".war",
|
|
66
|
+
".zip",
|
|
67
|
+
]);
|
|
68
|
+
const CODE_EXTENSIONS = new Set([
|
|
69
|
+
".c",
|
|
70
|
+
".cpp",
|
|
71
|
+
".cs",
|
|
72
|
+
".go",
|
|
73
|
+
".h",
|
|
74
|
+
".java",
|
|
75
|
+
".js",
|
|
76
|
+
".jsx",
|
|
77
|
+
".mjs",
|
|
78
|
+
".php",
|
|
79
|
+
".py",
|
|
80
|
+
".rb",
|
|
81
|
+
".rs",
|
|
82
|
+
".sql",
|
|
83
|
+
".ts",
|
|
84
|
+
".tsx",
|
|
85
|
+
]);
|
|
86
|
+
const CODE_MARKERS = new Set([
|
|
87
|
+
"cargo.toml",
|
|
88
|
+
"composer.json",
|
|
89
|
+
"go.mod",
|
|
90
|
+
"package.json",
|
|
91
|
+
"pom.xml",
|
|
92
|
+
"pyproject.toml",
|
|
93
|
+
"requirements.txt",
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
export async function executeAssignment(assignment, config, callbacks) {
|
|
97
|
+
const execution = connectorExecution(assignment);
|
|
98
|
+
const runWorkspace = await prepareRunWorkspace(
|
|
99
|
+
config.workspace,
|
|
100
|
+
assignment.run_id,
|
|
101
|
+
assignment.base_revision,
|
|
102
|
+
);
|
|
103
|
+
const controller = launchAgentProcess(
|
|
104
|
+
runWorkspace,
|
|
105
|
+
execution.prompt,
|
|
106
|
+
execution.sandboxMode,
|
|
107
|
+
config,
|
|
108
|
+
callbacks,
|
|
109
|
+
execution.profile,
|
|
110
|
+
undefined,
|
|
111
|
+
{ runId: assignment.run_id },
|
|
112
|
+
);
|
|
113
|
+
callbacks.onProcess?.(controller.child);
|
|
114
|
+
await controller.completed;
|
|
115
|
+
const changedFiles = await changedFilePaths(runWorkspace);
|
|
116
|
+
if (!changedFiles.length)
|
|
117
|
+
throw new Error("Agent completed without changing any files.");
|
|
118
|
+
const committed = await commitRunChange(
|
|
119
|
+
runWorkspace,
|
|
120
|
+
assignment.base_revision,
|
|
121
|
+
assignment.run_id,
|
|
122
|
+
);
|
|
123
|
+
const verificationHeading = "# Verification Report";
|
|
124
|
+
const verifier = launchAgentProcess(
|
|
125
|
+
runWorkspace,
|
|
126
|
+
buildAgentHarnessPrompt({
|
|
127
|
+
agentRole: "verification",
|
|
128
|
+
prompt: verificationPrompt(
|
|
129
|
+
assignment,
|
|
130
|
+
committed.revision,
|
|
131
|
+
committed.changedFiles,
|
|
132
|
+
),
|
|
133
|
+
sandboxMode: "read-only",
|
|
134
|
+
requiredOutputHeading: verificationHeading,
|
|
135
|
+
}),
|
|
136
|
+
"read-only",
|
|
137
|
+
config,
|
|
138
|
+
callbacks,
|
|
139
|
+
execution.profile,
|
|
140
|
+
);
|
|
141
|
+
callbacks.onProcess?.(verifier.child);
|
|
142
|
+
const verification = await verifier.completed;
|
|
143
|
+
const verificationReport = normalizeAgentStructuredOutput(
|
|
144
|
+
verification.finalMessage,
|
|
145
|
+
verificationHeading,
|
|
146
|
+
);
|
|
147
|
+
const proofEvidence = parseVerificationReport(
|
|
148
|
+
verificationReport,
|
|
149
|
+
assignment.proof_checks,
|
|
150
|
+
config.connector_id,
|
|
151
|
+
assignment.run_id,
|
|
152
|
+
);
|
|
153
|
+
return {
|
|
154
|
+
head_revision: committed.revision,
|
|
155
|
+
repository_locator: assignment.repository_locator,
|
|
156
|
+
external_reference: `connector:${config.connector_id}/run:${assignment.run_id}`,
|
|
157
|
+
diff_patch: committed.diffPatch,
|
|
158
|
+
changed_files: committed.changedFiles,
|
|
159
|
+
proof_evidence: proofEvidence,
|
|
160
|
+
verification_report: verificationReport,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function applyAcceptedChange(
|
|
165
|
+
workspace,
|
|
166
|
+
baseRevision,
|
|
167
|
+
headRevision,
|
|
168
|
+
) {
|
|
169
|
+
const current = await run("git", ["rev-parse", "HEAD"], workspace, {
|
|
170
|
+
allowFailure: true,
|
|
171
|
+
});
|
|
172
|
+
if (current.code !== 0) {
|
|
173
|
+
return {
|
|
174
|
+
applied: false,
|
|
175
|
+
reason: "The connected workspace is not a Git repository.",
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const currentHead = current.stdout.trim();
|
|
179
|
+
const alreadyApplied = await run(
|
|
180
|
+
"git",
|
|
181
|
+
["merge-base", "--is-ancestor", headRevision, currentHead],
|
|
182
|
+
workspace,
|
|
183
|
+
{ allowFailure: true },
|
|
184
|
+
);
|
|
185
|
+
if (alreadyApplied.code === 0)
|
|
186
|
+
return { applied: true, revision: currentHead };
|
|
187
|
+
const status = await run("git", ["status", "--porcelain"], workspace);
|
|
188
|
+
if (status.stdout.trim()) {
|
|
189
|
+
return {
|
|
190
|
+
applied: false,
|
|
191
|
+
reason: `The connected workspace has uncommitted changes. Apply accepted commit ${headRevision} after preserving them.`,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (currentHead !== baseRevision) {
|
|
195
|
+
return {
|
|
196
|
+
applied: false,
|
|
197
|
+
reason: `The connected branch moved from frozen base ${baseRevision} to ${currentHead}. Apply accepted commit ${headRevision} with git cherry-pick.`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const applied = await run("git", ["cherry-pick", headRevision], workspace, {
|
|
201
|
+
allowFailure: true,
|
|
202
|
+
});
|
|
203
|
+
if (applied.code !== 0) {
|
|
204
|
+
await run("git", ["cherry-pick", "--abort"], workspace, {
|
|
205
|
+
allowFailure: true,
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
applied: false,
|
|
209
|
+
reason: `The accepted commit ${headRevision} could not be applied cleanly. Apply it manually with git cherry-pick.`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const integrated = await run("git", ["rev-parse", "HEAD"], workspace);
|
|
213
|
+
return { applied: true, revision: integrated.stdout.trim() };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function commitRunChange(workspace, baseRevision, runId) {
|
|
217
|
+
await run("git", ["add", "-A"], workspace);
|
|
218
|
+
await run(
|
|
219
|
+
"git",
|
|
220
|
+
[
|
|
221
|
+
"-c",
|
|
222
|
+
"user.name=EngineerOS Codex",
|
|
223
|
+
"-c",
|
|
224
|
+
"user.email=codex@engineeros.local",
|
|
225
|
+
"commit",
|
|
226
|
+
"-m",
|
|
227
|
+
`EngineerOS Goal Run ${runId}`,
|
|
228
|
+
],
|
|
229
|
+
workspace,
|
|
230
|
+
);
|
|
231
|
+
const head = await run("git", ["rev-parse", "HEAD"], workspace);
|
|
232
|
+
const revision = head.stdout.trim();
|
|
233
|
+
const diff = await run(
|
|
234
|
+
"git",
|
|
235
|
+
["diff", "--binary", baseRevision, revision, "--"],
|
|
236
|
+
workspace,
|
|
237
|
+
);
|
|
238
|
+
const paths = await run(
|
|
239
|
+
"git",
|
|
240
|
+
["diff", "--name-only", "-z", baseRevision, revision, "--"],
|
|
241
|
+
workspace,
|
|
242
|
+
);
|
|
243
|
+
return {
|
|
244
|
+
revision,
|
|
245
|
+
diffPatch: diff.stdout,
|
|
246
|
+
changedFiles: gitPathList(paths.stdout).sort(),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function verificationPrompt(assignment, revision, changedFiles) {
|
|
251
|
+
const checks = (assignment.proof_checks ?? [])
|
|
252
|
+
.map(
|
|
253
|
+
(proof, index) =>
|
|
254
|
+
`## Proof ${index + 1}\n- Check: ${proof.check ?? ""}\n- Expected: ${proof.expected ?? ""}`,
|
|
255
|
+
)
|
|
256
|
+
.join("\n\n");
|
|
257
|
+
return `# EngineerOS Connected Verification
|
|
258
|
+
|
|
259
|
+
Independently verify the frozen Goal at Git commit \`${revision}\`. Do not modify files. Run the commands or inspections needed for every Proof item, and check the Goal boundaries and constraints in the supplied packet.
|
|
260
|
+
|
|
261
|
+
Changed files:
|
|
262
|
+
${changedFiles.map((item) => `- \`${item}\``).join("\n")}
|
|
263
|
+
|
|
264
|
+
${checks}
|
|
265
|
+
|
|
266
|
+
Return structured Markdown only, with exactly one section per Proof:
|
|
267
|
+
|
|
268
|
+
## Proof 1
|
|
269
|
+
- Status: passed or failed
|
|
270
|
+
- Exit code: integer or none
|
|
271
|
+
- Evidence: concise observed output and command
|
|
272
|
+
|
|
273
|
+
Do not claim a Proof passed unless you observed it directly.`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function parseVerificationReport(
|
|
277
|
+
report,
|
|
278
|
+
proofChecks,
|
|
279
|
+
connectorId,
|
|
280
|
+
runId,
|
|
281
|
+
) {
|
|
282
|
+
if (!report?.trim())
|
|
283
|
+
throw new Error("Codex returned no connected verification report.");
|
|
284
|
+
return (proofChecks ?? []).map((_, index) => {
|
|
285
|
+
const start = new RegExp(`^## Proof ${index + 1}\\s*$`, "im").exec(report);
|
|
286
|
+
const tail = start ? report.slice(start.index + start[0].length) : "";
|
|
287
|
+
const section = tail.split(/^## Proof \d+\s*$/im)[0] ?? "";
|
|
288
|
+
const status =
|
|
289
|
+
/^- Status:\s*(passed|failed)\s*$/im.exec(section)?.[1] ?? "failed";
|
|
290
|
+
const exitValue =
|
|
291
|
+
/^- Exit code:\s*(\d+|none)\s*$/im.exec(section)?.[1] ?? "none";
|
|
292
|
+
const evidence = /^- Evidence:\s*(.+)$/im.exec(section)?.[1]?.trim();
|
|
293
|
+
return {
|
|
294
|
+
proof_index: index,
|
|
295
|
+
status,
|
|
296
|
+
verifier_type: "agent_reported",
|
|
297
|
+
verifier_identity: "Connected Codex CLI verifier",
|
|
298
|
+
locator: `connector:${connectorId}/run:${runId}#proof-${index + 1}`,
|
|
299
|
+
output_excerpt:
|
|
300
|
+
evidence ||
|
|
301
|
+
"The connected verifier did not provide evidence for this Proof.",
|
|
302
|
+
exit_code: exitValue === "none" ? null : Number(exitValue),
|
|
303
|
+
};
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export async function executeWorkspaceAssessment(
|
|
308
|
+
assignment,
|
|
309
|
+
config,
|
|
310
|
+
callbacks,
|
|
311
|
+
) {
|
|
312
|
+
const execution = workspaceAssessmentExecution(assignment);
|
|
313
|
+
const startingRevision = await run(
|
|
314
|
+
"git",
|
|
315
|
+
["rev-parse", "HEAD"],
|
|
316
|
+
config.workspace,
|
|
317
|
+
{ allowFailure: true },
|
|
318
|
+
);
|
|
319
|
+
const startingHead =
|
|
320
|
+
startingRevision.code === 0
|
|
321
|
+
? startingRevision.stdout.trim().slice(0, 128)
|
|
322
|
+
: null;
|
|
323
|
+
if (
|
|
324
|
+
assignment.target_head_revision &&
|
|
325
|
+
startingHead !== assignment.target_head_revision
|
|
326
|
+
) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
"This workspace is no longer at the commit inventoried by EngineerOS. Refresh the workspace inventory before assessing it.",
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
const changeImpact =
|
|
332
|
+
assignment.assessment_mode === "incremental"
|
|
333
|
+
? await workspaceChangeImpact(
|
|
334
|
+
config.workspace,
|
|
335
|
+
assignment.base_head_revision,
|
|
336
|
+
assignment.target_head_revision,
|
|
337
|
+
)
|
|
338
|
+
: { changedFiles: [], markdown: null };
|
|
339
|
+
const prompt = changeImpact.markdown
|
|
340
|
+
? execution.prompt.replace(
|
|
341
|
+
"<!-- ENGINEEROS_CHANGE_IMPACT -->",
|
|
342
|
+
changeImpact.markdown,
|
|
343
|
+
)
|
|
344
|
+
: execution.prompt;
|
|
345
|
+
const controller = launchAgentProcess(
|
|
346
|
+
config.workspace,
|
|
347
|
+
prompt,
|
|
348
|
+
execution.sandboxMode,
|
|
349
|
+
config,
|
|
350
|
+
callbacks,
|
|
351
|
+
execution.profile,
|
|
352
|
+
);
|
|
353
|
+
callbacks.onProcess?.(controller.child);
|
|
354
|
+
const completed = await controller.completed;
|
|
355
|
+
const report = normalizeAgentStructuredOutput(
|
|
356
|
+
completed.finalMessage,
|
|
357
|
+
execution.requiredOutputHeading,
|
|
358
|
+
);
|
|
359
|
+
const endingRevision = await run(
|
|
360
|
+
"git",
|
|
361
|
+
["rev-parse", "HEAD"],
|
|
362
|
+
config.workspace,
|
|
363
|
+
{ allowFailure: true },
|
|
364
|
+
);
|
|
365
|
+
const endingHead =
|
|
366
|
+
endingRevision.code === 0
|
|
367
|
+
? endingRevision.stdout.trim().slice(0, 128)
|
|
368
|
+
: null;
|
|
369
|
+
if (startingHead !== endingHead) {
|
|
370
|
+
throw new Error(
|
|
371
|
+
"The Git commit changed during assessment. Refresh the workspace inventory and assess the new commit.",
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
report_markdown: report,
|
|
376
|
+
observed_head_revision: endingHead,
|
|
377
|
+
changed_files: changeImpact.changedFiles,
|
|
378
|
+
change_impact_markdown: changeImpact.markdown,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export async function workspaceChangeImpact(
|
|
383
|
+
workspace,
|
|
384
|
+
baseRevision,
|
|
385
|
+
targetRevision,
|
|
386
|
+
) {
|
|
387
|
+
if (!baseRevision || !targetRevision) {
|
|
388
|
+
throw new Error(
|
|
389
|
+
"Incremental assessment requires both the previously assessed and current Git commits. Run a full assessment instead.",
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
const range = `${baseRevision}..${targetRevision}`;
|
|
393
|
+
const names = await run(
|
|
394
|
+
"git",
|
|
395
|
+
["diff", "--name-status", "--find-renames", range],
|
|
396
|
+
workspace,
|
|
397
|
+
{ allowFailure: true },
|
|
398
|
+
);
|
|
399
|
+
if (names.code !== 0) {
|
|
400
|
+
throw new Error(
|
|
401
|
+
"Codex could not compare the assessed and current commits. Fetch the missing Git history or run a full assessment.",
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
const committedFiles = await run(
|
|
405
|
+
"git",
|
|
406
|
+
["-c", "core.quotepath=false", "diff", "--name-only", range],
|
|
407
|
+
workspace,
|
|
408
|
+
{ allowFailure: true },
|
|
409
|
+
);
|
|
410
|
+
const workingFiles = await run(
|
|
411
|
+
"git",
|
|
412
|
+
[
|
|
413
|
+
"-c",
|
|
414
|
+
"core.quotepath=false",
|
|
415
|
+
"ls-files",
|
|
416
|
+
"--others",
|
|
417
|
+
"--modified",
|
|
418
|
+
"--deleted",
|
|
419
|
+
"--exclude-standard",
|
|
420
|
+
],
|
|
421
|
+
workspace,
|
|
422
|
+
{ allowFailure: true },
|
|
423
|
+
);
|
|
424
|
+
const status = await run("git", ["status", "--short"], workspace, {
|
|
425
|
+
allowFailure: true,
|
|
426
|
+
});
|
|
427
|
+
const stat = await run(
|
|
428
|
+
"git",
|
|
429
|
+
["diff", "--stat", "--compact-summary", range],
|
|
430
|
+
workspace,
|
|
431
|
+
{ allowFailure: true },
|
|
432
|
+
);
|
|
433
|
+
const allChangedFiles = [
|
|
434
|
+
...new Set([
|
|
435
|
+
...pathLines(committedFiles.stdout),
|
|
436
|
+
...pathLines(workingFiles.stdout),
|
|
437
|
+
]),
|
|
438
|
+
];
|
|
439
|
+
if (allChangedFiles.length > 500) {
|
|
440
|
+
throw new Error(
|
|
441
|
+
`This change affects ${allChangedFiles.length} paths, above the 500-path incremental limit. Run a full reassessment instead.`,
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const changedFiles = allChangedFiles;
|
|
445
|
+
if (!changedFiles.length) {
|
|
446
|
+
throw new Error(
|
|
447
|
+
"The inventoried repository changed but Git reports no assessable paths. Refresh inventory or run a full assessment.",
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
const lines = [
|
|
451
|
+
`Comparison: \`${range}\``,
|
|
452
|
+
`Changed paths: ${changedFiles.length}`,
|
|
453
|
+
"",
|
|
454
|
+
"### Name status",
|
|
455
|
+
"",
|
|
456
|
+
"```text",
|
|
457
|
+
boundedText(names.stdout, 12_000),
|
|
458
|
+
"```",
|
|
459
|
+
];
|
|
460
|
+
if (status.stdout.trim()) {
|
|
461
|
+
lines.push(
|
|
462
|
+
"",
|
|
463
|
+
"### Working tree",
|
|
464
|
+
"",
|
|
465
|
+
"```text",
|
|
466
|
+
boundedText(status.stdout, 6_000),
|
|
467
|
+
"```",
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
if (stat.stdout.trim()) {
|
|
471
|
+
lines.push(
|
|
472
|
+
"",
|
|
473
|
+
"### Diff summary",
|
|
474
|
+
"",
|
|
475
|
+
"```text",
|
|
476
|
+
boundedText(stat.stdout, 6_000),
|
|
477
|
+
"```",
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
return { changedFiles, markdown: lines.join("\n") };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function pathLines(output) {
|
|
484
|
+
return String(output || "")
|
|
485
|
+
.split(/\r?\n/)
|
|
486
|
+
.map((line) => line.trim())
|
|
487
|
+
.filter(Boolean)
|
|
488
|
+
.map((line) => line.replace(/^"|"$/g, ""));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function boundedText(value, maximum) {
|
|
492
|
+
const text = String(value || "").trim();
|
|
493
|
+
return text.length <= maximum
|
|
494
|
+
? text
|
|
495
|
+
: `${text.slice(0, maximum)}\n... truncated by EngineerOS`;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export async function executeConnectedPrompt(assignment, config, callbacks) {
|
|
499
|
+
const execution = connectorExecution(assignment);
|
|
500
|
+
const previousSessionId = config.sessions?.[execution.sessionKey];
|
|
501
|
+
const controller = launchAgentProcess(
|
|
502
|
+
config.workspace,
|
|
503
|
+
execution.prompt,
|
|
504
|
+
execution.sandboxMode,
|
|
505
|
+
config,
|
|
506
|
+
callbacks,
|
|
507
|
+
execution.profile,
|
|
508
|
+
previousSessionId,
|
|
509
|
+
{
|
|
510
|
+
persistentAcp: true,
|
|
511
|
+
sessionKey: execution.sessionKey,
|
|
512
|
+
},
|
|
513
|
+
);
|
|
514
|
+
callbacks.onController?.(controller);
|
|
515
|
+
callbacks.onProcess?.(controller.child);
|
|
516
|
+
const completed = await controller.completed;
|
|
517
|
+
const content = sanitizeAgentResponse(completed.finalMessage).trim();
|
|
518
|
+
if (!content) {
|
|
519
|
+
throw new Error("Agent completed without returning a response.");
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
content,
|
|
523
|
+
model: completed.model ?? config.agent_protocol ?? "coding-agent",
|
|
524
|
+
sessionId: completed.sessionId,
|
|
525
|
+
sessionKey: execution.sessionKey,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export async function inspectCodingAgent(config, workspace = process.cwd()) {
|
|
530
|
+
if (config.agent_protocol === "acp") {
|
|
531
|
+
if (!config.agent_command) {
|
|
532
|
+
throw new Error(
|
|
533
|
+
"ACP requires --agent-command when pairing the connector.",
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
protocol: "acp",
|
|
538
|
+
name: config.agent_name || path.basename(config.agent_command),
|
|
539
|
+
version: config.agent_version || "ACP v1",
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const codex = await inspectCodexCli(workspace);
|
|
543
|
+
return { protocol: "codex", name: "Codex CLI", version: codex.version };
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export async function inspectCodexCli(workspace = process.cwd()) {
|
|
547
|
+
const command =
|
|
548
|
+
process.env.CODEX_BIN ||
|
|
549
|
+
(process.platform === "win32" ? "codex.cmd" : "codex");
|
|
550
|
+
const result = await runCodexCommand(command, ["--version"], workspace);
|
|
551
|
+
if (result.code !== 0) {
|
|
552
|
+
throw new Error(
|
|
553
|
+
"Codex CLI is unavailable. Install it with `npm install -g @openai/codex@latest`, run `codex login`, then restart this connector.",
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
const version = result.stdout.trim().slice(0, 100);
|
|
557
|
+
if (!version) {
|
|
558
|
+
throw new Error(
|
|
559
|
+
"Codex CLI returned no version. Reinstall @openai/codex, then restart this connector.",
|
|
560
|
+
);
|
|
561
|
+
}
|
|
562
|
+
return { command, version };
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function codexFailureMessage(output, code) {
|
|
566
|
+
if (/requires a newer version of Codex/i.test(output)) {
|
|
567
|
+
return (
|
|
568
|
+
"The configured model requires a newer Codex CLI. " +
|
|
569
|
+
"Run `npm install -g @openai/codex@latest`, verify with `codex --version`, " +
|
|
570
|
+
"then restart the EngineerOS connector and retry the assessment."
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
if (/not logged in|login required|authentication required/i.test(output)) {
|
|
574
|
+
return "Codex CLI is not authenticated. Run `codex login`, then restart the EngineerOS connector.";
|
|
575
|
+
}
|
|
576
|
+
return `Codex exited with code ${code}. ${output.slice(-1_000)}`;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export function assessmentProgressMessage(event) {
|
|
580
|
+
if (!event || typeof event !== "object") return null;
|
|
581
|
+
if (event.type === "turn.started")
|
|
582
|
+
return "Reviewing repository structure and current Git state";
|
|
583
|
+
if (event.type === "item.started") {
|
|
584
|
+
if (event.item?.type === "command_execution") {
|
|
585
|
+
return assessmentCommandMilestone(event.item.command);
|
|
586
|
+
}
|
|
587
|
+
if (event.item?.type === "mcp_tool_call")
|
|
588
|
+
return "Tracing architecture and code relationships";
|
|
589
|
+
if (event.item?.type === "web_search")
|
|
590
|
+
return "Checking an external technical reference";
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
if (event.type === "item.completed" && event.item?.type === "agent_message") {
|
|
594
|
+
return "Synthesizing findings and highest-return actions";
|
|
595
|
+
}
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export function promptProgressMessage(event) {
|
|
600
|
+
if (!event || typeof event !== "object") return null;
|
|
601
|
+
if (event.type === "turn.started")
|
|
602
|
+
return "Reviewing the request and workspace context";
|
|
603
|
+
if (event.type === "item.started") {
|
|
604
|
+
if (event.item?.type === "command_execution") {
|
|
605
|
+
return assessmentCommandMilestone(event.item.command);
|
|
606
|
+
}
|
|
607
|
+
if (event.item?.type === "mcp_tool_call")
|
|
608
|
+
return "Checking connected project evidence";
|
|
609
|
+
if (event.item?.type === "web_search")
|
|
610
|
+
return "Checking an external technical reference";
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
if (event.type === "item.completed" && event.item?.type === "agent_message") {
|
|
614
|
+
return "Preparing the response";
|
|
615
|
+
}
|
|
616
|
+
if (event.type === "agent.connected") return "Agent connected";
|
|
617
|
+
if (event.type === "acp.tool_call" || event.type === "acp.tool_call_update") {
|
|
618
|
+
return "Agent is inspecting the workspace";
|
|
619
|
+
}
|
|
620
|
+
if (event.type === "acp.agent_message_chunk") return "Preparing the response";
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function promptStreamEvent(event) {
|
|
625
|
+
if (!event || typeof event !== "object") return null;
|
|
626
|
+
if (
|
|
627
|
+
event.type === "codex.agent_message_delta" &&
|
|
628
|
+
typeof event.delta === "string"
|
|
629
|
+
) {
|
|
630
|
+
const delta = sanitizeAgentResponse(event.delta);
|
|
631
|
+
return delta ? { kind: "message", delta } : null;
|
|
632
|
+
}
|
|
633
|
+
if (
|
|
634
|
+
event.type === "acp.agent_message_chunk" &&
|
|
635
|
+
event.update?.content?.type === "text"
|
|
636
|
+
) {
|
|
637
|
+
const delta = sanitizeAgentResponse(event.update.content.text);
|
|
638
|
+
return delta ? { kind: "message", delta } : null;
|
|
639
|
+
}
|
|
640
|
+
if (event.type === "acp.agent_thought_chunk") {
|
|
641
|
+
return {
|
|
642
|
+
kind: "thought",
|
|
643
|
+
message: "Agent is reasoning through the request",
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
if (event.type === "acp.permission") {
|
|
647
|
+
return {
|
|
648
|
+
kind: "permission",
|
|
649
|
+
message: event.update?.title || "Agent requested workspace permission",
|
|
650
|
+
status: event.update?.status,
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
if (event.type === "codex.usage") {
|
|
654
|
+
return { kind: "usage", message: "Agent usage updated" };
|
|
655
|
+
}
|
|
656
|
+
if (event.type === "acp.plan") {
|
|
657
|
+
return { kind: "plan", message: "Agent updated the working plan" };
|
|
658
|
+
}
|
|
659
|
+
if (event.type === "acp.tool_call" || event.type === "acp.tool_call_update") {
|
|
660
|
+
return {
|
|
661
|
+
kind: "tool",
|
|
662
|
+
message: event.update?.title || "Agent is inspecting the workspace",
|
|
663
|
+
status: event.update?.status,
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
if (event.type === "item.completed" && event.item?.type === "agent_message") {
|
|
667
|
+
const delta = sanitizeAgentResponse(event.item.text);
|
|
668
|
+
return delta ? { kind: "message", delta } : null;
|
|
669
|
+
}
|
|
670
|
+
const message = promptProgressMessage(event);
|
|
671
|
+
return message ? { kind: "status", message } : null;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export function assessmentStreamDelta(event) {
|
|
675
|
+
const streamEvent = promptStreamEvent(event);
|
|
676
|
+
if (streamEvent?.kind !== "message" || !streamEvent.delta) return null;
|
|
677
|
+
return event.type === "item.completed"
|
|
678
|
+
? `${streamEvent.delta.trim()}\n\n`
|
|
679
|
+
: streamEvent.delta;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function assessmentCommandMilestone(command) {
|
|
683
|
+
const value = Array.isArray(command)
|
|
684
|
+
? command.join(" ")
|
|
685
|
+
: String(command || "");
|
|
686
|
+
const normalized = value.replace(/\s+/g, " ").trim().toLowerCase();
|
|
687
|
+
if (!normalized) return "Inspecting repository evidence";
|
|
688
|
+
if (/\bgit\s+(status|log|diff|show|rev-parse)\b/.test(normalized)) {
|
|
689
|
+
return "Comparing Git history and workspace changes";
|
|
690
|
+
}
|
|
691
|
+
if (
|
|
692
|
+
/\b(test|pytest|vitest|jest|ruff|eslint|tsc|build|lint)\b/.test(normalized)
|
|
693
|
+
) {
|
|
694
|
+
return "Checking verification and delivery signals";
|
|
695
|
+
}
|
|
696
|
+
if (
|
|
697
|
+
/\b(audit|dependency|dependencies|lockfile|package-lock|pnpm-lock|requirements)\b/.test(
|
|
698
|
+
normalized,
|
|
699
|
+
)
|
|
700
|
+
) {
|
|
701
|
+
return "Reviewing dependencies and security signals";
|
|
702
|
+
}
|
|
703
|
+
return "Tracing architecture and code relationships";
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export function workspaceAssessmentExecution(assignment) {
|
|
707
|
+
const requiredOutputHeading =
|
|
708
|
+
assignment?.assessment_mode === "incremental"
|
|
709
|
+
? "# Workspace Assessment Delta"
|
|
710
|
+
: "# Workspace Assessment";
|
|
711
|
+
return {
|
|
712
|
+
...connectorExecution(assignment, { requiredOutputHeading }),
|
|
713
|
+
requiredOutputHeading,
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
export function connectorExecution(assignment, options = {}) {
|
|
718
|
+
const rawPrompt = assignment?.prompt_markdown;
|
|
719
|
+
if (typeof rawPrompt !== "string" || !rawPrompt.trim()) {
|
|
720
|
+
throw new Error("EngineerOS assignment is missing prompt_markdown.");
|
|
721
|
+
}
|
|
722
|
+
const sandboxMode = assignment?.sandbox_mode;
|
|
723
|
+
if (!new Set(["read-only", "workspace-write"]).has(sandboxMode)) {
|
|
724
|
+
throw new Error("EngineerOS assignment has an unsupported sandbox_mode.");
|
|
725
|
+
}
|
|
726
|
+
const rawProfile = assignment?.execution_profile ?? {};
|
|
727
|
+
const model =
|
|
728
|
+
typeof rawProfile.model === "string" ? rawProfile.model.trim() : "";
|
|
729
|
+
const reasoningEffort = rawProfile.reasoning_effort;
|
|
730
|
+
if (
|
|
731
|
+
reasoningEffort &&
|
|
732
|
+
!new Set(["low", "medium", "high", "xhigh"]).has(reasoningEffort)
|
|
733
|
+
) {
|
|
734
|
+
throw new Error(
|
|
735
|
+
"EngineerOS assignment has an unsupported reasoning effort.",
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
const agentRole = assignment?.agent_role;
|
|
739
|
+
const prompt = buildAgentHarnessPrompt({
|
|
740
|
+
agentRole,
|
|
741
|
+
agentDefinition: assignment?.agent_definition,
|
|
742
|
+
prompt: rawPrompt,
|
|
743
|
+
sandboxMode,
|
|
744
|
+
requiredOutputHeading: options.requiredOutputHeading,
|
|
745
|
+
});
|
|
746
|
+
return {
|
|
747
|
+
prompt,
|
|
748
|
+
agentRole,
|
|
749
|
+
sandboxMode,
|
|
750
|
+
sessionKey:
|
|
751
|
+
typeof assignment.session_key === "string" &&
|
|
752
|
+
assignment.session_key.trim()
|
|
753
|
+
? assignment.session_key.trim()
|
|
754
|
+
: `project-${String(agentRole)}-${String(
|
|
755
|
+
assignment.purpose || "general",
|
|
756
|
+
)
|
|
757
|
+
.toLowerCase()
|
|
758
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
759
|
+
.slice(0, 80)}`,
|
|
760
|
+
profile: {
|
|
761
|
+
...(model ? { model } : {}),
|
|
762
|
+
...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
|
|
763
|
+
},
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export async function stopProcess(child) {
|
|
768
|
+
if (!child || child.exitCode !== null) return;
|
|
769
|
+
await child.engineerOsCancel?.();
|
|
770
|
+
if (process.platform === "win32") {
|
|
771
|
+
await run(
|
|
772
|
+
"taskkill",
|
|
773
|
+
["/pid", String(child.pid), "/t", "/f"],
|
|
774
|
+
process.cwd(),
|
|
775
|
+
{ allowFailure: true },
|
|
776
|
+
);
|
|
777
|
+
} else {
|
|
778
|
+
child.kill("SIGTERM");
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
export async function workspaceSnapshot(workspace) {
|
|
783
|
+
const root = path.resolve(workspace);
|
|
784
|
+
const gitFiles = await run(
|
|
785
|
+
"git",
|
|
786
|
+
["ls-files", "-co", "--exclude-standard"],
|
|
787
|
+
root,
|
|
788
|
+
{ allowFailure: true },
|
|
789
|
+
);
|
|
790
|
+
const candidates =
|
|
791
|
+
gitFiles.code === 0
|
|
792
|
+
? gitFiles.stdout.split(/\r?\n/).map(normalizePath).filter(Boolean)
|
|
793
|
+
: await workspaceFiles(root);
|
|
794
|
+
const files = [];
|
|
795
|
+
let excludedFileCount = 0;
|
|
796
|
+
let totalBytes = 0;
|
|
797
|
+
for (const relative of [...new Set(candidates)].sort()) {
|
|
798
|
+
if (!isShareablePath(relative)) {
|
|
799
|
+
excludedFileCount += 1;
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
const absolute = path.join(root, relative);
|
|
803
|
+
const details = await lstat(absolute).catch(() => null);
|
|
804
|
+
if (!details?.isFile() || details.isSymbolicLink()) {
|
|
805
|
+
excludedFileCount += 1;
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if (details.size > MAX_SHAREABLE_FILE_BYTES) {
|
|
809
|
+
excludedFileCount += 1;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
totalBytes += details.size;
|
|
813
|
+
if (totalBytes > MAX_ARCHIVE_BYTES) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
"Shareable workspace files exceed 25 MB. Exclude large generated or data files before onboarding.",
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
files.push({ name: relative, data: await readFile(absolute) });
|
|
819
|
+
if (files.length > MAX_WORKSPACE_FILES) {
|
|
820
|
+
throw new Error(
|
|
821
|
+
`Workspace exceeds the ${MAX_WORKSPACE_FILES.toLocaleString()}-file onboarding limit. Exclude generated files first.`,
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const archive = await createZip(files);
|
|
826
|
+
const head = await run("git", ["rev-parse", "HEAD"], root, {
|
|
827
|
+
allowFailure: true,
|
|
828
|
+
});
|
|
829
|
+
return {
|
|
830
|
+
archive_base64: archive.toString("base64"),
|
|
831
|
+
media_type: "application/zip",
|
|
832
|
+
workspace_name: path.basename(root),
|
|
833
|
+
workspace_kind: files.some(({ name }) => isCodeBearing(name))
|
|
834
|
+
? "brownfield"
|
|
835
|
+
: "greenfield",
|
|
836
|
+
file_count: files.length,
|
|
837
|
+
excluded_file_count: excludedFileCount,
|
|
838
|
+
head_revision: head.code === 0 ? head.stdout.trim().slice(0, 128) : null,
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
async function prepareRunWorkspace(workspace, runId, baseRevision) {
|
|
843
|
+
const source = path.resolve(workspace);
|
|
844
|
+
const root = path.join(os.homedir(), ".engineeros", "runs");
|
|
845
|
+
const target = path.join(root, runId);
|
|
846
|
+
await mkdir(root, { recursive: true });
|
|
847
|
+
const isGit =
|
|
848
|
+
(
|
|
849
|
+
await run("git", ["rev-parse", "--is-inside-work-tree"], source, {
|
|
850
|
+
allowFailure: true,
|
|
851
|
+
})
|
|
852
|
+
).code === 0;
|
|
853
|
+
if (isGit) {
|
|
854
|
+
const exists = await stat(target).then(
|
|
855
|
+
() => true,
|
|
856
|
+
() => false,
|
|
857
|
+
);
|
|
858
|
+
if (!exists) {
|
|
859
|
+
const base = await worktreeBase(source, baseRevision);
|
|
860
|
+
await run("git", ["worktree", "add", "--detach", target, base], source);
|
|
861
|
+
}
|
|
862
|
+
return target;
|
|
863
|
+
}
|
|
864
|
+
const exists = await stat(target).then(
|
|
865
|
+
() => true,
|
|
866
|
+
() => false,
|
|
867
|
+
);
|
|
868
|
+
if (!exists) {
|
|
869
|
+
await mkdir(target, { recursive: true });
|
|
870
|
+
await copyWorkspace(source, target);
|
|
871
|
+
await run("git", ["init"], target);
|
|
872
|
+
await run("git", ["config", "user.name", "EngineerOS Connector"], target);
|
|
873
|
+
await run(
|
|
874
|
+
"git",
|
|
875
|
+
["config", "user.email", "connector@engineeros.local"],
|
|
876
|
+
target,
|
|
877
|
+
);
|
|
878
|
+
await run("git", ["add", "-A"], target);
|
|
879
|
+
await run(
|
|
880
|
+
"git",
|
|
881
|
+
["commit", "--allow-empty", "-m", "EngineerOS run baseline"],
|
|
882
|
+
target,
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
return target;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function launchCodexProcess(
|
|
889
|
+
workspace,
|
|
890
|
+
prompt,
|
|
891
|
+
sandbox,
|
|
892
|
+
callbacks,
|
|
893
|
+
profile = {},
|
|
894
|
+
previousSessionId,
|
|
895
|
+
skipGitRepoCheck = false,
|
|
896
|
+
mcpServer,
|
|
897
|
+
) {
|
|
898
|
+
if (!mcpServer) {
|
|
899
|
+
return launchCodexAppServer({
|
|
900
|
+
workspace,
|
|
901
|
+
prompt,
|
|
902
|
+
sandbox,
|
|
903
|
+
profile,
|
|
904
|
+
previousSessionId,
|
|
905
|
+
callbacks,
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
const command =
|
|
909
|
+
process.env.CODEX_BIN ||
|
|
910
|
+
(process.platform === "win32" ? "codex.cmd" : "codex");
|
|
911
|
+
const args = codexExecutionArgs({
|
|
912
|
+
workspace,
|
|
913
|
+
sandbox,
|
|
914
|
+
profile,
|
|
915
|
+
previousSessionId,
|
|
916
|
+
skipGitRepoCheck,
|
|
917
|
+
mcpServer,
|
|
918
|
+
});
|
|
919
|
+
const child = spawn(command, args, {
|
|
920
|
+
cwd: workspace,
|
|
921
|
+
env: process.env,
|
|
922
|
+
shell: process.platform === "win32",
|
|
923
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
924
|
+
});
|
|
925
|
+
child.stdin.end(prompt);
|
|
926
|
+
let output = "";
|
|
927
|
+
let buffer = "";
|
|
928
|
+
let finalMessage = "";
|
|
929
|
+
let sessionId = previousSessionId || "";
|
|
930
|
+
child.stdout.setEncoding("utf8");
|
|
931
|
+
child.stdout.on("data", (chunk) => {
|
|
932
|
+
output += chunk;
|
|
933
|
+
buffer += chunk;
|
|
934
|
+
const lines = buffer.split(/\r?\n/);
|
|
935
|
+
buffer = lines.pop() ?? "";
|
|
936
|
+
for (const line of lines) {
|
|
937
|
+
if (!line.trim()) continue;
|
|
938
|
+
try {
|
|
939
|
+
const event = JSON.parse(line);
|
|
940
|
+
if (
|
|
941
|
+
event.type === "thread.started" &&
|
|
942
|
+
typeof event.thread_id === "string"
|
|
943
|
+
) {
|
|
944
|
+
sessionId = event.thread_id;
|
|
945
|
+
}
|
|
946
|
+
if (
|
|
947
|
+
event.type === "item.completed" &&
|
|
948
|
+
event.item?.type === "agent_message" &&
|
|
949
|
+
typeof event.item.text === "string"
|
|
950
|
+
) {
|
|
951
|
+
finalMessage = event.item.text;
|
|
952
|
+
}
|
|
953
|
+
callbacks.onEvent?.(event);
|
|
954
|
+
} catch {
|
|
955
|
+
callbacks.onEvent?.({
|
|
956
|
+
type: "agent.output",
|
|
957
|
+
message: line.slice(0, 500),
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
child.stderr.setEncoding("utf8");
|
|
963
|
+
child.stderr.on("data", (chunk) => {
|
|
964
|
+
output += chunk;
|
|
965
|
+
callbacks.onEvent?.({
|
|
966
|
+
type: "agent.stderr",
|
|
967
|
+
message: chunk.trim().slice(0, 500),
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
const completed = new Promise((resolve, reject) => {
|
|
971
|
+
child.once("error", reject);
|
|
972
|
+
child.once("close", (code) => {
|
|
973
|
+
if (code === 0 && sessionId)
|
|
974
|
+
resolve({ output: output.slice(-20_000), finalMessage, sessionId });
|
|
975
|
+
else if (code === 0)
|
|
976
|
+
reject(
|
|
977
|
+
new Error(
|
|
978
|
+
"Agent completed without announcing a resumable session id.",
|
|
979
|
+
),
|
|
980
|
+
);
|
|
981
|
+
else reject(new Error(codexFailureMessage(output, code)));
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
return { child, completed };
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
export function codexExecutionArgs({
|
|
988
|
+
workspace,
|
|
989
|
+
sandbox,
|
|
990
|
+
profile = {},
|
|
991
|
+
previousSessionId,
|
|
992
|
+
skipGitRepoCheck = false,
|
|
993
|
+
mcpServer,
|
|
994
|
+
}) {
|
|
995
|
+
const optionArgs = [
|
|
996
|
+
"--json",
|
|
997
|
+
"--config",
|
|
998
|
+
codexConfigArgument("skills.include_instructions=false"),
|
|
999
|
+
];
|
|
1000
|
+
if (skipGitRepoCheck) optionArgs.push("--skip-git-repo-check");
|
|
1001
|
+
if (profile.model) optionArgs.push("--model", profile.model);
|
|
1002
|
+
if (profile.reasoning_effort) {
|
|
1003
|
+
optionArgs.push(
|
|
1004
|
+
"--config",
|
|
1005
|
+
codexConfigArgument(
|
|
1006
|
+
`model_reasoning_effort=${tomlLiteralString(profile.reasoning_effort)}`,
|
|
1007
|
+
),
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
if (mcpServer) {
|
|
1011
|
+
const mcpArgs = [
|
|
1012
|
+
mcpServer.connectorBin,
|
|
1013
|
+
"mcp",
|
|
1014
|
+
"--workspace",
|
|
1015
|
+
mcpServer.workspace,
|
|
1016
|
+
"--run-id",
|
|
1017
|
+
mcpServer.runId,
|
|
1018
|
+
];
|
|
1019
|
+
optionArgs.push(
|
|
1020
|
+
"--config",
|
|
1021
|
+
codexConfigArgument(
|
|
1022
|
+
`mcp_servers.engineeros.command=${tomlLiteralString(process.execPath)}`,
|
|
1023
|
+
),
|
|
1024
|
+
"--config",
|
|
1025
|
+
codexConfigArgument(
|
|
1026
|
+
`mcp_servers.engineeros.args=[${mcpArgs.map(tomlLiteralString).join(",")}]`,
|
|
1027
|
+
),
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
return previousSessionId
|
|
1031
|
+
? ["exec", "resume", ...optionArgs, previousSessionId, "-"]
|
|
1032
|
+
: ["exec", ...optionArgs, "--sandbox", sandbox, "-C", workspace, "-"];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
export function sanitizeAgentResponse(value) {
|
|
1036
|
+
return String(value || "")
|
|
1037
|
+
.replace(
|
|
1038
|
+
/^Warning: Exceeded skills context budget(?: of \d+%)?\. All skill descriptions were removed and \d+ additional skills? (?:was|were) not included in the model-visible skills list\.\s*/i,
|
|
1039
|
+
"",
|
|
1040
|
+
)
|
|
1041
|
+
.trimStart();
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function tomlLiteralString(value) {
|
|
1045
|
+
const text = String(value);
|
|
1046
|
+
if (text.includes("'''")) {
|
|
1047
|
+
throw new Error(
|
|
1048
|
+
"Codex configuration values cannot contain three consecutive apostrophes.",
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
return `'''${text}'''`;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function codexConfigArgument(override) {
|
|
1055
|
+
return process.platform === "win32" ? `"${override}"` : override;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
function launchAgentProcess(
|
|
1059
|
+
workspace,
|
|
1060
|
+
prompt,
|
|
1061
|
+
sandbox,
|
|
1062
|
+
config,
|
|
1063
|
+
callbacks,
|
|
1064
|
+
profile = {},
|
|
1065
|
+
previousSessionId,
|
|
1066
|
+
mcpContext,
|
|
1067
|
+
) {
|
|
1068
|
+
if (config.agent_protocol === "acp") {
|
|
1069
|
+
return launchAcpAgent(workspace, prompt, config, callbacks, {
|
|
1070
|
+
persistent: mcpContext?.persistentAcp === true,
|
|
1071
|
+
sessionKey: mcpContext?.sessionKey,
|
|
1072
|
+
previousSessionId,
|
|
1073
|
+
sandbox,
|
|
1074
|
+
profile,
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
return launchCodexProcess(
|
|
1078
|
+
workspace,
|
|
1079
|
+
prompt,
|
|
1080
|
+
sandbox,
|
|
1081
|
+
callbacks,
|
|
1082
|
+
profile,
|
|
1083
|
+
previousSessionId,
|
|
1084
|
+
config.skip_git_repo_check === true,
|
|
1085
|
+
mcpContext?.runId
|
|
1086
|
+
? {
|
|
1087
|
+
connectorBin: process.argv[1],
|
|
1088
|
+
workspace: config.workspace,
|
|
1089
|
+
runId: mcpContext.runId,
|
|
1090
|
+
}
|
|
1091
|
+
: undefined,
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function runCodexCommand(command, args, cwd) {
|
|
1096
|
+
return new Promise((resolve, reject) => {
|
|
1097
|
+
const child = spawn(command, args, {
|
|
1098
|
+
cwd,
|
|
1099
|
+
env: process.env,
|
|
1100
|
+
shell: process.platform === "win32",
|
|
1101
|
+
windowsHide: true,
|
|
1102
|
+
});
|
|
1103
|
+
let stdout = "";
|
|
1104
|
+
let stderr = "";
|
|
1105
|
+
child.stdout.setEncoding("utf8");
|
|
1106
|
+
child.stderr.setEncoding("utf8");
|
|
1107
|
+
child.stdout.on("data", (chunk) => (stdout += chunk));
|
|
1108
|
+
child.stderr.on("data", (chunk) => (stderr += chunk));
|
|
1109
|
+
child.once("error", reject);
|
|
1110
|
+
child.once("close", (code) => resolve({ code: code ?? 1, stdout, stderr }));
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
async function changedFilePaths(workspace) {
|
|
1115
|
+
const tracked = await run(
|
|
1116
|
+
"git",
|
|
1117
|
+
["diff", "--name-only", "-z", "HEAD", "--"],
|
|
1118
|
+
workspace,
|
|
1119
|
+
);
|
|
1120
|
+
const untracked = await run(
|
|
1121
|
+
"git",
|
|
1122
|
+
["ls-files", "-z", "--others", "--exclude-standard"],
|
|
1123
|
+
workspace,
|
|
1124
|
+
);
|
|
1125
|
+
return [
|
|
1126
|
+
...new Set([
|
|
1127
|
+
...gitPathList(tracked.stdout),
|
|
1128
|
+
...gitPathList(untracked.stdout),
|
|
1129
|
+
]),
|
|
1130
|
+
].sort();
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
async function boundedDiff(workspace, changedFiles) {
|
|
1134
|
+
const tracked = await run(
|
|
1135
|
+
"git",
|
|
1136
|
+
["diff", "--binary", "HEAD", "--"],
|
|
1137
|
+
workspace,
|
|
1138
|
+
);
|
|
1139
|
+
const untracked = new Set(
|
|
1140
|
+
gitPathList(
|
|
1141
|
+
(
|
|
1142
|
+
await run(
|
|
1143
|
+
"git",
|
|
1144
|
+
["ls-files", "-z", "--others", "--exclude-standard"],
|
|
1145
|
+
workspace,
|
|
1146
|
+
)
|
|
1147
|
+
).stdout,
|
|
1148
|
+
),
|
|
1149
|
+
);
|
|
1150
|
+
const parts = [tracked.stdout];
|
|
1151
|
+
for (const relative of changedFiles.filter((item) => untracked.has(item))) {
|
|
1152
|
+
const generated = await run(
|
|
1153
|
+
"git",
|
|
1154
|
+
["diff", "--no-index", "--binary", "--", "/dev/null", relative],
|
|
1155
|
+
workspace,
|
|
1156
|
+
{
|
|
1157
|
+
allowFailure: true,
|
|
1158
|
+
},
|
|
1159
|
+
);
|
|
1160
|
+
parts.push(generated.stdout);
|
|
1161
|
+
}
|
|
1162
|
+
const diff = parts.filter(Boolean).join("\n");
|
|
1163
|
+
if (!diff.trim()) throw new Error("The run produced no bounded diff.");
|
|
1164
|
+
return diff;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
export async function repositoryArchive(workspace) {
|
|
1168
|
+
const listed = await run(
|
|
1169
|
+
"git",
|
|
1170
|
+
["ls-files", "-z", "-co", "--exclude-standard"],
|
|
1171
|
+
workspace,
|
|
1172
|
+
);
|
|
1173
|
+
const files = [...new Set(gitPathList(listed.stdout))].sort();
|
|
1174
|
+
return createZip(
|
|
1175
|
+
await Promise.all(
|
|
1176
|
+
files.map(async (relative) => ({
|
|
1177
|
+
name: relative,
|
|
1178
|
+
data: await readFile(path.join(workspace, relative)),
|
|
1179
|
+
})),
|
|
1180
|
+
),
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
async function workspaceFiles(root, current = root) {
|
|
1185
|
+
const files = [];
|
|
1186
|
+
for (const entry of await readdir(current, { withFileTypes: true })) {
|
|
1187
|
+
const absolute = path.join(current, entry.name);
|
|
1188
|
+
const relative = normalizePath(path.relative(root, absolute));
|
|
1189
|
+
if (entry.isSymbolicLink()) continue;
|
|
1190
|
+
if (entry.isDirectory()) {
|
|
1191
|
+
if (!EXCLUDED_DIRECTORIES.has(entry.name.toLowerCase())) {
|
|
1192
|
+
files.push(...(await workspaceFiles(root, absolute)));
|
|
1193
|
+
}
|
|
1194
|
+
} else if (entry.isFile()) {
|
|
1195
|
+
files.push(relative);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
return files;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function isShareablePath(relative) {
|
|
1202
|
+
const normalized = normalizePath(relative);
|
|
1203
|
+
if (
|
|
1204
|
+
!normalized ||
|
|
1205
|
+
normalized === ".." ||
|
|
1206
|
+
normalized.startsWith("../") ||
|
|
1207
|
+
path.isAbsolute(normalized)
|
|
1208
|
+
) {
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1211
|
+
const parts = normalized.split("/");
|
|
1212
|
+
if (parts.some((part) => EXCLUDED_DIRECTORIES.has(part.toLowerCase()))) {
|
|
1213
|
+
return false;
|
|
1214
|
+
}
|
|
1215
|
+
if (
|
|
1216
|
+
EXCLUDED_PATH_PREFIXES.some((prefix) =>
|
|
1217
|
+
normalized.toLowerCase().startsWith(prefix),
|
|
1218
|
+
)
|
|
1219
|
+
) {
|
|
1220
|
+
return false;
|
|
1221
|
+
}
|
|
1222
|
+
const name = parts.at(-1)?.toLowerCase() ?? "";
|
|
1223
|
+
if (EXCLUDED_FILE_EXTENSIONS.has(path.posix.extname(name))) return false;
|
|
1224
|
+
if (name === ".env.example" || name === ".env.sample") return true;
|
|
1225
|
+
if (
|
|
1226
|
+
name === ".env" ||
|
|
1227
|
+
name.startsWith(".env.") ||
|
|
1228
|
+
[".npmrc", ".netrc", "credentials", "credentials.json"].includes(name) ||
|
|
1229
|
+
/\.(?:key|pem|p12|pfx)$/i.test(name)
|
|
1230
|
+
) {
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
return true;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function isCodeBearing(relative) {
|
|
1237
|
+
const name = path.posix.basename(relative).toLowerCase();
|
|
1238
|
+
return (
|
|
1239
|
+
CODE_MARKERS.has(name) || CODE_EXTENSIONS.has(path.posix.extname(name))
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
async function worktreeBase(workspace, requested) {
|
|
1244
|
+
if (!requested || requested.startsWith("greenfield:")) return "HEAD";
|
|
1245
|
+
const exists = await run(
|
|
1246
|
+
"git",
|
|
1247
|
+
["cat-file", "-e", `${requested}^{commit}`],
|
|
1248
|
+
workspace,
|
|
1249
|
+
{ allowFailure: true },
|
|
1250
|
+
);
|
|
1251
|
+
if (exists.code !== 0) {
|
|
1252
|
+
throw new Error(
|
|
1253
|
+
`The frozen base revision ${requested} is not available in this repository.`,
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
return requested;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
export async function createZip(files) {
|
|
1260
|
+
const localParts = [];
|
|
1261
|
+
const centralParts = [];
|
|
1262
|
+
let offset = 0;
|
|
1263
|
+
let total = 0;
|
|
1264
|
+
for (const file of files) {
|
|
1265
|
+
const name = Buffer.from(normalizePath(file.name), "utf8");
|
|
1266
|
+
const data = Buffer.from(file.data);
|
|
1267
|
+
total += data.length;
|
|
1268
|
+
if (total > MAX_ARCHIVE_BYTES)
|
|
1269
|
+
throw new Error("Repository archive exceeds the 25 MB connector limit.");
|
|
1270
|
+
const compressed = await deflate(data);
|
|
1271
|
+
const crc = crc32(data);
|
|
1272
|
+
const local = Buffer.alloc(30);
|
|
1273
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
1274
|
+
local.writeUInt16LE(20, 4);
|
|
1275
|
+
local.writeUInt16LE(0x0800, 6);
|
|
1276
|
+
local.writeUInt16LE(8, 8);
|
|
1277
|
+
local.writeUInt32LE(crc, 14);
|
|
1278
|
+
local.writeUInt32LE(compressed.length, 18);
|
|
1279
|
+
local.writeUInt32LE(data.length, 22);
|
|
1280
|
+
local.writeUInt16LE(name.length, 26);
|
|
1281
|
+
localParts.push(local, name, compressed);
|
|
1282
|
+
|
|
1283
|
+
const central = Buffer.alloc(46);
|
|
1284
|
+
central.writeUInt32LE(0x02014b50, 0);
|
|
1285
|
+
central.writeUInt16LE(20, 4);
|
|
1286
|
+
central.writeUInt16LE(20, 6);
|
|
1287
|
+
central.writeUInt16LE(0x0800, 8);
|
|
1288
|
+
central.writeUInt16LE(8, 10);
|
|
1289
|
+
central.writeUInt32LE(crc, 16);
|
|
1290
|
+
central.writeUInt32LE(compressed.length, 20);
|
|
1291
|
+
central.writeUInt32LE(data.length, 24);
|
|
1292
|
+
central.writeUInt16LE(name.length, 28);
|
|
1293
|
+
central.writeUInt32LE(offset, 42);
|
|
1294
|
+
centralParts.push(central, name);
|
|
1295
|
+
offset += local.length + name.length + compressed.length;
|
|
1296
|
+
}
|
|
1297
|
+
const central = Buffer.concat(centralParts);
|
|
1298
|
+
const end = Buffer.alloc(22);
|
|
1299
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
1300
|
+
end.writeUInt16LE(files.length, 8);
|
|
1301
|
+
end.writeUInt16LE(files.length, 10);
|
|
1302
|
+
end.writeUInt32LE(central.length, 12);
|
|
1303
|
+
end.writeUInt32LE(offset, 16);
|
|
1304
|
+
return Buffer.concat([...localParts, central, end]);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
async function copyWorkspace(source, target) {
|
|
1308
|
+
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
1309
|
+
if ([".git", ".engineeros", "node_modules"].includes(entry.name)) continue;
|
|
1310
|
+
const from = path.join(source, entry.name);
|
|
1311
|
+
const to = path.join(target, entry.name);
|
|
1312
|
+
if (entry.isDirectory()) {
|
|
1313
|
+
await mkdir(to, { recursive: true });
|
|
1314
|
+
await copyWorkspace(from, to);
|
|
1315
|
+
} else if (entry.isFile()) {
|
|
1316
|
+
await writeFile(to, await readFile(from));
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function normalizePath(value) {
|
|
1322
|
+
return String(value ?? "")
|
|
1323
|
+
.trim()
|
|
1324
|
+
.replaceAll("\\", "/")
|
|
1325
|
+
.replace(/^\.\//, "");
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function gitPathList(value) {
|
|
1329
|
+
return String(value ?? "")
|
|
1330
|
+
.split("\0")
|
|
1331
|
+
.map(normalizePath)
|
|
1332
|
+
.filter(Boolean);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
function run(command, args, cwd, options = {}) {
|
|
1336
|
+
return new Promise((resolve, reject) => {
|
|
1337
|
+
const child = spawn(command, args, {
|
|
1338
|
+
cwd,
|
|
1339
|
+
shell: false,
|
|
1340
|
+
windowsHide: true,
|
|
1341
|
+
});
|
|
1342
|
+
let stdout = "";
|
|
1343
|
+
let stderr = "";
|
|
1344
|
+
child.stdout.setEncoding("utf8");
|
|
1345
|
+
child.stderr.setEncoding("utf8");
|
|
1346
|
+
child.stdout.on("data", (chunk) => (stdout += chunk));
|
|
1347
|
+
child.stderr.on("data", (chunk) => (stderr += chunk));
|
|
1348
|
+
child.once("error", reject);
|
|
1349
|
+
child.once("close", (code) => {
|
|
1350
|
+
const result = { code: code ?? 1, stdout, stderr };
|
|
1351
|
+
if (code === 0 || options.allowFailure) resolve(result);
|
|
1352
|
+
else
|
|
1353
|
+
reject(
|
|
1354
|
+
new Error(`${command} ${args.join(" ")} failed: ${stderr || stdout}`),
|
|
1355
|
+
);
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
function crc32(buffer) {
|
|
1361
|
+
let crc = 0xffffffff;
|
|
1362
|
+
for (const byte of buffer) {
|
|
1363
|
+
crc ^= byte;
|
|
1364
|
+
for (let bit = 0; bit < 8; bit += 1)
|
|
1365
|
+
crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
|
|
1366
|
+
}
|
|
1367
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
1368
|
+
}
|