burnoff 1.4.0 → 1.4.1
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/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/burnoff-pr-gate.yml +3 -3
- package/.github/workflows/burnoff-startup-lint.yml +2 -2
- package/README.md +213 -209
- package/bin/burnoff.mjs +1 -1
- package/commands/burnoff.md +1 -1
- package/docs/CLAUDE_CODE_PLUGIN.md +6 -6
- package/docs/DESIGN_PARTNER_INTAKE.md +3 -3
- package/hooks/hook-io.mjs +691 -599
- package/package.json +1 -1
- package/scripts/bench-hooks.mjs +252 -0
- package/src/cli/doctor.mjs +583 -462
- package/src/cli/hook-health.mjs +429 -0
- package/src/cli/init.mjs +668 -646
- package/src/clients/antigravity.mjs +285 -285
- package/src/config/policy.mjs +307 -306
- package/src/guards/credential-scrubber.mjs +185 -0
- package/src/guards/loop-breaker.mjs +797 -793
- package/src/guards/post-tool-engine.mjs +875 -854
- package/src/guards/pre-tool-engine.mjs +973 -978
- package/src/guards/read-clamp.mjs +826 -804
- package/src/guards/shell-guard.mjs +1705 -1676
- package/src/guards/structural-boundaries.mjs +175 -0
- package/src/ipc/fast-client.mjs +255 -255
- package/src/storage/fts5-archive.mjs +734 -733
|
@@ -1,733 +1,734 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file src/storage/fts5-archive.mjs
|
|
3
|
-
* Fail-Open CLI Output Compressor & Local SQLite FTS5 Index (`tool_logs_fts5.db`).
|
|
4
|
-
*
|
|
5
|
-
* Strictly FAIL-OPEN: if any exception occurs during SQLite indexing or parsing,
|
|
6
|
-
* returns the raw output untouched so builds and test workflows never break.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
import { getHomeDir, getBurnoffCacheDir } from '../config/paths.mjs';
|
|
12
|
-
import { openBurnoffDb, resolveFallbackDbPath } from './sqlite-client.mjs';
|
|
13
|
-
import { recordInterventionSavings } from './ledger.mjs';
|
|
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
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (/\
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/\
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return '
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
arr.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
for (const
|
|
135
|
-
for (const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
bounded.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
`
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for (const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
bounded.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
groups.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
`
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
bounded.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
`
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
for (const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
bounded.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
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
|
-
out
|
|
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
|
-
bounded.
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
const
|
|
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
|
-
String(
|
|
438
|
-
String(
|
|
439
|
-
String(
|
|
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
|
-
const
|
|
473
|
-
const
|
|
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
|
-
const
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
const
|
|
584
|
-
const
|
|
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
|
-
const
|
|
614
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
701
|
-
const
|
|
702
|
-
const
|
|
703
|
-
const
|
|
704
|
-
const
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file src/storage/fts5-archive.mjs
|
|
3
|
+
* Fail-Open CLI Output Compressor & Local SQLite FTS5 Index (`tool_logs_fts5.db`).
|
|
4
|
+
*
|
|
5
|
+
* Strictly FAIL-OPEN: if any exception occurs during SQLite indexing or parsing,
|
|
6
|
+
* returns the raw output untouched so builds and test workflows never break.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { getHomeDir, getBurnoffCacheDir } from '../config/paths.mjs';
|
|
12
|
+
import { openBurnoffDb, resolveFallbackDbPath } from './sqlite-client.mjs';
|
|
13
|
+
import { recordInterventionSavings } from './ledger.mjs';
|
|
14
|
+
import { redactSecretsPure } from '../guards/credential-scrubber.mjs';
|
|
15
|
+
|
|
16
|
+
export const FTS5_COMPRESSOR_CONSTANTS = Object.freeze({
|
|
17
|
+
MIN_LINES_TO_COMPRESS: 40,
|
|
18
|
+
MIN_BYTES_TO_COMPRESS: 4096,
|
|
19
|
+
MAX_SUMMARY_LINES: 25,
|
|
20
|
+
TARGET_COMMAND_REGEX:
|
|
21
|
+
/(?:(?:^|[\s;|&])@['"]|\b(?:pytest|jest|vitest|cargo\s+(?:test|clippy|check|build)|tsc|go\s+test|eslint|biome|ruff|next\s+build|vite\s+build|(?:mvn|mvnw(?:\.cmd)?|gradle|gradlew(?:\.bat)?|kotlinc)\b|dotnet\s+(?:test|build)\b|make\b|ctest\b|bazel\s+(?:test|build)\b|(?:(?:npx|pnpm(?:\s+exec)?)\s+)?playwright\s+test\b|(?:bundle\s+exec\s+)?rspec\b|phpunit\b|deno\s+test\b|docker\s+(?:build|logs)|kubectl\s+(?:logs|get|describe)|gh\s+(?:pr|run|api|issue|release|workflow)|git\s+(?:diff|log|show|status|grep|ls-files|blame|branch|tag|stash|reflog|cherry-pick)|(?:npm|pnpm|yarn|bun)\s+(?:test|run\s+(?:test|lint|build|typecheck)|install|ci|add|update|audit|outdated|pack|publish)|(?:pip3?|uv|poetry)\s+(?:install|sync|audit|list|show)|node(?:\.exe)?|python3?(?:\.exe)?|select-string|get-childitem|gci|get-content|write-output|powershell|pwsh|rg|ripgrep|grep|find|fd|tree|curl|wget|aws|gcloud|terraform)\b)/i
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export function getDefaultToolLogsDbPath(homeDir = null) {
|
|
25
|
+
return path.join(getBurnoffCacheDir(homeDir), 'tool_logs_fts5.db');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isCompressibleCliCommand(command = '') {
|
|
29
|
+
return FTS5_COMPRESSOR_CONSTANTS.TARGET_COMMAND_REGEX.test(String(command || ''));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const POWERSHELL_HEREDOC_OR_SEARCH_RE =
|
|
33
|
+
/(?:(?:^|[\s;|&])@['"]|\b(?:select-string|get-childitem|gci)\b)/i;
|
|
34
|
+
const BOUNDED_PIPE_FILTER_RE =
|
|
35
|
+
/\|\s*(?:head|tail|sed|awk|cut|wc|grep|egrep|fgrep|rg|ripgrep|jq)\b/i;
|
|
36
|
+
const INLINE_SCRIPT_OR_HEREDOC_RE =
|
|
37
|
+
/\b(?:node(?:\.exe)?\s+(?:-[ep]\b|--eval\b|--print\b)|python3?(?:\.exe)?\s+(?:-c\b|-\s*<<|<<))|\bcat\s*>\s*\S+[\s\S]*<</i;
|
|
38
|
+
const FILE_INSPECTION_SEGMENT_RE =
|
|
39
|
+
/^\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S+\s+)*(?:(?:\/[\w./-]+)?\/)?(?:cat|head|tail|sed|awk|cut|wc|nl|tac|rev|less|more|bat|jq|stat|file(?=\s+\S)|ls|dir|tree|grep|egrep|fgrep|rg|ripgrep|get-content)(?=\s|$)(?![.\w-])/i;
|
|
40
|
+
const GIT_INSPECTION_CMD_RE = /\bgit\s+(?:diff|show|status|blame|log)\b/i;
|
|
41
|
+
const NOISY_PRIMARY_RUNNER_RE =
|
|
42
|
+
/\b(?:(?:npm|pnpm|yarn|bun)\s+(?:test|install|ci|run|build|lint|typecheck)|node\s+--test|pytest|jest|vitest|cargo|go\s+test|tsc|eslint|biome|ruff|next\s+build|vite\s+build|mvn|mvnw|gradle|gradlew|kotlinc|dotnet\s+(?:test|build)|make|ctest|bazel\s+(?:test|build)|playwright\s+test|rspec|phpunit|deno\s+test|docker|kubectl)\b/i;
|
|
43
|
+
|
|
44
|
+
export function classifyShellPostToolPolicy(command = '') {
|
|
45
|
+
const cmd = String(command || '').trim();
|
|
46
|
+
if (!cmd) {
|
|
47
|
+
return { allowFts5: false, allowOffload: true, reason: 'empty_command' };
|
|
48
|
+
}
|
|
49
|
+
if (BOUNDED_PIPE_FILTER_RE.test(cmd)) {
|
|
50
|
+
return { allowFts5: false, allowOffload: false, reason: 'explicitly_bounded_shell_output' };
|
|
51
|
+
}
|
|
52
|
+
const segments = cmd.split(/(?:&&|\|\||;|\||\r?\n)/);
|
|
53
|
+
const hasInspectionSegment = segments.some((seg) => FILE_INSPECTION_SEGMENT_RE.test(seg));
|
|
54
|
+
if (POWERSHELL_HEREDOC_OR_SEARCH_RE.test(cmd) && !hasInspectionSegment) {
|
|
55
|
+
return { allowFts5: true, allowOffload: true, reason: 'eligible_powershell_cli' };
|
|
56
|
+
}
|
|
57
|
+
if (INLINE_SCRIPT_OR_HEREDOC_RE.test(cmd)) {
|
|
58
|
+
return { allowFts5: false, allowOffload: false, reason: 'inline_script_or_heredoc' };
|
|
59
|
+
}
|
|
60
|
+
if (hasInspectionSegment) {
|
|
61
|
+
return { allowFts5: false, allowOffload: false, reason: 'file_inspection_shell_command' };
|
|
62
|
+
}
|
|
63
|
+
if (GIT_INSPECTION_CMD_RE.test(cmd) && !NOISY_PRIMARY_RUNNER_RE.test(cmd)) {
|
|
64
|
+
return { allowFts5: false, allowOffload: false, reason: 'git_inspection_command' };
|
|
65
|
+
}
|
|
66
|
+
return { allowFts5: true, allowOffload: true, reason: 'eligible_cli_output' };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function classifyCliCommandFamily(command = '') {
|
|
70
|
+
const cmd = String(command || '').toLowerCase();
|
|
71
|
+
if (/\bgit\s+(diff|log|show|status)\b/.test(cmd)) return 'git';
|
|
72
|
+
if (/\b(docker|kubectl)\b/.test(cmd) || /\bgh\s+(pr|run)\b/.test(cmd)) return 'infra';
|
|
73
|
+
if (
|
|
74
|
+
/\b(pytest|jest|vitest|cargo\s+test|node\s+--test|(?:npm|pnpm|yarn|bun)\s+(?:test|run\s+(?:test|lint|build|typecheck))|go\s+test|(?:mvn|mvnw(?:\.cmd)?)\s+[^\n]*(?:test|verify)|(?:gradle|gradlew(?:\.bat)?)\s+[^\n]*(?:test|check)|dotnet\s+test|bazel\s+test|playwright\s+test|rspec|phpunit|deno\s+test|ctest|make\s+(?:test|check))\b/.test(
|
|
75
|
+
cmd
|
|
76
|
+
)
|
|
77
|
+
) {
|
|
78
|
+
return 'test';
|
|
79
|
+
}
|
|
80
|
+
if (
|
|
81
|
+
/\b(eslint|biome|ruff|tsc|cargo\s+(clippy|check|build)|next\s+build|vite\s+build|mvn|mvnw(?:\.cmd)?|gradle|gradlew(?:\.bat)?|kotlinc|dotnet\s+build|bazel\s+build|make)\b/.test(
|
|
82
|
+
cmd
|
|
83
|
+
)
|
|
84
|
+
) {
|
|
85
|
+
return 'lint_build';
|
|
86
|
+
}
|
|
87
|
+
if (
|
|
88
|
+
/\b(select-string|get-childitem|gci|rg|ripgrep|grep|find|fd|tree)\b/.test(cmd) ||
|
|
89
|
+
/\bgit\s+(grep|ls-files)\b/.test(cmd)
|
|
90
|
+
) {
|
|
91
|
+
return 'search_list';
|
|
92
|
+
}
|
|
93
|
+
if (/\bgh\b/.test(cmd) && !/\bgh\s+(api|issue|release|workflow)\b/.test(cmd)) return 'infra';
|
|
94
|
+
return 'generic_cli';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function pushUniqueBounded(arr, item, maxLen, sliceLen = 140) {
|
|
98
|
+
const cleaned = String(item || '').trim().slice(0, sliceLen);
|
|
99
|
+
if (!cleaned || arr.includes(cleaned) || arr.length >= maxLen) return;
|
|
100
|
+
arr.push(cleaned);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function buildDeterministicSummary(rawOutput = '', {
|
|
104
|
+
command = 'pytest',
|
|
105
|
+
exitCode = 1,
|
|
106
|
+
turnId = 'turn-1',
|
|
107
|
+
maxLines = FTS5_COMPRESSOR_CONSTANTS.MAX_SUMMARY_LINES
|
|
108
|
+
} = {}) {
|
|
109
|
+
const lines = String(rawOutput || '').split(/\r?\n/);
|
|
110
|
+
const family = classifyCliCommandFamily(command);
|
|
111
|
+
const queryHandleLine = `FTS5 Query Handle: npx burnoff search ${turnId} "<keyword>" (full output archived; do not re-run)`;
|
|
112
|
+
|
|
113
|
+
if (family === 'git') {
|
|
114
|
+
const fileHeaders = [];
|
|
115
|
+
const hunksOrMeta = [];
|
|
116
|
+
const conflictsOrErrors = [];
|
|
117
|
+
for (const rawLine of lines) {
|
|
118
|
+
const line = rawLine.trim();
|
|
119
|
+
if (!line) continue;
|
|
120
|
+
if (/^(diff --git |\+\+\+ [ab]\/|--- [ab]\/|commit [0-9a-f]{7,})/.test(line)) {
|
|
121
|
+
pushUniqueBounded(fileHeaders, line, 10);
|
|
122
|
+
} else if (/^\s*(M|A|D|R\d*|C\d*|UU|\?\?)\s+\S+/.test(rawLine)) {
|
|
123
|
+
pushUniqueBounded(fileHeaders, line, 10);
|
|
124
|
+
} else if (/^@@\s+.*\s+@@/.test(line) || /^(\d+\s+files?\s+changed|[\w./-]+\s+\|\s+\d+)/.test(line)) {
|
|
125
|
+
pushUniqueBounded(hunksOrMeta, line, 8);
|
|
126
|
+
} else if (/^(<{7}|={7}|>{7}|error:|fatal:)/i.test(line)) {
|
|
127
|
+
pushUniqueBounded(conflictsOrErrors, line, 4);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const out = [
|
|
131
|
+
`[FTS5 Compressed CLI Output] cmd="${command}" exit_code=${exitCode} raw_lines=${lines.length}`,
|
|
132
|
+
`Git Files & Hunks (${fileHeaders.length} files, ${hunksOrMeta.length} hunks):`
|
|
133
|
+
];
|
|
134
|
+
for (const f of fileHeaders) out.push(` ${f}`);
|
|
135
|
+
for (const h of hunksOrMeta) out.push(` ${h}`);
|
|
136
|
+
for (const c of conflictsOrErrors) out.push(` ${c}`);
|
|
137
|
+
if (out.length <= 2) {
|
|
138
|
+
for (const tailLine of lines.slice(-6)) {
|
|
139
|
+
if (tailLine.trim()) out.push(` ${tailLine.trim().slice(0, 140)}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const bounded = out.slice(0, Math.max(1, maxLines - 1));
|
|
143
|
+
bounded.push(queryHandleLine);
|
|
144
|
+
return bounded.slice(0, maxLines).join('\n');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (family === 'infra') {
|
|
148
|
+
const errors = [];
|
|
149
|
+
const stages = [];
|
|
150
|
+
for (const rawLine of lines) {
|
|
151
|
+
const line = rawLine.trim();
|
|
152
|
+
if (!line) continue;
|
|
153
|
+
if (/\b(ERROR|FATAL|panic:|CrashLoopBackOff|ImagePullBackOff|ErrImagePull|OOMKilled|FAILED|fail)\b/i.test(line) || /^[✗✖X]\s+/.test(line)) {
|
|
154
|
+
pushUniqueBounded(errors, line, 12);
|
|
155
|
+
} else if (/^(#\d+\s+(?:DONE|ERROR)|Step\s+\d+\/\d+|NAME\s+READY|Successfully\s+(?:built|tagged))/i.test(line)) {
|
|
156
|
+
pushUniqueBounded(stages, line, 6);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const out = [
|
|
160
|
+
`[FTS5 Compressed CLI Output] cmd="${command}" exit_code=${exitCode} raw_lines=${lines.length}`,
|
|
161
|
+
`Infra & Deploy Diagnostics (${errors.length} error(s), ${stages.length} stage(s)):`
|
|
162
|
+
];
|
|
163
|
+
for (const e of errors) out.push(` ${e}`);
|
|
164
|
+
for (const s of stages) out.push(` ${s}`);
|
|
165
|
+
if (errors.length === 0 && stages.length === 0) {
|
|
166
|
+
for (const tailLine of lines.slice(-6)) {
|
|
167
|
+
if (tailLine.trim()) out.push(` ${tailLine.trim().slice(0, 140)}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const bounded = out.slice(0, Math.max(1, maxLines - 1));
|
|
171
|
+
bounded.push(queryHandleLine);
|
|
172
|
+
return bounded.slice(0, maxLines).join('\n');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (family === 'search_list') {
|
|
176
|
+
const groups = new Map();
|
|
177
|
+
const samples = [];
|
|
178
|
+
const errors = [];
|
|
179
|
+
for (const rawLine of lines) {
|
|
180
|
+
const line = rawLine.trim();
|
|
181
|
+
if (!line) continue;
|
|
182
|
+
if (/\b(ERROR|FATAL|Exception|AccessDenied|UnauthorizedAccess)\b/i.test(line)) {
|
|
183
|
+
pushUniqueBounded(errors, line, 4, 140);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const grepMatch = line.match(/^((?:[A-Za-z]:)?[./\\\w-]+?\.[a-zA-Z0-9]{1,8}):(\d+):(.*)$/);
|
|
187
|
+
if (grepMatch) {
|
|
188
|
+
const key = grepMatch[1];
|
|
189
|
+
if (!groups.has(key)) groups.set(key, { count: 0, first: `L${grepMatch[2]}: ${grepMatch[3].trim()}` });
|
|
190
|
+
groups.get(key).count += 1;
|
|
191
|
+
} else {
|
|
192
|
+
pushUniqueBounded(samples, line, 12, 140);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const rawBytes = Buffer.byteLength(String(rawOutput || ''), 'utf8');
|
|
196
|
+
const out = [
|
|
197
|
+
`[FTS5 Compressed CLI Output] cmd="${String(command).slice(0, 80)}" exit_code=${exitCode} raw_lines=${lines.length} raw_bytes=${rawBytes}`,
|
|
198
|
+
`Search/List Summary (${groups.size} matched file(s), ${samples.length} other line(s)):`
|
|
199
|
+
];
|
|
200
|
+
for (const e of errors) out.push(` ! ${e}`);
|
|
201
|
+
let shown = 0;
|
|
202
|
+
for (const [fileKey, info] of groups.entries()) {
|
|
203
|
+
shown += 1;
|
|
204
|
+
if (shown > 10) {
|
|
205
|
+
out.push(` ... +${groups.size - 10} more matched files indexed`);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
out.push(` ${fileKey} (${info.count}): ${info.first}`.slice(0, 140));
|
|
209
|
+
}
|
|
210
|
+
if (groups.size === 0) {
|
|
211
|
+
for (const s of samples.slice(0, 10)) out.push(` ${s}`);
|
|
212
|
+
if (lines.length > 10) out.push(` ... +${lines.length - 10} more lines indexed`);
|
|
213
|
+
}
|
|
214
|
+
const bounded = out.slice(0, Math.max(1, maxLines - 1));
|
|
215
|
+
bounded.push(queryHandleLine);
|
|
216
|
+
return bounded.slice(0, maxLines).join('\n');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (family === 'generic_cli') {
|
|
220
|
+
const errors = [];
|
|
221
|
+
const nonEmpty = [];
|
|
222
|
+
for (const rawLine of lines) {
|
|
223
|
+
const line = rawLine.trim();
|
|
224
|
+
if (!line) continue;
|
|
225
|
+
if (
|
|
226
|
+
/\b(ERROR|FATAL|WARN|WARNING|Exception|AssertionError|TypeError|ReferenceError|SyntaxError|ERR!|FAILED|fail)\b/i.test(line) ||
|
|
227
|
+
/^(?:ℹ\s*(?:tests|suites|pass|fail)\b|#\s*(?:tests|suites|pass|fail)\b)/i.test(line)
|
|
228
|
+
) {
|
|
229
|
+
pushUniqueBounded(errors, line, 10, 240);
|
|
230
|
+
}
|
|
231
|
+
nonEmpty.push(line);
|
|
232
|
+
}
|
|
233
|
+
const rawBytes = Buffer.byteLength(String(rawOutput || ''), 'utf8');
|
|
234
|
+
const out = [
|
|
235
|
+
`[FTS5 Compressed CLI Output] cmd="${String(command).slice(0, 80)}" exit_code=${exitCode} raw_lines=${lines.length} raw_bytes=${rawBytes}`,
|
|
236
|
+
`Diagnostics & Head/Tail Preview (${errors.length} error/warn line(s)):`
|
|
237
|
+
];
|
|
238
|
+
for (const e of errors) out.push(` ${e}`);
|
|
239
|
+
for (const h of nonEmpty.slice(0, 5)) pushUniqueBounded(out, ` ${h}`, maxLines - 1, 140);
|
|
240
|
+
if (nonEmpty.length > 5) {
|
|
241
|
+
for (const t of nonEmpty.slice(-5)) pushUniqueBounded(out, ` ${t}`, maxLines - 1, 140);
|
|
242
|
+
}
|
|
243
|
+
const bounded = out.slice(0, Math.max(1, maxLines - 1));
|
|
244
|
+
bounded.push(queryHandleLine);
|
|
245
|
+
return bounded.slice(0, maxLines).join('\n');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const failingTests = [];
|
|
249
|
+
const fileLineTraces = [];
|
|
250
|
+
const assertionLines = [];
|
|
251
|
+
const summaryLines = [];
|
|
252
|
+
const warningLines = [];
|
|
253
|
+
|
|
254
|
+
for (const rawLine of lines) {
|
|
255
|
+
const line = rawLine.trim();
|
|
256
|
+
if (!line) continue;
|
|
257
|
+
|
|
258
|
+
const isKotlinWarning = /^w:\s+/.test(line);
|
|
259
|
+
const isKotlinError = /^e:\s+/.test(line);
|
|
260
|
+
|
|
261
|
+
if (
|
|
262
|
+
/^(FAILED|FAIL|✖|✗|✘|--- FAIL:)\s+/.test(line) ||
|
|
263
|
+
/^[✘✖×]\s+\d+\s+/.test(line) ||
|
|
264
|
+
/^\d+\)\s+(?:\[[^\]]+\]\s+›\s+|\S+)/.test(line) ||
|
|
265
|
+
/^_{3,}\s+.+\s+_{3,}$/.test(line) ||
|
|
266
|
+
/^test\s+[\w:./-]+\s+\.\.\.\s+FAILED/i.test(line) ||
|
|
267
|
+
/^FAIL\t\S+/.test(line) ||
|
|
268
|
+
/^\[ERROR\]\s+(?:Failures:|Errors:|BUILD\s+FAILURE|.+<<<\s*(?:FAILURE|ERROR)!|\S+:\d+\s+)/.test(line) ||
|
|
269
|
+
/^>\s+Task\s+:\S+\s+FAILED/.test(line) ||
|
|
270
|
+
/^.+\s+>\s+.+\s+FAILED$/.test(line) ||
|
|
271
|
+
/^FAILURE:\s+Build\s+failed/.test(line) ||
|
|
272
|
+
/^Execution\s+failed\s+for\s+task\s+':\S+'/i.test(line) ||
|
|
273
|
+
/^Failed\s+\S+/.test(line) ||
|
|
274
|
+
/^make(?:\[\d+\])?:\s*\*\*\*/.test(line) ||
|
|
275
|
+
/^\d+\/\d+\s+Test\s+#\d+:.+\*\*\*Failed/i.test(line) ||
|
|
276
|
+
/^(?:FAIL|ERROR):\s+(?:\/\/)?\S+/.test(line) ||
|
|
277
|
+
/^rspec\s+[\w./\\-]+:\d+/.test(line) ||
|
|
278
|
+
/^(?:FAILURES|ERRORS)!$/.test(line) ||
|
|
279
|
+
/^.+\s+\.\.\.\s+FAILED\s+\(/.test(line)
|
|
280
|
+
) {
|
|
281
|
+
const cleaned = line.replace(/^_{3,}\s*|\s*_{3,}$/g, '').trim();
|
|
282
|
+
pushUniqueBounded(failingTests, cleaned, 6, 160);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (
|
|
286
|
+
/^(?:ℹ\s*(?:tests|suites|pass|fail|cancelled|skipped|todo|duration_ms)\b|#\s*(?:tests|suites|pass|fail|cancelled|skipped|todo|ok)\b|Tests?:|Test Suites?:|Test Files?:|Ran\s+\d+\s+tests?|test result:|===+\s+\d+\s+(?:passed|failed)|\d+\s+(?:passed|passing|failed|failing)\b|PASS(?:\s+\S+)?$|ok\s+\S+\s+[\d.]+s|\[(?:INFO|ERROR)\]\s+(?:Tests\s+run:\s*\d+|BUILD\s+(?:SUCCESS|FAILURE))|\d+\s+tests?\s+completed,\s*\d+\s+failed|BUILD\s+(?:SUCCESSFUL|FAILED)|(?:Failed|Passed)!\s+-\s+Failed:\s*\d+|Build\s+(?:FAILED|succeeded)|\d+%\s+tests?\s+passed,\s*\d+\s+tests?\s+failed|Executed\s+\d+\s+out\s+of\s+\d+\s+tests?:|\d+\s+examples?,\s*\d+\s+failures?|Tests:\s*\d+,\s*Assertions:\s*\d+|OK\s+\(\d+\s+tests?|(?:ok|FAILED)\s+\|\s+\d+\s+passed\s+\|\s+\d+\s+failed)/i.test(
|
|
287
|
+
line
|
|
288
|
+
)
|
|
289
|
+
) {
|
|
290
|
+
pushUniqueBounded(summaryLines, line, 8, 200);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (/\b(?:WARN|WARNING)\b[:\s]/i.test(line) || isKotlinWarning) {
|
|
294
|
+
pushUniqueBounded(warningLines, line, 4, 240);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (
|
|
298
|
+
!isKotlinWarning &&
|
|
299
|
+
(/\b[A-Za-z0-9_./\\-]+\.(?:py|ts|tsx|js|mjs|cjs|rs|go|java|kt|kts|groovy|scala|rb|php|cs|cpp|cc|cxx|c|h|hpp)(?::\d+(?::\d+)?|\[\d+,\d+\]|(?::\s*)?\(\d+,\s*\d+\)|\s*:\s*line\s+\d+)/i.test(
|
|
300
|
+
line
|
|
301
|
+
) ||
|
|
302
|
+
/\b[A-Za-z0-9_./\\-]+\.(?:ts|tsx|cs)\(\d+,\d+\):\s*error\s+(?:TS|CS)\d+/i.test(line) ||
|
|
303
|
+
/\bMakefile:\d+/.test(line) ||
|
|
304
|
+
/^\d+:\d+\s+(?:error|warning)\s+/i.test(line) ||
|
|
305
|
+
/\berror\[E\d+\]:/i.test(line) ||
|
|
306
|
+
(family === 'lint_build' && /^[A-Za-z0-9_./\\-]+\.(?:py|ts|tsx|js|mjs|cjs|rs|go|jsx|java|kt|cs|cpp|c)$/.test(line)))
|
|
307
|
+
) {
|
|
308
|
+
pushUniqueBounded(fileLineTraces, line, 9, 180);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (
|
|
312
|
+
isKotlinError ||
|
|
313
|
+
/^(E\s+|AssertionError:|Error:|Expected\b|Received\b|Actual\b|assert\s+|error\s+|Failed asserting|Caused by:|org\.junit|org\.opentest4j\.|kotlin\.test\.|java\.lang\.AssertionError|AssertionFailedError\b|Assert\.|\[ERROR\]\s+.*error:|>\s+(?:Compilation\s+error|Could\s+not\s+resolve|There\s+were\s+failing\s+tests))/i.test(
|
|
314
|
+
line
|
|
315
|
+
)
|
|
316
|
+
) {
|
|
317
|
+
pushUniqueBounded(assertionLines, line, 5, 180);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const out = [];
|
|
322
|
+
out.push(`[FTS5 Compressed CLI Output] cmd="${command}" exit_code=${exitCode} raw_lines=${lines.length}`);
|
|
323
|
+
if (failingTests.length === 0 && Number(exitCode) === 0) {
|
|
324
|
+
out.push('Result: PASS (0 failing tests)');
|
|
325
|
+
if (warningLines.length > 0) {
|
|
326
|
+
out.push(`Warnings (${warningLines.length}):`);
|
|
327
|
+
for (const w of warningLines) out.push(` ${w}`);
|
|
328
|
+
}
|
|
329
|
+
out.push('Test Summary:');
|
|
330
|
+
if (summaryLines.length > 0) {
|
|
331
|
+
for (const s of summaryLines) out.push(` ${s}`);
|
|
332
|
+
} else if (fileLineTraces.length > 0) {
|
|
333
|
+
for (const tr of fileLineTraces.slice(0, 8)) out.push(` ${tr}`);
|
|
334
|
+
} else {
|
|
335
|
+
for (const tailLine of lines.slice(-6)) {
|
|
336
|
+
if (tailLine.trim()) out.push(` ${tailLine.trim().slice(0, 140)}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
out.push(`Failing Tests (${failingTests.length}):`);
|
|
341
|
+
if (failingTests.length > 0) {
|
|
342
|
+
for (const ft of failingTests.slice(0, 6)) out.push(` - ${ft}`);
|
|
343
|
+
} else {
|
|
344
|
+
out.push(` - (No structured test header matched; see tracebacks below)`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
out.push(`File:Line Tracebacks & Assertions:`);
|
|
348
|
+
const combinedTraces = [...new Set([...fileLineTraces, ...assertionLines])].slice(summaryLines.length > 0 ? 0 : 0, summaryLines.length > 0 ? 8 : 10);
|
|
349
|
+
if (combinedTraces.length > 0) {
|
|
350
|
+
for (const tr of combinedTraces) out.push(` ${tr}`);
|
|
351
|
+
} else {
|
|
352
|
+
for (const tailLine of lines.slice(-6)) {
|
|
353
|
+
if (tailLine.trim()) out.push(` ${tailLine.trim().slice(0, 140)}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (warningLines.length > 0) {
|
|
357
|
+
out.push(`Warnings (${warningLines.length}):`);
|
|
358
|
+
for (const w of warningLines.slice(0, 2)) out.push(` ${w}`);
|
|
359
|
+
}
|
|
360
|
+
if (summaryLines.length > 0) {
|
|
361
|
+
out.push('Test Summary:');
|
|
362
|
+
for (const s of summaryLines.slice(0, 4)) out.push(` ${s}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const bounded = out.slice(0, Math.max(1, maxLines - 1));
|
|
367
|
+
bounded.push(queryHandleLine);
|
|
368
|
+
return bounded.slice(0, maxLines).join('\n');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function compressCliOutputFts5Sync({
|
|
372
|
+
sessionId = 'default-session',
|
|
373
|
+
turnId = 'turn-1',
|
|
374
|
+
command = 'pytest',
|
|
375
|
+
exitCode = 1,
|
|
376
|
+
rawOutput = '',
|
|
377
|
+
dbPath = null,
|
|
378
|
+
homeDir = getHomeDir(),
|
|
379
|
+
DatabaseSync = null,
|
|
380
|
+
forceCompress = false,
|
|
381
|
+
recordLedger = true,
|
|
382
|
+
ledgerPath = null,
|
|
383
|
+
minBytes = 0,
|
|
384
|
+
minTokensSaved = 0,
|
|
385
|
+
retentionDays = 30
|
|
386
|
+
} = {}) {
|
|
387
|
+
const rawStr = redactSecretsPure(String(rawOutput || '')).sanitized;
|
|
388
|
+
const rawLines = rawStr.split(/\r?\n/);
|
|
389
|
+
const rawBytes = Buffer.byteLength(rawStr, 'utf8');
|
|
390
|
+
const rawTokens = Math.ceil(rawStr.length / 4);
|
|
391
|
+
const meetsMinBytes = minBytes <= 0 || rawBytes >= Number(minBytes);
|
|
392
|
+
const meetsSizeThreshold =
|
|
393
|
+
meetsMinBytes &&
|
|
394
|
+
(rawLines.length > FTS5_COMPRESSOR_CONSTANTS.MIN_LINES_TO_COMPRESS ||
|
|
395
|
+
rawBytes >= FTS5_COMPRESSOR_CONSTANTS.MIN_BYTES_TO_COMPRESS);
|
|
396
|
+
|
|
397
|
+
if (!forceCompress && (!meetsSizeThreshold || !isCompressibleCliCommand(command))) {
|
|
398
|
+
return {
|
|
399
|
+
compressed: false,
|
|
400
|
+
failOpen: false,
|
|
401
|
+
output: rawStr,
|
|
402
|
+
lineCount: rawLines.length,
|
|
403
|
+
rawTokens,
|
|
404
|
+
compressedTokens: rawTokens,
|
|
405
|
+
tokensSaved: 0,
|
|
406
|
+
reductionPct: 0,
|
|
407
|
+
turnId,
|
|
408
|
+
queryHandle: null
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let db = null;
|
|
413
|
+
try {
|
|
414
|
+
const resolvedDbPath = dbPath || getDefaultToolLogsDbPath(homeDir);
|
|
415
|
+
db = openBurnoffDb(resolvedDbPath, { readOnly: false, DatabaseSync });
|
|
416
|
+
|
|
417
|
+
db.exec(`
|
|
418
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS tool_logs USING fts5(
|
|
419
|
+
session_id,
|
|
420
|
+
turn_id,
|
|
421
|
+
command,
|
|
422
|
+
exit_code,
|
|
423
|
+
raw_output,
|
|
424
|
+
created_at
|
|
425
|
+
);
|
|
426
|
+
CREATE TABLE IF NOT EXISTS tool_logs_meta (
|
|
427
|
+
key TEXT PRIMARY KEY,
|
|
428
|
+
value TEXT NOT NULL
|
|
429
|
+
);
|
|
430
|
+
`);
|
|
431
|
+
|
|
432
|
+
const createdAt = new Date().toISOString();
|
|
433
|
+
db.prepare(`
|
|
434
|
+
INSERT INTO tool_logs (session_id, turn_id, command, exit_code, raw_output, created_at)
|
|
435
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
436
|
+
`).run(
|
|
437
|
+
String(sessionId),
|
|
438
|
+
String(turnId),
|
|
439
|
+
String(command),
|
|
440
|
+
String(exitCode),
|
|
441
|
+
rawStr,
|
|
442
|
+
createdAt
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
try {
|
|
446
|
+
pruneExpiredFts5LogsSync(db, Date.now(), Number(retentionDays ?? 30));
|
|
447
|
+
} catch (pruneErr) {
|
|
448
|
+
void pruneErr; // ignore: non-fatal background retention prune
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const summary = buildDeterministicSummary(rawStr, {
|
|
452
|
+
command,
|
|
453
|
+
exitCode,
|
|
454
|
+
turnId,
|
|
455
|
+
maxLines: FTS5_COMPRESSOR_CONSTANTS.MAX_SUMMARY_LINES
|
|
456
|
+
});
|
|
457
|
+
if (!forceCompress && summary.length >= rawStr.length) {
|
|
458
|
+
return {
|
|
459
|
+
compressed: false,
|
|
460
|
+
failOpen: false,
|
|
461
|
+
dbPath: resolvedDbPath,
|
|
462
|
+
output: rawStr,
|
|
463
|
+
lineCount: rawLines.length,
|
|
464
|
+
rawTokens,
|
|
465
|
+
compressedTokens: rawTokens,
|
|
466
|
+
tokensSaved: 0,
|
|
467
|
+
reductionPct: 0,
|
|
468
|
+
turnId: String(turnId),
|
|
469
|
+
queryHandle: null
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
const summaryLines = summary.split(/\r?\n/);
|
|
473
|
+
const compressedTokens = Math.ceil(summary.length / 4);
|
|
474
|
+
const tokensSaved = Math.max(0, rawTokens - compressedTokens);
|
|
475
|
+
if (!forceCompress && minTokensSaved > 0 && tokensSaved < Number(minTokensSaved)) {
|
|
476
|
+
return {
|
|
477
|
+
compressed: false,
|
|
478
|
+
failOpen: false,
|
|
479
|
+
dbPath: resolvedDbPath,
|
|
480
|
+
output: rawStr,
|
|
481
|
+
lineCount: rawLines.length,
|
|
482
|
+
rawTokens,
|
|
483
|
+
compressedTokens: rawTokens,
|
|
484
|
+
tokensSaved: 0,
|
|
485
|
+
reductionPct: 0,
|
|
486
|
+
turnId: String(turnId),
|
|
487
|
+
queryHandle: null
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
const reductionPct = rawTokens > 0 ? Number(((tokensSaved / rawTokens) * 100).toFixed(1)) : 0;
|
|
491
|
+
|
|
492
|
+
if (recordLedger && tokensSaved > 0 && !DatabaseSync) {
|
|
493
|
+
try {
|
|
494
|
+
recordInterventionSavings(
|
|
495
|
+
{
|
|
496
|
+
sessionId: String(sessionId),
|
|
497
|
+
turnId: String(turnId),
|
|
498
|
+
dedupeId: `fts5:${sessionId}:${turnId}:${command}`,
|
|
499
|
+
category: 'CLI_FTS5_COMPRESSED',
|
|
500
|
+
savedTokens: tokensSaved,
|
|
501
|
+
detail: `FTS5 compressed "${String(command).slice(0, 60)}" (${rawLines.length} -> ${summaryLines.length} lines)`
|
|
502
|
+
},
|
|
503
|
+
{ homeDir, ledgerPath }
|
|
504
|
+
);
|
|
505
|
+
} catch (err) {
|
|
506
|
+
void err; // ignore: best-effort ledger telemetry must never break fail-open compression
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return {
|
|
511
|
+
compressed: true,
|
|
512
|
+
failOpen: false,
|
|
513
|
+
dbPath: resolvedDbPath,
|
|
514
|
+
output: summary,
|
|
515
|
+
lineCount: summaryLines.length,
|
|
516
|
+
rawLineCount: rawLines.length,
|
|
517
|
+
rawTokens,
|
|
518
|
+
compressedTokens,
|
|
519
|
+
tokensSaved,
|
|
520
|
+
reductionPct,
|
|
521
|
+
turnId: String(turnId),
|
|
522
|
+
queryHandle: `npx burnoff search ${turnId} "<keyword>"`,
|
|
523
|
+
recallCommand: `npx burnoff search ${turnId} "<keyword>"`
|
|
524
|
+
};
|
|
525
|
+
} catch (err) {
|
|
526
|
+
return {
|
|
527
|
+
compressed: false,
|
|
528
|
+
failOpen: true,
|
|
529
|
+
error: String(err?.message || err),
|
|
530
|
+
output: rawStr,
|
|
531
|
+
lineCount: rawLines.length,
|
|
532
|
+
rawTokens,
|
|
533
|
+
compressedTokens: rawTokens,
|
|
534
|
+
tokensSaved: 0,
|
|
535
|
+
reductionPct: 0,
|
|
536
|
+
turnId: String(turnId),
|
|
537
|
+
queryHandle: null
|
|
538
|
+
};
|
|
539
|
+
} finally {
|
|
540
|
+
try {
|
|
541
|
+
if (db) db.close();
|
|
542
|
+
} catch (closeErr) {
|
|
543
|
+
void closeErr; // ignore: db close guard
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export async function compressCliOutputFts5(options = {}) {
|
|
549
|
+
return compressCliOutputFts5Sync(options);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export async function compressToolOutputWithFts5(options = {}) {
|
|
553
|
+
return compressCliOutputFts5Sync(options);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Prunes FTS5 `tool_logs` entries older than `retentionDays` at most once per 24 hours.
|
|
558
|
+
* Runs `VACUUM` automatically when `deletedRows >= 500`.
|
|
559
|
+
*/
|
|
560
|
+
export function pruneExpiredFts5LogsSync(
|
|
561
|
+
db,
|
|
562
|
+
nowMs = Date.now(),
|
|
563
|
+
retentionDays = 30,
|
|
564
|
+
options = {}
|
|
565
|
+
) {
|
|
566
|
+
if (!db || typeof db.exec !== 'function' || typeof db.prepare !== 'function') {
|
|
567
|
+
return { skipped: true, deletedRows: 0, vacuumed: false };
|
|
568
|
+
}
|
|
569
|
+
db.exec(`
|
|
570
|
+
CREATE TABLE IF NOT EXISTS tool_logs_meta (
|
|
571
|
+
key TEXT PRIMARY KEY,
|
|
572
|
+
value TEXT NOT NULL
|
|
573
|
+
);
|
|
574
|
+
`);
|
|
575
|
+
|
|
576
|
+
const metaRow = db.prepare("SELECT value FROM tool_logs_meta WHERE key = 'last_prune_ms'").get();
|
|
577
|
+
const lastPruneMs = metaRow ? Number(metaRow.value) : 0;
|
|
578
|
+
if (!options.force && Number.isFinite(lastPruneMs) && lastPruneMs > 0 && nowMs - lastPruneMs < 86_400_000) {
|
|
579
|
+
return { skipped: true, deletedRows: 0, vacuumed: false };
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
const cutoffMs = nowMs - Math.max(1, Number(retentionDays || 30)) * 86_400_000;
|
|
583
|
+
const cutoffIso = new Date(cutoffMs).toISOString();
|
|
584
|
+
const res = db.prepare('DELETE FROM tool_logs WHERE created_at < ?').run(cutoffIso);
|
|
585
|
+
const deletedRows = Number(res?.changes || 0);
|
|
586
|
+
|
|
587
|
+
db.prepare("INSERT OR REPLACE INTO tool_logs_meta (key, value) VALUES ('last_prune_ms', ?)").run(String(nowMs));
|
|
588
|
+
|
|
589
|
+
let vacuumed = false;
|
|
590
|
+
if (deletedRows >= 500) {
|
|
591
|
+
db.exec('VACUUM');
|
|
592
|
+
vacuumed = true;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return { skipped: false, deletedRows, vacuumed, cutoffIso };
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export async function searchToolLogsFts5(dbPath, {
|
|
599
|
+
turnId = '',
|
|
600
|
+
keyword = '',
|
|
601
|
+
limit = 10,
|
|
602
|
+
homeDir = null,
|
|
603
|
+
DatabaseSync = null
|
|
604
|
+
} = {}) {
|
|
605
|
+
const resolvedDbPath = dbPath || getDefaultToolLogsDbPath(homeDir);
|
|
606
|
+
if (!fs.existsSync(resolvedDbPath) && !fs.existsSync(resolveFallbackDbPath(resolvedDbPath))) {
|
|
607
|
+
return { hits: [], matchedLines: [] };
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
let db = null;
|
|
611
|
+
try {
|
|
612
|
+
db = openBurnoffDb(resolvedDbPath, { readOnly: true, DatabaseSync });
|
|
613
|
+
const cleanKeyword = String(keyword || '').replace(/[^A-Za-z0-9_./:-]/g, ' ').trim();
|
|
614
|
+
const maxLimit = Math.max(1, Number(limit) || 10);
|
|
615
|
+
const cleanTurnId = turnId ? String(turnId) : '';
|
|
616
|
+
|
|
617
|
+
let rows = [];
|
|
618
|
+
if (cleanKeyword) {
|
|
619
|
+
const ftsToken = cleanKeyword.split(/\s+/).filter(Boolean).map((t) => `"${t}"`).join(' AND ');
|
|
620
|
+
if (cleanTurnId) {
|
|
621
|
+
rows = db.prepare(`
|
|
622
|
+
SELECT session_id AS sessionId, turn_id AS turnId, command, exit_code AS exitCode, raw_output AS rawOutput, created_at AS createdAt
|
|
623
|
+
FROM tool_logs
|
|
624
|
+
WHERE turn_id = ? AND tool_logs MATCH ?
|
|
625
|
+
LIMIT ?
|
|
626
|
+
`).all(cleanTurnId, ftsToken, maxLimit);
|
|
627
|
+
} else {
|
|
628
|
+
rows = db.prepare(`
|
|
629
|
+
SELECT session_id AS sessionId, turn_id AS turnId, command, exit_code AS exitCode, raw_output AS rawOutput, created_at AS createdAt
|
|
630
|
+
FROM tool_logs
|
|
631
|
+
WHERE tool_logs MATCH ?
|
|
632
|
+
LIMIT ?
|
|
633
|
+
`).all(ftsToken, maxLimit);
|
|
634
|
+
}
|
|
635
|
+
} else if (cleanTurnId) {
|
|
636
|
+
rows = db.prepare(`
|
|
637
|
+
SELECT session_id AS sessionId, turn_id AS turnId, command, exit_code AS exitCode, raw_output AS rawOutput, created_at AS createdAt
|
|
638
|
+
FROM tool_logs
|
|
639
|
+
WHERE turn_id = ?
|
|
640
|
+
LIMIT ?
|
|
641
|
+
`).all(cleanTurnId, maxLimit);
|
|
642
|
+
} else {
|
|
643
|
+
rows = db.prepare(`
|
|
644
|
+
SELECT session_id AS sessionId, turn_id AS turnId, command, exit_code AS exitCode, raw_output AS rawOutput, created_at AS createdAt
|
|
645
|
+
FROM tool_logs
|
|
646
|
+
LIMIT ?
|
|
647
|
+
`).all(maxLimit);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const matchedLines = [];
|
|
651
|
+
const kwLower = String(keyword || '').toLowerCase();
|
|
652
|
+
for (const r of rows) {
|
|
653
|
+
const lines = String(r.rawOutput || '').split(/\r?\n/);
|
|
654
|
+
for (let i = 0; i < lines.length; i++) {
|
|
655
|
+
if (!kwLower || lines[i].toLowerCase().includes(kwLower)) {
|
|
656
|
+
matchedLines.push({
|
|
657
|
+
turnId: r.turnId,
|
|
658
|
+
lineNumber: i + 1,
|
|
659
|
+
text: lines[i],
|
|
660
|
+
source: 'tool_logs'
|
|
661
|
+
});
|
|
662
|
+
if (matchedLines.length >= 25) break;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (matchedLines.length >= 25) break;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return { hits: rows, matchedLines };
|
|
669
|
+
} catch (err) {
|
|
670
|
+
void err; // ignore: search failure returns empty hits
|
|
671
|
+
return { hits: [], matchedLines: [] };
|
|
672
|
+
} finally {
|
|
673
|
+
try {
|
|
674
|
+
if (db) db.close();
|
|
675
|
+
} catch (closeErr) {
|
|
676
|
+
void closeErr; // ignore: db close guard
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export async function searchFts5Logs(options = {}) {
|
|
682
|
+
const { turnId = '', keyword = '', limit = 10, dbPath = null, homeDir = null, DatabaseSync = null } = options;
|
|
683
|
+
return searchToolLogsFts5(dbPath, { turnId, keyword, limit, homeDir, DatabaseSync });
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export function getFts5CompressionStats(dbPath = null, { DatabaseSync = null, homeDir = null } = {}) {
|
|
687
|
+
const resolvedDbPath = dbPath || getDefaultToolLogsDbPath(homeDir);
|
|
688
|
+
if (!fs.existsSync(resolvedDbPath) && !fs.existsSync(resolveFallbackDbPath(resolvedDbPath))) {
|
|
689
|
+
return { active: true, logCount: 0, savedTokens: 0, formattedSavedK: '0.0k' };
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
let db = null;
|
|
693
|
+
try {
|
|
694
|
+
db = openBurnoffDb(resolvedDbPath, { readOnly: true, DatabaseSync });
|
|
695
|
+
const row = db.prepare(`
|
|
696
|
+
SELECT count(*) as count, coalesce(sum(length(raw_output)), 0) as totalBytes
|
|
697
|
+
FROM tool_logs
|
|
698
|
+
`).get();
|
|
699
|
+
|
|
700
|
+
const count = Number(row?.count || 0);
|
|
701
|
+
const totalBytes = Number(row?.totalBytes || 0);
|
|
702
|
+
const rawTokensEst = Math.ceil(totalBytes / 4);
|
|
703
|
+
const summaryTokensEst = count * 300;
|
|
704
|
+
const savedTokens = Math.max(0, rawTokensEst - summaryTokensEst);
|
|
705
|
+
const formattedSavedK = `${(savedTokens / 1000).toFixed(1)}k`;
|
|
706
|
+
|
|
707
|
+
return { active: true, logCount: count, savedTokens, formattedSavedK };
|
|
708
|
+
} catch (err) {
|
|
709
|
+
void err; // ignore: unreadable FTS5 store reports empty stats
|
|
710
|
+
return { active: true, logCount: 0, savedTokens: 0, formattedSavedK: '0.0k' };
|
|
711
|
+
} finally {
|
|
712
|
+
try {
|
|
713
|
+
if (db) db.close();
|
|
714
|
+
} catch (closeErr) {
|
|
715
|
+
void closeErr; // ignore: db close guard
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export default {
|
|
721
|
+
FTS5_COMPRESSOR_CONSTANTS,
|
|
722
|
+
getDefaultToolLogsDbPath,
|
|
723
|
+
isCompressibleCliCommand,
|
|
724
|
+
classifyShellPostToolPolicy,
|
|
725
|
+
classifyCliCommandFamily,
|
|
726
|
+
buildDeterministicSummary,
|
|
727
|
+
compressCliOutputFts5Sync,
|
|
728
|
+
compressCliOutputFts5,
|
|
729
|
+
compressToolOutputWithFts5,
|
|
730
|
+
pruneExpiredFts5LogsSync,
|
|
731
|
+
searchToolLogsFts5,
|
|
732
|
+
searchFts5Logs,
|
|
733
|
+
getFts5CompressionStats
|
|
734
|
+
};
|