@yhong91/vibetime 0.1.25 → 0.1.27

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.
Files changed (2) hide show
  1. package/bin/vibetime.mjs +1884 -257
  2. package/package.json +2 -1
package/bin/vibetime.mjs CHANGED
@@ -157,11 +157,736 @@ var init_fs = __esm({
157
157
  }
158
158
  });
159
159
 
160
+ // ../../node_modules/.pnpm/fzstd@0.1.1/node_modules/fzstd/esm/index.mjs
161
+ var esm_exports = {};
162
+ __export(esm_exports, {
163
+ Decompress: () => Decompress,
164
+ ZstdErrorCode: () => ZstdErrorCode,
165
+ decompress: () => decompress
166
+ });
167
+ function decompress(dat, buf) {
168
+ var bufs = [], nb = +!buf;
169
+ var bt = 0, ol = 0;
170
+ for (; dat.length; ) {
171
+ var st = rzfh(dat, nb || buf);
172
+ if (typeof st == "object") {
173
+ if (nb) {
174
+ buf = null;
175
+ if (st.w.length == st.u) {
176
+ bufs.push(buf = st.w);
177
+ ol += st.u;
178
+ }
179
+ } else {
180
+ bufs.push(buf);
181
+ st.e = 0;
182
+ }
183
+ for (; !st.l; ) {
184
+ var blk = rzb(dat, st, buf);
185
+ if (!blk)
186
+ err(5);
187
+ if (buf)
188
+ st.e = st.y;
189
+ else {
190
+ bufs.push(blk);
191
+ ol += blk.length;
192
+ cpw(st.w, 0, blk.length);
193
+ st.w.set(blk, st.w.length - blk.length);
194
+ }
195
+ }
196
+ bt = st.b + st.c * 4;
197
+ } else
198
+ bt = st;
199
+ dat = dat.subarray(bt);
200
+ }
201
+ return cct(bufs, ol);
202
+ }
203
+ var ab, u8, u16, i16, i32, slc, fill, cpw, ZstdErrorCode, ec, err, rb, b4, rzfh, msb, rfse, rhu, dllt, dmlt, doct, b2bl, llb, llbl, mlb, mlbl, dhu, dhu4, rzb, cct, Decompress;
204
+ var init_esm = __esm({
205
+ "../../node_modules/.pnpm/fzstd@0.1.1/node_modules/fzstd/esm/index.mjs"() {
206
+ ab = ArrayBuffer;
207
+ u8 = Uint8Array;
208
+ u16 = Uint16Array;
209
+ i16 = Int16Array;
210
+ i32 = Int32Array;
211
+ slc = function(v, s, e) {
212
+ if (u8.prototype.slice)
213
+ return u8.prototype.slice.call(v, s, e);
214
+ if (s == null || s < 0)
215
+ s = 0;
216
+ if (e == null || e > v.length)
217
+ e = v.length;
218
+ var n = new u8(e - s);
219
+ n.set(v.subarray(s, e));
220
+ return n;
221
+ };
222
+ fill = function(v, n, s, e) {
223
+ if (u8.prototype.fill)
224
+ return u8.prototype.fill.call(v, n, s, e);
225
+ if (s == null || s < 0)
226
+ s = 0;
227
+ if (e == null || e > v.length)
228
+ e = v.length;
229
+ for (; s < e; ++s)
230
+ v[s] = n;
231
+ return v;
232
+ };
233
+ cpw = function(v, t, s, e) {
234
+ if (u8.prototype.copyWithin)
235
+ return u8.prototype.copyWithin.call(v, t, s, e);
236
+ if (s == null || s < 0)
237
+ s = 0;
238
+ if (e == null || e > v.length)
239
+ e = v.length;
240
+ while (s < e) {
241
+ v[t++] = v[s++];
242
+ }
243
+ };
244
+ ZstdErrorCode = {
245
+ InvalidData: 0,
246
+ WindowSizeTooLarge: 1,
247
+ InvalidBlockType: 2,
248
+ FSEAccuracyTooHigh: 3,
249
+ DistanceTooFarBack: 4,
250
+ UnexpectedEOF: 5
251
+ };
252
+ ec = [
253
+ "invalid zstd data",
254
+ "window size too large (>2046MB)",
255
+ "invalid block type",
256
+ "FSE accuracy too high",
257
+ "match distance too far back",
258
+ "unexpected EOF"
259
+ ];
260
+ err = function(ind, msg, nt) {
261
+ var e = new Error(msg || ec[ind]);
262
+ e.code = ind;
263
+ if (Error.captureStackTrace)
264
+ Error.captureStackTrace(e, err);
265
+ if (!nt)
266
+ throw e;
267
+ return e;
268
+ };
269
+ rb = function(d, b, n) {
270
+ var i = 0, o = 0;
271
+ for (; i < n; ++i)
272
+ o |= d[b++] << (i << 3);
273
+ return o;
274
+ };
275
+ b4 = function(d, b) {
276
+ return (d[b] | d[b + 1] << 8 | d[b + 2] << 16 | d[b + 3] << 24) >>> 0;
277
+ };
278
+ rzfh = function(dat, w) {
279
+ var n3 = dat[0] | dat[1] << 8 | dat[2] << 16;
280
+ if (n3 == 3126568 && dat[3] == 253) {
281
+ var flg = dat[4];
282
+ var ss = flg >> 5 & 1, cc = flg >> 2 & 1, df = flg & 3, fcf = flg >> 6;
283
+ if (flg & 8)
284
+ err(0);
285
+ var bt = 6 - ss;
286
+ var db = df == 3 ? 4 : df;
287
+ var di = rb(dat, bt, db);
288
+ bt += db;
289
+ var fsb = fcf ? 1 << fcf : ss;
290
+ var fss = rb(dat, bt, fsb) + (fcf == 1 && 256);
291
+ var ws = fss;
292
+ if (!ss) {
293
+ var wb = 1 << 10 + (dat[5] >> 3);
294
+ ws = wb + (wb >> 3) * (dat[5] & 7);
295
+ }
296
+ if (ws > 2145386496)
297
+ err(1);
298
+ var buf = new u8((w == 1 ? fss || ws : w ? 0 : ws) + 12);
299
+ buf[0] = 1, buf[4] = 4, buf[8] = 8;
300
+ return {
301
+ b: bt + fsb,
302
+ y: 0,
303
+ l: 0,
304
+ d: di,
305
+ w: w && w != 1 ? w : buf.subarray(12),
306
+ e: ws,
307
+ o: new i32(buf.buffer, 0, 3),
308
+ u: fss,
309
+ c: cc,
310
+ m: Math.min(131072, ws)
311
+ };
312
+ } else if ((n3 >> 4 | dat[3] << 20) == 25481893) {
313
+ return b4(dat, 4) + 8;
314
+ }
315
+ err(0);
316
+ };
317
+ msb = function(val) {
318
+ var bits = 0;
319
+ for (; 1 << bits <= val; ++bits)
320
+ ;
321
+ return bits - 1;
322
+ };
323
+ rfse = function(dat, bt, mal) {
324
+ var tpos = (bt << 3) + 4;
325
+ var al = (dat[bt] & 15) + 5;
326
+ if (al > mal)
327
+ err(3);
328
+ var sz = 1 << al;
329
+ var probs = sz, sym = -1, re = -1, i = -1, ht = sz;
330
+ var buf = new ab(512 + (sz << 2));
331
+ var freq = new i16(buf, 0, 256);
332
+ var dstate = new u16(buf, 0, 256);
333
+ var nstate = new u16(buf, 512, sz);
334
+ var bb1 = 512 + (sz << 1);
335
+ var syms = new u8(buf, bb1, sz);
336
+ var nbits = new u8(buf, bb1 + sz);
337
+ while (sym < 255 && probs > 0) {
338
+ var bits = msb(probs + 1);
339
+ var cbt = tpos >> 3;
340
+ var msk = (1 << bits + 1) - 1;
341
+ var val = (dat[cbt] | dat[cbt + 1] << 8 | dat[cbt + 2] << 16) >> (tpos & 7) & msk;
342
+ var msk1fb = (1 << bits) - 1;
343
+ var msv = msk - probs - 1;
344
+ var sval = val & msk1fb;
345
+ if (sval < msv)
346
+ tpos += bits, val = sval;
347
+ else {
348
+ tpos += bits + 1;
349
+ if (val > msk1fb)
350
+ val -= msv;
351
+ }
352
+ freq[++sym] = --val;
353
+ if (val == -1) {
354
+ probs += val;
355
+ syms[--ht] = sym;
356
+ } else
357
+ probs -= val;
358
+ if (!val) {
359
+ do {
360
+ var rbt = tpos >> 3;
361
+ re = (dat[rbt] | dat[rbt + 1] << 8) >> (tpos & 7) & 3;
362
+ tpos += 2;
363
+ sym += re;
364
+ } while (re == 3);
365
+ }
366
+ }
367
+ if (sym > 255 || probs)
368
+ err(0);
369
+ var sympos = 0;
370
+ var sstep = (sz >> 1) + (sz >> 3) + 3;
371
+ var smask = sz - 1;
372
+ for (var s = 0; s <= sym; ++s) {
373
+ var sf = freq[s];
374
+ if (sf < 1) {
375
+ dstate[s] = -sf;
376
+ continue;
377
+ }
378
+ for (i = 0; i < sf; ++i) {
379
+ syms[sympos] = s;
380
+ do {
381
+ sympos = sympos + sstep & smask;
382
+ } while (sympos >= ht);
383
+ }
384
+ }
385
+ if (sympos)
386
+ err(0);
387
+ for (i = 0; i < sz; ++i) {
388
+ var ns = dstate[syms[i]]++;
389
+ var nb = nbits[i] = al - msb(ns);
390
+ nstate[i] = (ns << nb) - sz;
391
+ }
392
+ return [tpos + 7 >> 3, {
393
+ b: al,
394
+ s: syms,
395
+ n: nbits,
396
+ t: nstate
397
+ }];
398
+ };
399
+ rhu = function(dat, bt) {
400
+ var i = 0, wc = -1;
401
+ var buf = new u8(292), hb = dat[bt];
402
+ var hw = buf.subarray(0, 256);
403
+ var rc = buf.subarray(256, 268);
404
+ var ri = new u16(buf.buffer, 268);
405
+ if (hb < 128) {
406
+ var _a = rfse(dat, bt + 1, 6), ebt = _a[0], fdt = _a[1];
407
+ bt += hb;
408
+ var epos = ebt << 3;
409
+ var lb = dat[bt];
410
+ if (!lb)
411
+ err(0);
412
+ var st1 = 0, st2 = 0, btr1 = fdt.b, btr2 = btr1;
413
+ var fpos = (++bt << 3) - 8 + msb(lb);
414
+ for (; ; ) {
415
+ fpos -= btr1;
416
+ if (fpos < epos)
417
+ break;
418
+ var cbt = fpos >> 3;
419
+ st1 += (dat[cbt] | dat[cbt + 1] << 8) >> (fpos & 7) & (1 << btr1) - 1;
420
+ hw[++wc] = fdt.s[st1];
421
+ fpos -= btr2;
422
+ if (fpos < epos)
423
+ break;
424
+ cbt = fpos >> 3;
425
+ st2 += (dat[cbt] | dat[cbt + 1] << 8) >> (fpos & 7) & (1 << btr2) - 1;
426
+ hw[++wc] = fdt.s[st2];
427
+ btr1 = fdt.n[st1];
428
+ st1 = fdt.t[st1];
429
+ btr2 = fdt.n[st2];
430
+ st2 = fdt.t[st2];
431
+ }
432
+ if (++wc > 255)
433
+ err(0);
434
+ } else {
435
+ wc = hb - 127;
436
+ for (; i < wc; i += 2) {
437
+ var byte = dat[++bt];
438
+ hw[i] = byte >> 4;
439
+ hw[i + 1] = byte & 15;
440
+ }
441
+ ++bt;
442
+ }
443
+ var wes = 0;
444
+ for (i = 0; i < wc; ++i) {
445
+ var wt = hw[i];
446
+ if (wt > 11)
447
+ err(0);
448
+ wes += wt && 1 << wt - 1;
449
+ }
450
+ var mb = msb(wes) + 1;
451
+ var ts = 1 << mb;
452
+ var rem = ts - wes;
453
+ if (rem & rem - 1)
454
+ err(0);
455
+ hw[wc++] = msb(rem) + 1;
456
+ for (i = 0; i < wc; ++i) {
457
+ var wt = hw[i];
458
+ ++rc[hw[i] = wt && mb + 1 - wt];
459
+ }
460
+ var hbuf = new u8(ts << 1);
461
+ var syms = hbuf.subarray(0, ts), nb = hbuf.subarray(ts);
462
+ ri[mb] = 0;
463
+ for (i = mb; i > 0; --i) {
464
+ var pv = ri[i];
465
+ fill(nb, i, pv, ri[i - 1] = pv + rc[i] * (1 << mb - i));
466
+ }
467
+ if (ri[0] != ts)
468
+ err(0);
469
+ for (i = 0; i < wc; ++i) {
470
+ var bits = hw[i];
471
+ if (bits) {
472
+ var code = ri[bits];
473
+ fill(syms, i, code, ri[bits] = code + (1 << mb - bits));
474
+ }
475
+ }
476
+ return [bt, {
477
+ n: nb,
478
+ b: mb,
479
+ s: syms
480
+ }];
481
+ };
482
+ dllt = rfse(/* @__PURE__ */ new u8([
483
+ 81,
484
+ 16,
485
+ 99,
486
+ 140,
487
+ 49,
488
+ 198,
489
+ 24,
490
+ 99,
491
+ 12,
492
+ 33,
493
+ 196,
494
+ 24,
495
+ 99,
496
+ 102,
497
+ 102,
498
+ 134,
499
+ 70,
500
+ 146,
501
+ 4
502
+ ]), 0, 6)[1];
503
+ dmlt = rfse(/* @__PURE__ */ new u8([
504
+ 33,
505
+ 20,
506
+ 196,
507
+ 24,
508
+ 99,
509
+ 140,
510
+ 33,
511
+ 132,
512
+ 16,
513
+ 66,
514
+ 8,
515
+ 33,
516
+ 132,
517
+ 16,
518
+ 66,
519
+ 8,
520
+ 33,
521
+ 68,
522
+ 68,
523
+ 68,
524
+ 68,
525
+ 68,
526
+ 68,
527
+ 68,
528
+ 68,
529
+ 36,
530
+ 9
531
+ ]), 0, 6)[1];
532
+ doct = rfse(/* @__PURE__ */ new u8([
533
+ 32,
534
+ 132,
535
+ 16,
536
+ 66,
537
+ 102,
538
+ 70,
539
+ 68,
540
+ 68,
541
+ 68,
542
+ 68,
543
+ 36,
544
+ 73,
545
+ 2
546
+ ]), 0, 5)[1];
547
+ b2bl = function(b, s) {
548
+ var len = b.length, bl = new i32(len);
549
+ for (var i = 0; i < len; ++i) {
550
+ bl[i] = s;
551
+ s += 1 << b[i];
552
+ }
553
+ return bl;
554
+ };
555
+ llb = /* @__PURE__ */ new u8((/* @__PURE__ */ new i32([
556
+ 0,
557
+ 0,
558
+ 0,
559
+ 0,
560
+ 16843009,
561
+ 50528770,
562
+ 134678020,
563
+ 202050057,
564
+ 269422093
565
+ ])).buffer, 0, 36);
566
+ llbl = /* @__PURE__ */ b2bl(llb, 0);
567
+ mlb = /* @__PURE__ */ new u8((/* @__PURE__ */ new i32([
568
+ 0,
569
+ 0,
570
+ 0,
571
+ 0,
572
+ 0,
573
+ 0,
574
+ 0,
575
+ 0,
576
+ 16843009,
577
+ 50528770,
578
+ 117769220,
579
+ 185207048,
580
+ 252579084,
581
+ 16
582
+ ])).buffer, 0, 53);
583
+ mlbl = /* @__PURE__ */ b2bl(mlb, 3);
584
+ dhu = function(dat, out, hu) {
585
+ var len = dat.length, ss = out.length, lb = dat[len - 1], msk = (1 << hu.b) - 1, eb = -hu.b;
586
+ if (!lb)
587
+ err(0);
588
+ var st = 0, btr = hu.b, pos = (len << 3) - 8 + msb(lb) - btr, i = -1;
589
+ for (; pos > eb && i < ss; ) {
590
+ var cbt = pos >> 3;
591
+ var val = (dat[cbt] | dat[cbt + 1] << 8 | dat[cbt + 2] << 16) >> (pos & 7);
592
+ st = (st << btr | val) & msk;
593
+ out[++i] = hu.s[st];
594
+ pos -= btr = hu.n[st];
595
+ }
596
+ if (pos != eb || i + 1 != ss)
597
+ err(0);
598
+ };
599
+ dhu4 = function(dat, out, hu) {
600
+ var bt = 6;
601
+ var ss = out.length, sz1 = ss + 3 >> 2, sz2 = sz1 << 1, sz3 = sz1 + sz2;
602
+ dhu(dat.subarray(bt, bt += dat[0] | dat[1] << 8), out.subarray(0, sz1), hu);
603
+ dhu(dat.subarray(bt, bt += dat[2] | dat[3] << 8), out.subarray(sz1, sz2), hu);
604
+ dhu(dat.subarray(bt, bt += dat[4] | dat[5] << 8), out.subarray(sz2, sz3), hu);
605
+ dhu(dat.subarray(bt), out.subarray(sz3), hu);
606
+ };
607
+ rzb = function(dat, st, out) {
608
+ var _a;
609
+ var bt = st.b;
610
+ var b0 = dat[bt], btype = b0 >> 1 & 3;
611
+ st.l = b0 & 1;
612
+ var sz = b0 >> 3 | dat[bt + 1] << 5 | dat[bt + 2] << 13;
613
+ var ebt = (bt += 3) + sz;
614
+ if (btype == 1) {
615
+ if (bt >= dat.length)
616
+ return;
617
+ st.b = bt + 1;
618
+ if (out) {
619
+ fill(out, dat[bt], st.y, st.y += sz);
620
+ return out;
621
+ }
622
+ return fill(new u8(sz), dat[bt]);
623
+ }
624
+ if (ebt > dat.length)
625
+ return;
626
+ if (btype == 0) {
627
+ st.b = ebt;
628
+ if (out) {
629
+ out.set(dat.subarray(bt, ebt), st.y);
630
+ st.y += sz;
631
+ return out;
632
+ }
633
+ return slc(dat, bt, ebt);
634
+ }
635
+ if (btype == 2) {
636
+ var b3 = dat[bt], lbt = b3 & 3, sf = b3 >> 2 & 3;
637
+ var lss = b3 >> 4, lcs = 0, s4 = 0;
638
+ if (lbt < 2) {
639
+ if (sf & 1)
640
+ lss |= dat[++bt] << 4 | (sf & 2 && dat[++bt] << 12);
641
+ else
642
+ lss = b3 >> 3;
643
+ } else {
644
+ s4 = sf;
645
+ if (sf < 2)
646
+ lss |= (dat[++bt] & 63) << 4, lcs = dat[bt] >> 6 | dat[++bt] << 2;
647
+ else if (sf == 2)
648
+ lss |= dat[++bt] << 4 | (dat[++bt] & 3) << 12, lcs = dat[bt] >> 2 | dat[++bt] << 6;
649
+ else
650
+ lss |= dat[++bt] << 4 | (dat[++bt] & 63) << 12, lcs = dat[bt] >> 6 | dat[++bt] << 2 | dat[++bt] << 10;
651
+ }
652
+ ++bt;
653
+ var buf = out ? out.subarray(st.y, st.y + st.m) : new u8(st.m);
654
+ var spl = buf.length - lss;
655
+ if (lbt == 0)
656
+ buf.set(dat.subarray(bt, bt += lss), spl);
657
+ else if (lbt == 1)
658
+ fill(buf, dat[bt++], spl);
659
+ else {
660
+ var hu = st.h;
661
+ if (lbt == 2) {
662
+ var hud = rhu(dat, bt);
663
+ lcs += bt - (bt = hud[0]);
664
+ st.h = hu = hud[1];
665
+ } else if (!hu)
666
+ err(0);
667
+ (s4 ? dhu4 : dhu)(dat.subarray(bt, bt += lcs), buf.subarray(spl), hu);
668
+ }
669
+ var ns = dat[bt++];
670
+ if (ns) {
671
+ if (ns == 255)
672
+ ns = (dat[bt++] | dat[bt++] << 8) + 32512;
673
+ else if (ns > 127)
674
+ ns = ns - 128 << 8 | dat[bt++];
675
+ var scm = dat[bt++];
676
+ if (scm & 3)
677
+ err(0);
678
+ var dts = [dmlt, doct, dllt];
679
+ for (var i = 2; i > -1; --i) {
680
+ var md = scm >> (i << 1) + 2 & 3;
681
+ if (md == 1) {
682
+ var rbuf = new u8([0, 0, dat[bt++]]);
683
+ dts[i] = {
684
+ s: rbuf.subarray(2, 3),
685
+ n: rbuf.subarray(0, 1),
686
+ t: new u16(rbuf.buffer, 0, 1),
687
+ b: 0
688
+ };
689
+ } else if (md == 2) {
690
+ _a = rfse(dat, bt, 9 - (i & 1)), bt = _a[0], dts[i] = _a[1];
691
+ } else if (md == 3) {
692
+ if (!st.t)
693
+ err(0);
694
+ dts[i] = st.t[i];
695
+ }
696
+ }
697
+ var _b = st.t = dts, mlt = _b[0], oct = _b[1], llt = _b[2];
698
+ var lb = dat[ebt - 1];
699
+ if (!lb)
700
+ err(0);
701
+ var spos = (ebt << 3) - 8 + msb(lb) - llt.b, cbt = spos >> 3, oubt = 0;
702
+ var lst = (dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << llt.b) - 1;
703
+ cbt = (spos -= oct.b) >> 3;
704
+ var ost = (dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << oct.b) - 1;
705
+ cbt = (spos -= mlt.b) >> 3;
706
+ var mst = (dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << mlt.b) - 1;
707
+ for (++ns; --ns; ) {
708
+ var llc = llt.s[lst];
709
+ var lbtr = llt.n[lst];
710
+ var mlc = mlt.s[mst];
711
+ var mbtr = mlt.n[mst];
712
+ var ofc = oct.s[ost];
713
+ var obtr = oct.n[ost];
714
+ cbt = (spos -= ofc) >> 3;
715
+ var ofp = 1 << ofc;
716
+ var off = ofp + ((dat[cbt] | dat[cbt + 1] << 8 | dat[cbt + 2] << 16 | dat[cbt + 3] << 24) >>> (spos & 7) & ofp - 1);
717
+ cbt = (spos -= mlb[mlc]) >> 3;
718
+ var ml = mlbl[mlc] + ((dat[cbt] | dat[cbt + 1] << 8 | dat[cbt + 2] << 16) >> (spos & 7) & (1 << mlb[mlc]) - 1);
719
+ cbt = (spos -= llb[llc]) >> 3;
720
+ var ll = llbl[llc] + ((dat[cbt] | dat[cbt + 1] << 8 | dat[cbt + 2] << 16) >> (spos & 7) & (1 << llb[llc]) - 1);
721
+ cbt = (spos -= lbtr) >> 3;
722
+ lst = llt.t[lst] + ((dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << lbtr) - 1);
723
+ cbt = (spos -= mbtr) >> 3;
724
+ mst = mlt.t[mst] + ((dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << mbtr) - 1);
725
+ cbt = (spos -= obtr) >> 3;
726
+ ost = oct.t[ost] + ((dat[cbt] | dat[cbt + 1] << 8) >> (spos & 7) & (1 << obtr) - 1);
727
+ if (off > 3) {
728
+ st.o[2] = st.o[1];
729
+ st.o[1] = st.o[0];
730
+ st.o[0] = off -= 3;
731
+ } else {
732
+ var idx = off - (ll != 0);
733
+ if (idx) {
734
+ off = idx == 3 ? st.o[0] - 1 : st.o[idx];
735
+ if (idx > 1)
736
+ st.o[2] = st.o[1];
737
+ st.o[1] = st.o[0];
738
+ st.o[0] = off;
739
+ } else
740
+ off = st.o[0];
741
+ }
742
+ for (var i = 0; i < ll; ++i) {
743
+ buf[oubt + i] = buf[spl + i];
744
+ }
745
+ oubt += ll, spl += ll;
746
+ var stin = oubt - off;
747
+ if (stin < 0) {
748
+ var len = -stin;
749
+ var bs = st.e + stin;
750
+ if (len > ml)
751
+ len = ml;
752
+ for (var i = 0; i < len; ++i) {
753
+ buf[oubt + i] = st.w[bs + i];
754
+ }
755
+ oubt += len, ml -= len, stin = 0;
756
+ }
757
+ for (var i = 0; i < ml; ++i) {
758
+ buf[oubt + i] = buf[stin + i];
759
+ }
760
+ oubt += ml;
761
+ }
762
+ if (oubt != spl) {
763
+ while (spl < buf.length) {
764
+ buf[oubt++] = buf[spl++];
765
+ }
766
+ } else
767
+ oubt = buf.length;
768
+ if (out)
769
+ st.y += oubt;
770
+ else
771
+ buf = slc(buf, 0, oubt);
772
+ } else if (out) {
773
+ st.y += lss;
774
+ if (spl) {
775
+ for (var i = 0; i < lss; ++i) {
776
+ buf[i] = buf[spl + i];
777
+ }
778
+ }
779
+ } else if (spl)
780
+ buf = slc(buf, spl);
781
+ st.b = ebt;
782
+ return buf;
783
+ }
784
+ err(2);
785
+ };
786
+ cct = function(bufs, ol) {
787
+ if (bufs.length == 1)
788
+ return bufs[0];
789
+ var buf = new u8(ol);
790
+ for (var i = 0, b = 0; i < bufs.length; ++i) {
791
+ var chk = bufs[i];
792
+ buf.set(chk, b);
793
+ b += chk.length;
794
+ }
795
+ return buf;
796
+ };
797
+ Decompress = /* @__PURE__ */ (function() {
798
+ function Decompress2(ondata) {
799
+ this.ondata = ondata;
800
+ this.c = [];
801
+ this.l = 0;
802
+ this.z = 0;
803
+ }
804
+ Decompress2.prototype.push = function(chunk, final) {
805
+ if (typeof this.s == "number") {
806
+ var sub = Math.min(chunk.length, this.s);
807
+ chunk = chunk.subarray(sub);
808
+ this.s -= sub;
809
+ }
810
+ var sl = chunk.length;
811
+ var ncs = sl + this.l;
812
+ if (!this.s) {
813
+ if (final) {
814
+ if (!ncs) {
815
+ this.ondata(new u8(0), true);
816
+ return;
817
+ }
818
+ if (ncs < 5)
819
+ err(5);
820
+ } else if (ncs < 18) {
821
+ this.c.push(chunk);
822
+ this.l = ncs;
823
+ return;
824
+ }
825
+ if (this.l) {
826
+ this.c.push(chunk);
827
+ chunk = cct(this.c, ncs);
828
+ this.c = [];
829
+ this.l = 0;
830
+ }
831
+ if (typeof (this.s = rzfh(chunk)) == "number")
832
+ return this.push(chunk, final);
833
+ }
834
+ if (typeof this.s != "number") {
835
+ if (ncs < (this.z || 3)) {
836
+ if (final)
837
+ err(5);
838
+ this.c.push(chunk);
839
+ this.l = ncs;
840
+ return;
841
+ }
842
+ if (this.l) {
843
+ this.c.push(chunk);
844
+ chunk = cct(this.c, ncs);
845
+ this.c = [];
846
+ this.l = 0;
847
+ }
848
+ if (!this.z && ncs < (this.z = chunk[this.s.b] & 2 ? 4 : 3 + (chunk[this.s.b] >> 3 | chunk[this.s.b + 1] << 5 | chunk[this.s.b + 2] << 13))) {
849
+ if (final)
850
+ err(5);
851
+ this.c.push(chunk);
852
+ this.l = ncs;
853
+ return;
854
+ } else
855
+ this.z = 0;
856
+ for (; ; ) {
857
+ var blk = rzb(chunk, this.s);
858
+ if (!blk) {
859
+ if (final)
860
+ err(5);
861
+ var adc = chunk.subarray(this.s.b);
862
+ this.s.b = 0;
863
+ this.c.push(adc), this.l += adc.length;
864
+ return;
865
+ } else {
866
+ this.ondata(blk, false);
867
+ cpw(this.s.w, 0, blk.length);
868
+ this.s.w.set(blk, this.s.w.length - blk.length);
869
+ }
870
+ if (this.s.l) {
871
+ var rest = chunk.subarray(this.s.b);
872
+ this.s = this.s.c * 4;
873
+ this.push(rest, final);
874
+ return;
875
+ }
876
+ }
877
+ } else if (final)
878
+ err(5);
879
+ };
880
+ return Decompress2;
881
+ })();
882
+ }
883
+ });
884
+
160
885
  // src/cli.ts
161
886
  import { spawn as spawn2, spawnSync } from "node:child_process";
162
- import { mkdir as mkdir5, open, rm, stat as stat12, writeFile as writeFile4 } from "node:fs/promises";
163
- import os9 from "node:os";
164
- import path21 from "node:path";
887
+ import { mkdir as mkdir5, open, rm, stat as stat13, writeFile as writeFile4 } from "node:fs/promises";
888
+ import os10 from "node:os";
889
+ import path23 from "node:path";
165
890
  import { fileURLToPath } from "node:url";
166
891
 
167
892
  // ../shared/src/index.ts
@@ -191,13 +916,15 @@ var TELEMETRY_EVENT_TYPES = [
191
916
  "model.usage",
192
917
  "permission.requested",
193
918
  "permission.resolved",
919
+ "permission.granted",
920
+ "permission.denied",
194
921
  "context.compacted",
195
922
  "test.completed",
196
923
  "git.changed",
197
924
  "agent.operation"
198
925
  ];
199
926
  var FILE_ACTIVITY_OPERATIONS = ["read", "search", "create", "write", "edit", "delete"];
200
- var BACKFILL_SOURCE_IDS = ["codex", "claude-code", "claude-cowork", "copilot", "opencode", "pi", "agy", "codebuddy", "qoder", "qoder-cn", "workbuddy", "zcode"];
927
+ var BACKFILL_SOURCE_IDS = ["codex", "claude-code", "claude-cowork", "copilot", "opencode", "pi", "agy", "codebuddy", "qoder", "qoder-cn", "workbuddy", "zcode", "grok-build", "zed"];
201
928
  function createWorkspaceId(input) {
202
929
  const basis = input.repoUrl || input.repoRoot || input.projectName || "unknown";
203
930
  return `workspace_${fnv1a(basis)}`;
@@ -1201,7 +1928,7 @@ function countTextLines(text) {
1201
1928
  }
1202
1929
 
1203
1930
  // src/lib/constants.ts
1204
- var PACKAGE_VERSION = true ? "0.1.25" : "0.1.1";
1931
+ var PACKAGE_VERSION = true ? "0.1.27" : "0.1.1";
1205
1932
  var DEFAULT_API_URL = "http://121.196.224.82:3001";
1206
1933
  var DEFAULT_BACKFILL_BATCH_SIZE = 50;
1207
1934
  var DEFAULT_BACKFILL_BATCH_BYTES = 800 * 1024;
@@ -1226,6 +1953,12 @@ function objectField(object, key) {
1226
1953
  }
1227
1954
  return object[key];
1228
1955
  }
1956
+ function arrayField(object, key) {
1957
+ if (!isPlainObject(object) || !Array.isArray(object[key])) {
1958
+ return [];
1959
+ }
1960
+ return object[key];
1961
+ }
1229
1962
  function isPlainObject(value) {
1230
1963
  return value !== null && typeof value === "object" && !Array.isArray(value);
1231
1964
  }
@@ -2905,7 +3638,7 @@ function fileActivitiesFromClaudeToolUse(tool, input, ts, cwd) {
2905
3638
  const metrics = fileMetricsFromClaudeToolInput(tool, input);
2906
3639
  addResolvedPathActivity(changes, filePath, operation, ts, cwd, workdir, metrics);
2907
3640
  }
2908
- for (const edit of arrayField(input, "edits")) {
3641
+ for (const edit of arrayField2(input, "edits")) {
2909
3642
  if (!isPlainObject(edit)) {
2910
3643
  continue;
2911
3644
  }
@@ -2949,17 +3682,17 @@ function fileMetricsFromClaudeToolInput(tool, input) {
2949
3682
  }
2950
3683
  return {};
2951
3684
  }
2952
- function arrayField(object, key) {
3685
+ function arrayField2(object, key) {
2953
3686
  if (!isPlainObject(object) || !Array.isArray(object[key])) {
2954
3687
  return [];
2955
3688
  }
2956
3689
  return object[key];
2957
3690
  }
2958
3691
  function claudeToolUseItems(message) {
2959
- return arrayField(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
3692
+ return arrayField2(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
2960
3693
  }
2961
3694
  function claudeToolResultItems(message) {
2962
- return arrayField(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
3695
+ return arrayField2(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
2963
3696
  }
2964
3697
  function isClaudeToolResultMessage(message) {
2965
3698
  return claudeToolResultItems(message).length > 0;
@@ -4029,8 +4762,8 @@ async function codebuddyBackfillFiles(sourceRoot, home, env) {
4029
4762
  }
4030
4763
  const filePath = path9.join(traceDir, entry);
4031
4764
  try {
4032
- const stat13 = await import("node:fs/promises").then((fs) => fs.stat(filePath));
4033
- files.push({ path: filePath, modifiedAt: stat13.mtime.toISOString() });
4765
+ const stat14 = await import("node:fs/promises").then((fs) => fs.stat(filePath));
4766
+ files.push({ path: filePath, modifiedAt: stat14.mtime.toISOString() });
4034
4767
  } catch {
4035
4768
  }
4036
4769
  }
@@ -4615,7 +5348,7 @@ function fileActivitiesFromFunctionCall(payload, payloadType, ts, cwd) {
4615
5348
  for (const key of ["file_path", "path", "notebook_path"]) {
4616
5349
  addResolvedPathActivity(changes, stringField(args, key), operation, ts, cwd, workdir);
4617
5350
  }
4618
- for (const file of arrayField2(args, "files")) {
5351
+ for (const file of arrayField3(args, "files")) {
4619
5352
  if (typeof file === "string") {
4620
5353
  addResolvedPathActivity(changes, file, operation, ts, cwd, workdir);
4621
5354
  }
@@ -4628,7 +5361,7 @@ function fileActivitiesFromFunctionCall(payload, payloadType, ts, cwd) {
4628
5361
  }
4629
5362
  return [...changes.values()];
4630
5363
  }
4631
- function arrayField2(object, key) {
5364
+ function arrayField3(object, key) {
4632
5365
  if (!isPlainObject(object) || !Array.isArray(object[key])) {
4633
5366
  return [];
4634
5367
  }
@@ -5058,95 +5791,583 @@ function createCopilotAdapter() {
5058
5791
  };
5059
5792
  }
5060
5793
 
5061
- // src/adapters/opencode.ts
5062
- import os6 from "node:os";
5794
+ // src/adapters/grok-build.ts
5795
+ import { readdir as readdir6, readFile as readFile8, stat as stat7 } from "node:fs/promises";
5063
5796
  import path13 from "node:path";
5064
- async function parseOpenCodeSessionFile(dbPath, options) {
5065
- const { DatabaseSync } = await import("node:sqlite");
5066
- if (!dbPath.endsWith(".db")) {
5797
+ init_fs();
5798
+ var SOURCE_ID = "grok-build";
5799
+ var AGENT_NAME = "grok-build";
5800
+ var HOOK_COMMAND = `vibetime hook --agent ${SOURCE_ID}`;
5801
+ function grokHome(home, env) {
5802
+ const override = env?.GROK_HOME;
5803
+ if (override && override.trim()) {
5804
+ return path13.resolve(override);
5805
+ }
5806
+ return path13.join(home, ".grok");
5807
+ }
5808
+ function grokHooksPath(home, env) {
5809
+ return path13.join(grokHome(home, env), "hooks", "vibetime.json");
5810
+ }
5811
+ function grokSessionsDir(home, env) {
5812
+ return path13.join(grokHome(home, env), "sessions");
5813
+ }
5814
+ async function grokBackfillFiles(sourceRoot, home, env) {
5815
+ const root = sourceRoot || grokSessionsDir(home, env);
5816
+ const files = [];
5817
+ async function walk(dir) {
5818
+ let entries;
5819
+ try {
5820
+ entries = await readdir6(dir, { withFileTypes: true });
5821
+ } catch {
5822
+ return;
5823
+ }
5824
+ for (const entry of entries) {
5825
+ const entryPath = path13.join(dir, entry.name);
5826
+ if (entry.isDirectory()) {
5827
+ await walk(entryPath);
5828
+ continue;
5829
+ }
5830
+ if (!entry.isFile() || entry.name !== "summary.json") {
5831
+ continue;
5832
+ }
5833
+ try {
5834
+ const info = await stat7(entryPath);
5835
+ files.push({ path: entryPath, modifiedAt: info.mtime.toISOString() });
5836
+ } catch {
5837
+ }
5838
+ }
5839
+ }
5840
+ await walk(root);
5841
+ return files.sort((a, b) => a.path.localeCompare(b.path));
5842
+ }
5843
+ async function parseGrokSessionFile(filePath, options) {
5844
+ const sessionDir = resolveSessionDir(filePath);
5845
+ if (!sessionDir) {
5067
5846
  return [];
5068
5847
  }
5069
- const db = new DatabaseSync(dbPath, { readOnly: true });
5848
+ const summaryPath = path13.join(sessionDir, "summary.json");
5849
+ const eventsPath = path13.join(sessionDir, "events.jsonl");
5850
+ const signalsPath = path13.join(sessionDir, "signals.json");
5851
+ const updatesPath = path13.join(sessionDir, "updates.jsonl");
5852
+ const summary = await readJsonIfExists(summaryPath);
5853
+ if (!isPlainObject(summary)) {
5854
+ return [];
5855
+ }
5856
+ const info = objectField(summary, "info");
5857
+ const sessionId = stringField(info, "id") || path13.basename(sessionDir);
5858
+ const cwd = stringField(info, "cwd");
5859
+ const project = cwd ? path13.basename(cwd) : void 0;
5860
+ const workspaceId = createWorkspaceId({ projectName: project, repoRoot: cwd });
5861
+ const model = stringField(summary, "current_model_id");
5862
+ const createdAt = timestampFrom(summary.created_at) || timestampFrom(summary.createdAt);
5863
+ const updatedAt = timestampFrom(summary.updated_at) || timestampFrom(summary.last_active_at) || timestampFrom(summary.updatedAt) || createdAt;
5864
+ if (!createdAt) {
5865
+ return [];
5866
+ }
5867
+ const sourcePathHash = `sha256:${createStableHash(summaryPath)}`;
5868
+ const toolInputs = await loadToolInputsFromUpdates(updatesPath);
5070
5869
  const events = [];
5870
+ const push = (event, lineNumber2, topType, payloadType) => {
5871
+ const validated = validateCanonicalEvent(event);
5872
+ if (!validated.valid) {
5873
+ return;
5874
+ }
5875
+ events.push(withBackfillRefs(event, {
5876
+ filePath: summaryPath,
5877
+ sourcePathHash,
5878
+ lineNumber: lineNumber2,
5879
+ topType: topType || "session",
5880
+ payloadType: payloadType || event.type,
5881
+ options
5882
+ }));
5883
+ };
5884
+ const base = (partial) => ({
5885
+ schemaVersion: AGENT_TIME_SCHEMA_VERSION,
5886
+ source: SOURCE_ID,
5887
+ agent: AGENT_NAME,
5888
+ workspaceId,
5889
+ project,
5890
+ cwd,
5891
+ model,
5892
+ sessionId,
5893
+ ...partial
5894
+ });
5895
+ push(base({
5896
+ ts: createdAt,
5897
+ type: "session.started",
5898
+ confidence: "exact",
5899
+ refs: stringRefs({ sourceId: `${sessionId}:started` })
5900
+ }), 0, "summary", "session.started");
5901
+ let currentTurnId;
5902
+ let currentTurnStartedAt;
5903
+ let lineNumber = 0;
5904
+ const pendingTools = /* @__PURE__ */ new Map();
5905
+ let eventsText = "";
5071
5906
  try {
5072
- const sessionCols = new Set(
5073
- db.prepare("PRAGMA table_info(session)").all().map((row) => row.name)
5074
- );
5075
- const hasDirectory = sessionCols.has("directory");
5076
- const hasPath = sessionCols.has("path");
5077
- const hasArchived = sessionCols.has("time_archived");
5078
- const selectCols = ["id", "title", "time_created"];
5079
- if (hasDirectory) {
5080
- selectCols.push("directory");
5907
+ eventsText = await readFile8(eventsPath, "utf8");
5908
+ } catch {
5909
+ }
5910
+ const lines = eventsText.split("\n").filter(Boolean);
5911
+ for (const [index, line] of lines.entries()) {
5912
+ lineNumber = index + 1;
5913
+ const raw = parseJsonLine(line);
5914
+ if (!raw) {
5915
+ continue;
5081
5916
  }
5082
- if (hasPath) {
5083
- selectCols.push("path");
5917
+ const type = stringField(raw, "type");
5918
+ const ts = timestampFrom(raw.ts) || timestampFrom(raw.timestamp);
5919
+ if (!type || !ts) {
5920
+ continue;
5084
5921
  }
5085
- if (hasArchived) {
5086
- selectCols.push("time_archived");
5922
+ if (type === "turn_started") {
5923
+ const turnNumber = numberField(raw, "turn_number");
5924
+ currentTurnId = turnNumber !== void 0 ? `turn_${turnNumber}` : `turn_${createStableHash([sessionId, lineNumber]).slice(0, 24)}`;
5925
+ currentTurnStartedAt = ts;
5926
+ const turnModel = stringField(raw, "model_id") || model;
5927
+ push(base({
5928
+ ts,
5929
+ type: "turn.started",
5930
+ turnId: currentTurnId,
5931
+ model: turnModel,
5932
+ confidence: "exact",
5933
+ refs: stringRefs({ sourceId: `${sessionId}:${currentTurnId}:started` })
5934
+ }), lineNumber, type, "turn.started");
5935
+ continue;
5087
5936
  }
5088
- const sessions = db.prepare(
5089
- `SELECT ${selectCols.join(", ")} FROM session WHERE time_created IS NOT NULL ORDER BY time_created`
5090
- ).all();
5091
- for (const session of sessions) {
5092
- const sessionId = session.id;
5093
- const cwd = session.directory || session.path || void 0;
5094
- const project = cwd ? path13.basename(cwd) : void 0;
5095
- const sessionTs = msToIso(session.time_created);
5096
- events.push(baseOpenCodeEvent({
5097
- ts: sessionTs,
5098
- type: "session.started",
5099
- sessionId,
5100
- cwd,
5101
- project,
5102
- operation: "session start"
5103
- }));
5104
- const messages = db.prepare(
5105
- "SELECT id, data FROM message WHERE session_id = ? ORDER BY time_created"
5106
- ).all(sessionId);
5107
- let currentTurnId;
5108
- let currentProvider;
5109
- let turnTs;
5110
- let reasoningEffort;
5111
- const modelSwitchedEvents = db.prepare(
5112
- "SELECT data FROM event WHERE aggregate_id = ? AND type = 'session.next.model.switched.1' ORDER BY seq"
5113
- ).all(sessionId);
5114
- for (const evt of modelSwitchedEvents) {
5115
- try {
5116
- const evtData = JSON.parse(evt.data);
5117
- const variant = isPlainObject(evtData) ? stringField(evtData.model || evtData, "variant") : void 0;
5118
- if (variant && variant !== "default") {
5119
- reasoningEffort = variant;
5120
- }
5121
- } catch {
5937
+ if (type === "turn_ended") {
5938
+ const turnId = currentTurnId;
5939
+ const outcome = stringField(raw, "outcome");
5940
+ const success = outcome !== "error" && outcome !== "failed" && outcome !== "cancelled";
5941
+ const durationMs = durationMsBetween(currentTurnStartedAt, ts);
5942
+ push(base({
5943
+ ts,
5944
+ type: success ? "turn.completed" : "turn.failed",
5945
+ turnId,
5946
+ success,
5947
+ confidence: "exact",
5948
+ metrics: durationMs !== void 0 ? { durationMs } : void 0,
5949
+ refs: stringRefs({
5950
+ sourceId: `${sessionId}:${turnId || "turn"}:ended`,
5951
+ outcome
5952
+ })
5953
+ }), lineNumber, type, "turn.ended");
5954
+ currentTurnId = void 0;
5955
+ currentTurnStartedAt = void 0;
5956
+ continue;
5957
+ }
5958
+ if (type === "tool_started" || type === "mcp_tool_call_started") {
5959
+ const toolName = type === "mcp_tool_call_started" ? mcpToolName(raw) : stringField(raw, "tool_name") || "unknown";
5960
+ const toolId = stringField(raw, "call_id") || `${sessionId}:tool:${lineNumber}:${toolName}`;
5961
+ pendingTools.set(toolId, {
5962
+ id: toolId,
5963
+ name: toolName,
5964
+ startedAt: ts,
5965
+ lineNumber,
5966
+ turnId: currentTurnId
5967
+ });
5968
+ const knownInput = toolInputs.get(toolId);
5969
+ const fileActivities = fileActivitiesFromTool(
5970
+ toolName,
5971
+ knownInput?.input || {},
5972
+ ts,
5973
+ cwd
5974
+ );
5975
+ push(base({
5976
+ ts,
5977
+ type: "tool.started",
5978
+ turnId: currentTurnId,
5979
+ tool: toolName,
5980
+ operation: `${toolName} started`,
5981
+ confidence: "exact",
5982
+ fileActivities: fileActivities.length > 0 ? fileActivities : void 0,
5983
+ refs: stringRefs({ sourceId: `${toolId}:started` })
5984
+ }), lineNumber, type, "tool.started");
5985
+ if (isShellTool(toolName)) {
5986
+ const command = stringField(knownInput?.input || {}, "command");
5987
+ if (command) {
5988
+ push(base({
5989
+ ts,
5990
+ type: "command.started",
5991
+ turnId: currentTurnId,
5992
+ tool: toolName,
5993
+ operation: "command started",
5994
+ confidence: "derived",
5995
+ refs: stringRefs({
5996
+ sourceId: `${toolId}:command:started`,
5997
+ commandHash: `sha256:${createStableHash(command)}`
5998
+ })
5999
+ }), lineNumber, type, "command.started");
5122
6000
  }
5123
6001
  }
5124
- for (const msg of messages) {
5125
- let info;
5126
- try {
5127
- info = JSON.parse(msg.data);
5128
- } catch {
5129
- continue;
5130
- }
5131
- if (!isPlainObject(info)) {
5132
- continue;
5133
- }
5134
- const role = stringField(info, "role");
5135
- const timeObj = objectField(info, "time");
5136
- const timeCreated = numberField(timeObj, "created");
5137
- if (!role || !timeCreated) {
5138
- continue;
5139
- }
5140
- if (role === "user") {
5141
- currentTurnId = `turn_${createStableHash([sessionId, msg.id]).slice(0, 24)}`;
5142
- turnTs = msToIso(timeCreated);
5143
- const userAgent = stringField(info, "agent") || "opencode";
5144
- const modelObj = objectField(info, "model");
5145
- const model = modelObj ? stringField(modelObj, "modelID") : void 0;
5146
- currentProvider = modelObj ? stringField(modelObj, "providerID") : void 0;
5147
- events.push(baseOpenCodeEvent({
5148
- ts: turnTs,
5149
- type: "turn.started",
6002
+ continue;
6003
+ }
6004
+ if (type === "tool_completed" || type === "mcp_tool_call_completed") {
6005
+ const toolName = type === "mcp_tool_call_completed" ? mcpToolName(raw) : stringField(raw, "tool_name") || "unknown";
6006
+ const toolId = stringField(raw, "call_id") || findPendingToolId(pendingTools, toolName) || `${sessionId}:tool:${lineNumber}:${toolName}`;
6007
+ const pending = pendingTools.get(toolId);
6008
+ const durationMs = numberField(raw, "duration_ms") ?? durationMsBetween(pending?.startedAt, ts);
6009
+ const outcome = stringField(raw, "outcome");
6010
+ const success = raw.success !== false && outcome !== "error" && outcome !== "failed" && !raw.is_timeout;
6011
+ push(base({
6012
+ ts,
6013
+ type: success ? "tool.completed" : "tool.failed",
6014
+ turnId: pending?.turnId || currentTurnId,
6015
+ tool: pending?.name || toolName,
6016
+ operation: `${pending?.name || toolName} completed`,
6017
+ success,
6018
+ confidence: "exact",
6019
+ metrics: {
6020
+ toolCalls: 1,
6021
+ toolDurationMs: durationMs,
6022
+ durationMs
6023
+ },
6024
+ refs: stringRefs({ sourceId: `${toolId}:completed` })
6025
+ }), lineNumber, type, "tool.completed");
6026
+ if (isShellTool(pending?.name || toolName)) {
6027
+ push(base({
6028
+ ts,
6029
+ type: success ? "command.completed" : "command.failed",
6030
+ turnId: pending?.turnId || currentTurnId,
6031
+ tool: pending?.name || toolName,
6032
+ operation: "command completed",
6033
+ success,
6034
+ confidence: "derived",
6035
+ metrics: {
6036
+ commandCalls: 1,
6037
+ commandDurationMs: durationMs,
6038
+ durationMs
6039
+ },
6040
+ refs: stringRefs({ sourceId: `${toolId}:command:completed` })
6041
+ }), lineNumber, type, "command.completed");
6042
+ }
6043
+ pendingTools.delete(toolId);
6044
+ continue;
6045
+ }
6046
+ if (type === "permission_resolved") {
6047
+ const toolName = stringField(raw, "tool_name");
6048
+ const decision = stringField(raw, "decision") || stringField(raw, "outcome");
6049
+ const allowed = decision !== "deny" && decision !== "denied" && decision !== "reject";
6050
+ push(base({
6051
+ ts,
6052
+ type: allowed ? "permission.granted" : "permission.denied",
6053
+ turnId: currentTurnId,
6054
+ tool: toolName,
6055
+ success: allowed,
6056
+ confidence: "partial",
6057
+ refs: stringRefs({
6058
+ sourceId: `${sessionId}:permission:${lineNumber}`,
6059
+ decision
6060
+ })
6061
+ }), lineNumber, type, "permission");
6062
+ }
6063
+ }
6064
+ const signals = await readJsonIfExists(signalsPath);
6065
+ if (isPlainObject(signals) && updatedAt) {
6066
+ const metrics = metricsFromSignals(signals);
6067
+ if (metrics) {
6068
+ push(base({
6069
+ ts: updatedAt,
6070
+ type: "model.usage",
6071
+ model: stringField(signals, "primaryModelId") || model,
6072
+ confidence: "partial",
6073
+ metrics,
6074
+ refs: stringRefs({ sourceId: `${sessionId}:usage:signals` })
6075
+ }), lineNumber + 1, "signals", "model.usage");
6076
+ }
6077
+ }
6078
+ if (updatedAt) {
6079
+ push(base({
6080
+ ts: updatedAt,
6081
+ type: "session.ended",
6082
+ confidence: "derived",
6083
+ refs: stringRefs({ sourceId: `${sessionId}:ended` })
6084
+ }), lineNumber + 2, "summary", "session.ended");
6085
+ }
6086
+ return events;
6087
+ }
6088
+ function resolveSessionDir(filePath) {
6089
+ const base = path13.basename(filePath);
6090
+ if (base === "summary.json" || base === "events.jsonl" || base === "signals.json") {
6091
+ return path13.dirname(filePath);
6092
+ }
6093
+ if (base.match(/^[0-9a-f]{8}-[0-9a-f-]{27,}$/i)) {
6094
+ return filePath;
6095
+ }
6096
+ return void 0;
6097
+ }
6098
+ function mcpToolName(raw) {
6099
+ const server = stringField(raw, "server_name");
6100
+ const tool = stringField(raw, "tool_name");
6101
+ if (server && tool) {
6102
+ return `${server}__${tool}`;
6103
+ }
6104
+ return tool || server || "mcp_tool";
6105
+ }
6106
+ function findPendingToolId(pending, toolName) {
6107
+ for (const [id, item] of pending) {
6108
+ if (item.name === toolName) {
6109
+ return id;
6110
+ }
6111
+ }
6112
+ return void 0;
6113
+ }
6114
+ function isShellTool(name) {
6115
+ if (!name) {
6116
+ return false;
6117
+ }
6118
+ const lower = name.toLowerCase();
6119
+ return lower === "run_terminal_command" || lower === "bash" || lower === "shell" || lower.endsWith("__run_terminal_command");
6120
+ }
6121
+ function fileActivitiesFromTool(toolName, input, ts, cwd) {
6122
+ const lower = toolName.toLowerCase();
6123
+ if (isShellTool(toolName)) {
6124
+ const command = stringField(input, "command");
6125
+ if (command) {
6126
+ return fileActivitiesFromShellCommand(command, ts, cwd, cwd);
6127
+ }
6128
+ return [];
6129
+ }
6130
+ if (lower === "read_file" || lower.endsWith("__read_file")) {
6131
+ const target = stringField(input, "target_file") || stringField(input, "path");
6132
+ if (!target) {
6133
+ return [];
6134
+ }
6135
+ return [{
6136
+ ts,
6137
+ path: displayPath(target, cwd),
6138
+ operation: "read",
6139
+ confidence: "exact"
6140
+ }];
6141
+ }
6142
+ if (lower === "search_replace" || lower === "write" || lower.endsWith("__search_replace") || lower.endsWith("__write")) {
6143
+ const target = stringField(input, "file_path") || stringField(input, "target_file") || stringField(input, "path");
6144
+ if (!target) {
6145
+ return [];
6146
+ }
6147
+ return [{
6148
+ ts,
6149
+ path: displayPath(target, cwd),
6150
+ operation: "edit",
6151
+ confidence: "exact"
6152
+ }];
6153
+ }
6154
+ return [];
6155
+ }
6156
+ function displayPath(filePath, cwd) {
6157
+ if (!cwd || !path13.isAbsolute(filePath)) {
6158
+ return filePath;
6159
+ }
6160
+ const relative = path13.relative(cwd, filePath);
6161
+ return relative && !relative.startsWith("..") && !path13.isAbsolute(relative) ? relative : filePath;
6162
+ }
6163
+ async function loadToolInputsFromUpdates(updatesPath) {
6164
+ const map = /* @__PURE__ */ new Map();
6165
+ let text = "";
6166
+ try {
6167
+ text = await readFile8(updatesPath, "utf8");
6168
+ } catch {
6169
+ return map;
6170
+ }
6171
+ for (const line of text.split("\n")) {
6172
+ if (!line.trim()) {
6173
+ continue;
6174
+ }
6175
+ const raw = parseJsonLine(line);
6176
+ if (!raw) {
6177
+ continue;
6178
+ }
6179
+ const params = objectField(raw, "params");
6180
+ const update = objectField(params, "update");
6181
+ const sessionUpdate = stringField(update, "sessionUpdate");
6182
+ if (sessionUpdate !== "tool_call" && sessionUpdate !== "tool_call_update") {
6183
+ continue;
6184
+ }
6185
+ const toolCallId = stringField(update, "toolCallId");
6186
+ if (!toolCallId) {
6187
+ continue;
6188
+ }
6189
+ const meta = objectField(update, "_meta");
6190
+ const toolMeta = objectField(meta, "x.ai/tool");
6191
+ const name = stringField(toolMeta, "name") || stringField(update, "title") || "unknown";
6192
+ const rawInput = objectField(update, "rawInput");
6193
+ const nestedInput = objectField(toolMeta, "input");
6194
+ const input = Object.keys(rawInput).length > 0 ? rawInput : nestedInput;
6195
+ if (!map.has(toolCallId) || Object.keys(input).length > 0) {
6196
+ map.set(toolCallId, { name, input });
6197
+ }
6198
+ }
6199
+ return map;
6200
+ }
6201
+ function metricsFromSignals(signals) {
6202
+ const contextTokens = numberField(signals, "contextTokensUsed");
6203
+ const toolCallCount = numberField(signals, "toolCallCount");
6204
+ const turnCount = numberField(signals, "turnCount");
6205
+ const durationSec = numberField(signals, "sessionDurationSeconds");
6206
+ const linesAdded = numberField(signals, "agentLinesAdded");
6207
+ const linesRemoved = numberField(signals, "agentLinesRemoved");
6208
+ if (contextTokens === void 0 && toolCallCount === void 0 && turnCount === void 0 && durationSec === void 0) {
6209
+ return void 0;
6210
+ }
6211
+ const metrics = {};
6212
+ if (contextTokens !== void 0 && contextTokens > 0) {
6213
+ metrics.tokensTotal = contextTokens;
6214
+ metrics.tokensInput = contextTokens;
6215
+ }
6216
+ if (toolCallCount !== void 0) {
6217
+ metrics.toolCalls = toolCallCount;
6218
+ }
6219
+ if (turnCount !== void 0) {
6220
+ metrics.modelCalls = turnCount;
6221
+ }
6222
+ if (durationSec !== void 0) {
6223
+ metrics.durationMs = Math.round(durationSec * 1e3);
6224
+ }
6225
+ if (linesAdded !== void 0) {
6226
+ metrics.linesAdded = linesAdded;
6227
+ }
6228
+ if (linesRemoved !== void 0) {
6229
+ metrics.linesRemoved = linesRemoved;
6230
+ }
6231
+ return metrics;
6232
+ }
6233
+ var grokHandler = (msg) => hookHandler(SOURCE_ID, msg);
6234
+ function hookConfig5() {
6235
+ const anyTool = [{ matcher: ".*", hooks: [grokHandler("Reporting tool activity")] }];
6236
+ return {
6237
+ hooks: {
6238
+ SessionStart: [{ hooks: [grokHandler("Reporting session start")] }],
6239
+ SessionEnd: [{ hooks: [grokHandler("Reporting session end")] }],
6240
+ UserPromptSubmit: [{ hooks: [grokHandler("Reporting prompt activity")] }],
6241
+ PreToolUse: anyTool,
6242
+ PostToolUse: anyTool,
6243
+ PostToolUseFailure: anyTool,
6244
+ PermissionDenied: anyTool,
6245
+ SubagentStart: [{ hooks: [grokHandler("Reporting subagent start")] }],
6246
+ SubagentStop: [{ hooks: [grokHandler("Reporting subagent completion")] }],
6247
+ Stop: [{ hooks: [grokHandler("Reporting turn completion")] }],
6248
+ StopFailure: [{ hooks: [grokHandler("Reporting turn failure")] }],
6249
+ PostCompact: [{ hooks: [grokHandler("Reporting context compaction")] }]
6250
+ }
6251
+ };
6252
+ }
6253
+ function createGrokBuildAdapter() {
6254
+ return {
6255
+ id: SOURCE_ID,
6256
+ label: "Grok Build",
6257
+ agentName: AGENT_NAME,
6258
+ kind: "agent",
6259
+ detectPath(home, env) {
6260
+ return grokHome(home, env);
6261
+ },
6262
+ installedPath(home, env) {
6263
+ return grokHooksPath(home, env);
6264
+ },
6265
+ async isInstalled(home, env) {
6266
+ return isHooksJsonInstalled(grokHooksPath(home, env), HOOK_COMMAND);
6267
+ },
6268
+ installEntries(home, env) {
6269
+ return [{
6270
+ kind: "hooks-json",
6271
+ path: grokHooksPath(home, env),
6272
+ content: hookConfig5()
6273
+ }];
6274
+ },
6275
+ sourcePaths(home, env) {
6276
+ return [grokSessionsDir(home, env)];
6277
+ },
6278
+ parseSessionFile: parseGrokSessionFile
6279
+ };
6280
+ }
6281
+
6282
+ // src/adapters/opencode.ts
6283
+ import os6 from "node:os";
6284
+ import path14 from "node:path";
6285
+ async function parseOpenCodeSessionFile(dbPath, options) {
6286
+ const { DatabaseSync } = await import("node:sqlite");
6287
+ if (!dbPath.endsWith(".db")) {
6288
+ return [];
6289
+ }
6290
+ const db = new DatabaseSync(dbPath, { readOnly: true });
6291
+ const events = [];
6292
+ try {
6293
+ const sessionCols = new Set(
6294
+ db.prepare("PRAGMA table_info(session)").all().map((row) => row.name)
6295
+ );
6296
+ const hasDirectory = sessionCols.has("directory");
6297
+ const hasPath = sessionCols.has("path");
6298
+ const hasArchived = sessionCols.has("time_archived");
6299
+ const selectCols = ["id", "title", "time_created"];
6300
+ if (hasDirectory) {
6301
+ selectCols.push("directory");
6302
+ }
6303
+ if (hasPath) {
6304
+ selectCols.push("path");
6305
+ }
6306
+ if (hasArchived) {
6307
+ selectCols.push("time_archived");
6308
+ }
6309
+ const sessions = db.prepare(
6310
+ `SELECT ${selectCols.join(", ")} FROM session WHERE time_created IS NOT NULL ORDER BY time_created`
6311
+ ).all();
6312
+ for (const session of sessions) {
6313
+ const sessionId = session.id;
6314
+ const cwd = session.directory || session.path || void 0;
6315
+ const project = cwd ? path14.basename(cwd) : void 0;
6316
+ const sessionTs = msToIso(session.time_created);
6317
+ events.push(baseOpenCodeEvent({
6318
+ ts: sessionTs,
6319
+ type: "session.started",
6320
+ sessionId,
6321
+ cwd,
6322
+ project,
6323
+ operation: "session start"
6324
+ }));
6325
+ const messages = db.prepare(
6326
+ "SELECT id, data FROM message WHERE session_id = ? ORDER BY time_created"
6327
+ ).all(sessionId);
6328
+ let currentTurnId;
6329
+ let currentProvider;
6330
+ let turnTs;
6331
+ let reasoningEffort;
6332
+ const modelSwitchedEvents = db.prepare(
6333
+ "SELECT data FROM event WHERE aggregate_id = ? AND type = 'session.next.model.switched.1' ORDER BY seq"
6334
+ ).all(sessionId);
6335
+ for (const evt of modelSwitchedEvents) {
6336
+ try {
6337
+ const evtData = JSON.parse(evt.data);
6338
+ const variant = isPlainObject(evtData) ? stringField(evtData.model || evtData, "variant") : void 0;
6339
+ if (variant && variant !== "default") {
6340
+ reasoningEffort = variant;
6341
+ }
6342
+ } catch {
6343
+ }
6344
+ }
6345
+ for (const msg of messages) {
6346
+ let info;
6347
+ try {
6348
+ info = JSON.parse(msg.data);
6349
+ } catch {
6350
+ continue;
6351
+ }
6352
+ if (!isPlainObject(info)) {
6353
+ continue;
6354
+ }
6355
+ const role = stringField(info, "role");
6356
+ const timeObj = objectField(info, "time");
6357
+ const timeCreated = numberField(timeObj, "created");
6358
+ if (!role || !timeCreated) {
6359
+ continue;
6360
+ }
6361
+ if (role === "user") {
6362
+ currentTurnId = `turn_${createStableHash([sessionId, msg.id]).slice(0, 24)}`;
6363
+ turnTs = msToIso(timeCreated);
6364
+ const userAgent = stringField(info, "agent") || "opencode";
6365
+ const modelObj = objectField(info, "model");
6366
+ const model = modelObj ? stringField(modelObj, "modelID") : void 0;
6367
+ currentProvider = modelObj ? stringField(modelObj, "providerID") : void 0;
6368
+ events.push(baseOpenCodeEvent({
6369
+ ts: turnTs,
6370
+ type: "turn.started",
5150
6371
  sessionId,
5151
6372
  turnId: currentTurnId,
5152
6373
  cwd,
@@ -5199,7 +6420,7 @@ async function parseOpenCodeSessionFile(dbPath, options) {
5199
6420
  const provider = currentProvider;
5200
6421
  const pathObj = objectField(info, "path");
5201
6422
  const assistantCwd = stringField(pathObj, "cwd") || cwd;
5202
- const assistantProject = assistantCwd ? path13.basename(assistantCwd) : project;
6423
+ const assistantProject = assistantCwd ? path14.basename(assistantCwd) : project;
5203
6424
  const completedTs = numberField(objectField(info, "time"), "completed");
5204
6425
  const createdTs = timeCreated;
5205
6426
  const tokens = opencodeUsageFromInfo(info);
@@ -5447,33 +6668,33 @@ function opencodeUsageFromInfo(info) {
5447
6668
  function opencodeConfigDir(home, env) {
5448
6669
  const override = env?.OPENCODE_CONFIG_DIR;
5449
6670
  if (override && override.trim()) {
5450
- return path13.resolve(override);
6671
+ return path14.resolve(override);
5451
6672
  }
5452
6673
  const xdgConfig = env?.XDG_CONFIG_HOME;
5453
6674
  if (xdgConfig && xdgConfig.trim()) {
5454
- return path13.join(path13.resolve(xdgConfig), "opencode");
6675
+ return path14.join(path14.resolve(xdgConfig), "opencode");
5455
6676
  }
5456
- return path13.join(home, ".config", "opencode");
6677
+ return path14.join(home, ".config", "opencode");
5457
6678
  }
5458
6679
  function opencodeDataCandidates(home, env) {
5459
6680
  const xdgData = env?.XDG_DATA_HOME;
5460
- const primary = xdgData && xdgData.trim() ? path13.join(path13.resolve(xdgData), "opencode", "opencode.db") : path13.join(home, ".local", "share", "opencode", "opencode.db");
5461
- return [primary, path13.join(home, ".opencode", "opencode.db")];
6681
+ const primary = xdgData && xdgData.trim() ? path14.join(path14.resolve(xdgData), "opencode", "opencode.db") : path14.join(home, ".local", "share", "opencode", "opencode.db");
6682
+ return [primary, path14.join(home, ".opencode", "opencode.db")];
5462
6683
  }
5463
6684
  async function opencodeBackfillFiles(sourceRoot, home = os6.homedir(), env) {
5464
- const { stat: stat13 } = await import("node:fs/promises");
6685
+ const { stat: stat14 } = await import("node:fs/promises");
5465
6686
  if (sourceRoot) {
5466
6687
  if (!sourceRoot.endsWith(".db")) {
5467
6688
  return [];
5468
6689
  }
5469
- const info = await stat13(sourceRoot).catch(() => null);
6690
+ const info = await stat14(sourceRoot).catch(() => null);
5470
6691
  if (!info) {
5471
6692
  return [];
5472
6693
  }
5473
6694
  return [{ path: sourceRoot, modifiedAt: info.mtime.toISOString() }];
5474
6695
  }
5475
6696
  for (const candidatePath of opencodeDataCandidates(home, env)) {
5476
- const info = await stat13(candidatePath).catch(() => null);
6697
+ const info = await stat14(candidatePath).catch(() => null);
5477
6698
  if (info) {
5478
6699
  return [{ path: candidatePath, modifiedAt: info.mtime.toISOString() }];
5479
6700
  }
@@ -5548,12 +6769,12 @@ function createOpenCodeAdapter() {
5548
6769
  return opencodeConfigDir(home, env);
5549
6770
  },
5550
6771
  installedPath(home, env) {
5551
- return path13.join(opencodeConfigDir(home, env), PLUGIN_PATH);
6772
+ return path14.join(opencodeConfigDir(home, env), PLUGIN_PATH);
5552
6773
  },
5553
6774
  async isInstalled(home, env) {
5554
6775
  try {
5555
6776
  const { pathExists: pathExists2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
5556
- return await pathExists2(path13.join(opencodeConfigDir(home, env), PLUGIN_PATH)) || await pathExists2(path13.join(".opencode", PLUGIN_PATH));
6777
+ return await pathExists2(path14.join(opencodeConfigDir(home, env), PLUGIN_PATH)) || await pathExists2(path14.join(".opencode", PLUGIN_PATH));
5557
6778
  } catch {
5558
6779
  return false;
5559
6780
  }
@@ -5561,7 +6782,7 @@ function createOpenCodeAdapter() {
5561
6782
  installEntries(home, env) {
5562
6783
  return [{
5563
6784
  kind: "file",
5564
- path: path13.join(opencodeConfigDir(home, env), PLUGIN_PATH),
6785
+ path: path14.join(opencodeConfigDir(home, env), PLUGIN_PATH),
5565
6786
  content: opencodePluginContent()
5566
6787
  }];
5567
6788
  },
@@ -5573,10 +6794,10 @@ function createOpenCodeAdapter() {
5573
6794
  }
5574
6795
 
5575
6796
  // src/adapters/pi.ts
5576
- import { readFile as readFile8 } from "node:fs/promises";
5577
- import path14 from "node:path";
6797
+ import { readFile as readFile9 } from "node:fs/promises";
6798
+ import path15 from "node:path";
5578
6799
  async function parsePiSessionFile(filePath, options) {
5579
- const text = await readFile8(filePath, "utf8");
6800
+ const text = await readFile9(filePath, "utf8");
5580
6801
  const lines = text.split("\n").filter(Boolean);
5581
6802
  let sessionId;
5582
6803
  let cwd;
@@ -5607,7 +6828,7 @@ async function parsePiSessionFile(filePath, options) {
5607
6828
  sessionId = stringField(raw, "id") || state.sessionId;
5608
6829
  state.sessionId = sessionId || state.sessionId;
5609
6830
  cwd = stringField(raw, "cwd") || cwd;
5610
- project = cwd ? path14.basename(cwd) : project;
6831
+ project = cwd ? path15.basename(cwd) : project;
5611
6832
  continue;
5612
6833
  }
5613
6834
  if (entryType === "model_change") {
@@ -6016,16 +7237,16 @@ export default function (pi: ExtensionAPI) {
6016
7237
  function piAgentDir(home, env) {
6017
7238
  const override = env?.PI_CODING_AGENT_DIR;
6018
7239
  if (override && override.trim()) {
6019
- return path14.resolve(override);
7240
+ return path15.resolve(override);
6020
7241
  }
6021
- return path14.join(home, ".pi", "agent");
7242
+ return path15.join(home, ".pi", "agent");
6022
7243
  }
6023
7244
  function piSessionDir(home, env) {
6024
7245
  const override = env?.PI_CODING_AGENT_SESSION_DIR;
6025
7246
  if (override && override.trim()) {
6026
- return path14.resolve(override);
7247
+ return path15.resolve(override);
6027
7248
  }
6028
- return path14.join(piAgentDir(home, env), "sessions");
7249
+ return path15.join(piAgentDir(home, env), "sessions");
6029
7250
  }
6030
7251
  function createPiAdapter() {
6031
7252
  return {
@@ -6037,12 +7258,12 @@ function createPiAdapter() {
6037
7258
  return piAgentDir(home, env);
6038
7259
  },
6039
7260
  installedPath(home, env) {
6040
- return path14.join(piAgentDir(home, env), "extensions", "vibetime.ts");
7261
+ return path15.join(piAgentDir(home, env), "extensions", "vibetime.ts");
6041
7262
  },
6042
7263
  async isInstalled(home, env) {
6043
7264
  try {
6044
7265
  const { pathExists: pathExists2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
6045
- return await pathExists2(path14.join(piAgentDir(home, env), "extensions", "vibetime.ts"));
7266
+ return await pathExists2(path15.join(piAgentDir(home, env), "extensions", "vibetime.ts"));
6046
7267
  } catch {
6047
7268
  return false;
6048
7269
  }
@@ -6050,7 +7271,7 @@ function createPiAdapter() {
6050
7271
  installEntries(home, env) {
6051
7272
  return [{
6052
7273
  kind: "file",
6053
- path: path14.join(piAgentDir(home, env), "extensions", "vibetime.ts"),
7274
+ path: path15.join(piAgentDir(home, env), "extensions", "vibetime.ts"),
6054
7275
  content: piExtensionContent()
6055
7276
  }];
6056
7277
  },
@@ -6062,11 +7283,11 @@ function createPiAdapter() {
6062
7283
  }
6063
7284
 
6064
7285
  // src/adapters/qoder-cn.ts
6065
- import { readdir as readdir6, readFile as readFile9, stat as stat7 } from "node:fs/promises";
7286
+ import { readdir as readdir7, readFile as readFile10, stat as stat8 } from "node:fs/promises";
6066
7287
  import os7 from "node:os";
6067
- import path15 from "node:path";
7288
+ import path16 from "node:path";
6068
7289
  function parseQoderCnPaths(filePath) {
6069
- const parts = filePath.split(path15.sep);
7290
+ const parts = filePath.split(path16.sep);
6070
7291
  const subagentsIdx = parts.lastIndexOf("subagents");
6071
7292
  let sessionId = "";
6072
7293
  let projectName = "";
@@ -6075,20 +7296,20 @@ function parseQoderCnPaths(filePath) {
6075
7296
  sessionId = parts[subagentsIdx - 1];
6076
7297
  projectName = parts[subagentsIdx - 2];
6077
7298
  const projectsIdx = parts.lastIndexOf("projects");
6078
- configDir2 = parts.slice(0, projectsIdx).join(path15.sep);
7299
+ configDir2 = parts.slice(0, projectsIdx).join(path16.sep);
6079
7300
  } else {
6080
7301
  const filename = parts.at(-1) || "";
6081
- sessionId = path15.basename(filename, ".jsonl");
7302
+ sessionId = path16.basename(filename, ".jsonl");
6082
7303
  projectName = parts.at(-2) || "";
6083
7304
  const projectsIdx = parts.lastIndexOf("projects");
6084
- configDir2 = parts.slice(0, projectsIdx).join(path15.sep);
7305
+ configDir2 = parts.slice(0, projectsIdx).join(path16.sep);
6085
7306
  }
6086
7307
  return { configDir: configDir2, projectName, sessionId };
6087
7308
  }
6088
7309
  async function loadQoderCnModelNames(configDir2) {
6089
7310
  try {
6090
- const dynamicTextsPath = path15.join(configDir2, ".auth", "dynamic-texts.json");
6091
- const content = await readFile9(dynamicTextsPath, "utf8");
7311
+ const dynamicTextsPath = path16.join(configDir2, ".auth", "dynamic-texts.json");
7312
+ const content = await readFile10(dynamicTextsPath, "utf8");
6092
7313
  const json = JSON.parse(content);
6093
7314
  const texts = json.texts || {};
6094
7315
  const map = {};
@@ -6105,15 +7326,15 @@ async function loadQoderCnModelNames(configDir2) {
6105
7326
  }
6106
7327
  async function loadQoderCnSegmentModelCalls(filePath, isSubagentSession, modelMap) {
6107
7328
  const { configDir: configDir2, projectName, sessionId } = parseQoderCnPaths(filePath);
6108
- const segmentsPath = path15.join(configDir2, "logs", "sessions", projectName, sessionId, "segments");
7329
+ const segmentsPath = path16.join(configDir2, "logs", "sessions", projectName, sessionId, "segments");
6109
7330
  const modelCalls = [];
6110
7331
  try {
6111
- const files = await readdir6(segmentsPath);
7332
+ const files = await readdir7(segmentsPath);
6112
7333
  for (const file of files) {
6113
7334
  if (!file.endsWith(".jsonl")) {
6114
7335
  continue;
6115
7336
  }
6116
- const content = await readFile9(path15.join(segmentsPath, file), "utf8");
7337
+ const content = await readFile10(path16.join(segmentsPath, file), "utf8");
6117
7338
  let currentTurnIsSubagent = false;
6118
7339
  for (const line of content.split("\n").filter(Boolean)) {
6119
7340
  const raw = parseJsonLine(line);
@@ -6146,7 +7367,7 @@ async function loadQoderCnSegmentModelCalls(filePath, isSubagentSession, modelMa
6146
7367
  return modelCalls.filter((call) => call.isSubagent === isSubagentSession);
6147
7368
  }
6148
7369
  async function parseQoderCnSessionFile(filePath, options) {
6149
- const text = await readFile9(filePath, "utf8");
7370
+ const text = await readFile10(filePath, "utf8");
6150
7371
  const lines = text.split("\n").filter(Boolean);
6151
7372
  const { configDir: configDir2 } = parseQoderCnPaths(filePath);
6152
7373
  const projectContext = await qoderCnProjectContextFromLines(filePath, lines, options, configDir2);
@@ -6181,7 +7402,7 @@ async function parseQoderCnSessionFile(filePath, options) {
6181
7402
  sessionId = stringField(raw, "sessionId") || sessionId;
6182
7403
  state.sessionId = sessionId;
6183
7404
  cwd = stringField(raw, "cwd") || cwd;
6184
- project = projectContext.project || (cwd ? path15.basename(cwd) : project || await qoderCnProjectFromFilePath(filePath, options));
7405
+ project = projectContext.project || (cwd ? path16.basename(cwd) : project || await qoderCnProjectFromFilePath(filePath, options));
6185
7406
  if (!ts) {
6186
7407
  continue;
6187
7408
  }
@@ -6482,7 +7703,7 @@ function fileActivitiesFromQoderCnToolUse(tool, input, ts, cwd) {
6482
7703
  const metrics = fileMetricsFromQoderCnToolInput(tool, input);
6483
7704
  addResolvedPathActivity(changes, filePath, operation, ts, cwd, workdir, metrics);
6484
7705
  }
6485
- for (const edit of arrayField3(input, "edits")) {
7706
+ for (const edit of arrayField4(input, "edits")) {
6486
7707
  if (!isPlainObject(edit)) {
6487
7708
  continue;
6488
7709
  }
@@ -6526,17 +7747,17 @@ function fileMetricsFromQoderCnToolInput(tool, input) {
6526
7747
  }
6527
7748
  return {};
6528
7749
  }
6529
- function arrayField3(object, key) {
7750
+ function arrayField4(object, key) {
6530
7751
  if (!isPlainObject(object) || !Array.isArray(object[key])) {
6531
7752
  return [];
6532
7753
  }
6533
7754
  return object[key];
6534
7755
  }
6535
7756
  function qoderCnToolUseItems(message) {
6536
- return arrayField3(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
7757
+ return arrayField4(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
6537
7758
  }
6538
7759
  function qoderCnToolResultItems(message) {
6539
- return arrayField3(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
7760
+ return arrayField4(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
6540
7761
  }
6541
7762
  function isQoderCnToolResultMessage(message) {
6542
7763
  return qoderCnToolResultItems(message).length > 0;
@@ -6610,28 +7831,28 @@ function isNoisePrompt(text) {
6610
7831
  }
6611
7832
  async function qoderCnProjectContextFromLines(filePath, lines, options, configDir2) {
6612
7833
  const { projectName: projectDir, sessionId } = parseQoderCnPaths(filePath);
6613
- const isSubagent = filePath.includes(`${path15.sep}subagents${path15.sep}`);
7834
+ const isSubagent = filePath.includes(`${path16.sep}subagents${path16.sep}`);
6614
7835
  const inherited = isSubagent ? await readPersistedSessionContextFromOptions(options, sessionId) : void 0;
6615
7836
  let cwds = [];
6616
7837
  for (const line of lines) {
6617
7838
  const raw = parseJsonLine(line);
6618
7839
  const cwd = raw ? stringField(raw, "cwd") : void 0;
6619
- if (cwd && path15.isAbsolute(cwd)) {
7840
+ if (cwd && path16.isAbsolute(cwd)) {
6620
7841
  cwds.push(cwd);
6621
7842
  }
6622
7843
  }
6623
7844
  if (isSubagent) {
6624
- if (inherited?.cwd && path15.isAbsolute(inherited.cwd)) {
7845
+ if (inherited?.cwd && path16.isAbsolute(inherited.cwd)) {
6625
7846
  cwds = [inherited.cwd];
6626
7847
  } else {
6627
- const parentSessionPath = path15.join(configDir2, "projects", projectDir, `${sessionId}.jsonl`);
7848
+ const parentSessionPath = path16.join(configDir2, "projects", projectDir, `${sessionId}.jsonl`);
6628
7849
  try {
6629
- const parentText = await readFile9(parentSessionPath, "utf8");
7850
+ const parentText = await readFile10(parentSessionPath, "utf8");
6630
7851
  const parentCwds = [];
6631
7852
  for (const line of parentText.split("\n").filter(Boolean)) {
6632
7853
  const raw = parseJsonLine(line);
6633
7854
  const cwd = raw ? stringField(raw, "cwd") : void 0;
6634
- if (cwd && path15.isAbsolute(cwd)) {
7855
+ if (cwd && path16.isAbsolute(cwd)) {
6635
7856
  parentCwds.push(cwd);
6636
7857
  }
6637
7858
  }
@@ -6643,7 +7864,7 @@ async function qoderCnProjectContextFromLines(filePath, lines, options, configDi
6643
7864
  }
6644
7865
  }
6645
7866
  const root = await gitRootFromCwds2(cwds) || qoderCnProjectRootFromCwds(projectDir, cwds);
6646
- const project = inherited?.project || (cwds.length > 0 ? path15.basename(cwds[0]) : root ? path15.basename(root) : await qoderCnProjectFromFilePath(filePath, options));
7867
+ const project = inherited?.project || (cwds.length > 0 ? path16.basename(cwds[0]) : root ? path16.basename(root) : await qoderCnProjectFromFilePath(filePath, options));
6647
7868
  return {
6648
7869
  project,
6649
7870
  workspaceId: createWorkspaceId({ projectName: project, repoRoot: root })
@@ -6652,15 +7873,15 @@ async function qoderCnProjectContextFromLines(filePath, lines, options, configDi
6652
7873
  async function gitRootFromCwds2(cwds) {
6653
7874
  const seen = /* @__PURE__ */ new Set();
6654
7875
  for (const cwd of cwds) {
6655
- let current = path15.resolve(cwd);
7876
+ let current = path16.resolve(cwd);
6656
7877
  while (!seen.has(current)) {
6657
7878
  seen.add(current);
6658
7879
  try {
6659
- await stat7(path15.join(current, ".git"));
7880
+ await stat8(path16.join(current, ".git"));
6660
7881
  return current;
6661
7882
  } catch {
6662
7883
  }
6663
- const parent = path15.dirname(current);
7884
+ const parent = path16.dirname(current);
6664
7885
  if (parent === current) {
6665
7886
  break;
6666
7887
  }
@@ -6671,12 +7892,12 @@ async function gitRootFromCwds2(cwds) {
6671
7892
  }
6672
7893
  function qoderCnProjectRootFromCwds(projectDir, cwds) {
6673
7894
  for (const cwd of cwds) {
6674
- let current = path15.resolve(cwd);
7895
+ let current = path16.resolve(cwd);
6675
7896
  while (true) {
6676
7897
  if (encodeQoderCnProjectPath(current) === projectDir) {
6677
7898
  return current;
6678
7899
  }
6679
- const parent = path15.dirname(current);
7900
+ const parent = path16.dirname(current);
6680
7901
  if (parent === current) {
6681
7902
  break;
6682
7903
  }
@@ -6686,14 +7907,14 @@ function qoderCnProjectRootFromCwds(projectDir, cwds) {
6686
7907
  return void 0;
6687
7908
  }
6688
7909
  function encodeQoderCnProjectPath(value) {
6689
- return path15.resolve(value).split(path15.sep).join("-").replace(/_/g, "-");
7910
+ return path16.resolve(value).split(path16.sep).join("-").replace(/_/g, "-");
6690
7911
  }
6691
7912
  async function qoderCnProjectFromFilePath(filePath, options) {
6692
- const projectDir = path15.basename(path15.dirname(filePath));
6693
- const home = options ? path15.resolve(stringOption(options.home) || os7.homedir()) : os7.homedir();
7913
+ const projectDir = path16.basename(path16.dirname(filePath));
7914
+ const home = options ? path16.resolve(stringOption(options.home) || os7.homedir()) : os7.homedir();
6694
7915
  const resolved = await resolveQoderCnProjectPath(projectDir, home);
6695
7916
  if (resolved) {
6696
- return path15.basename(resolved);
7917
+ return path16.basename(resolved);
6697
7918
  }
6698
7919
  const homePrefix = `${encodeQoderCnProjectPath(home)}-`;
6699
7920
  if (projectDir.startsWith(homePrefix)) {
@@ -6713,12 +7934,12 @@ async function resolveQoderCnProjectPath(projectDir, home) {
6713
7934
  while (projectDir.startsWith(`${currentEncoded}-`)) {
6714
7935
  let matchedChild;
6715
7936
  try {
6716
- const entries = await readdir6(current, { withFileTypes: true });
7937
+ const entries = await readdir7(current, { withFileTypes: true });
6717
7938
  for (const entry of entries) {
6718
7939
  if (!entry.isDirectory()) {
6719
7940
  continue;
6720
7941
  }
6721
- const candidate = path15.join(current, entry.name);
7942
+ const candidate = path16.join(current, entry.name);
6722
7943
  const encoded = encodeQoderCnProjectPath(candidate);
6723
7944
  if (encoded === projectDir) {
6724
7945
  return candidate;
@@ -6740,7 +7961,7 @@ async function resolveQoderCnProjectPath(projectDir, home) {
6740
7961
  return void 0;
6741
7962
  }
6742
7963
  var qoderCnHandler = (msg) => hookHandler("qoder-cn", msg);
6743
- function hookConfig5() {
7964
+ function hookConfig6() {
6744
7965
  const anyTool = [{ matcher: ".*", hooks: [qoderCnHandler("Reporting tool activity")] }];
6745
7966
  return {
6746
7967
  hooks: {
@@ -6763,9 +7984,9 @@ function hookConfig5() {
6763
7984
  function qoderCnConfigDir(home, env) {
6764
7985
  const override = env?.QODER_CN_CONFIG_DIR;
6765
7986
  if (override && override.trim()) {
6766
- return path15.resolve(override);
7987
+ return path16.resolve(override);
6767
7988
  }
6768
- return path15.join(home, ".qoder-cn");
7989
+ return path16.join(home, ".qoder-cn");
6769
7990
  }
6770
7991
  function createQoderCnAdapter() {
6771
7992
  return {
@@ -6777,27 +7998,27 @@ function createQoderCnAdapter() {
6777
7998
  return qoderCnConfigDir(home, env);
6778
7999
  },
6779
8000
  installedPath(home, env) {
6780
- return path15.join(qoderCnConfigDir(home, env), "settings.json");
8001
+ return path16.join(qoderCnConfigDir(home, env), "settings.json");
6781
8002
  },
6782
8003
  async isInstalled(home, env) {
6783
8004
  return isHooksJsonInstalled(
6784
- path15.join(qoderCnConfigDir(home, env), "settings.json"),
8005
+ path16.join(qoderCnConfigDir(home, env), "settings.json"),
6785
8006
  "vibetime hook --agent qoder-cn"
6786
8007
  );
6787
8008
  },
6788
8009
  installEntries(home, env) {
6789
8010
  return [{
6790
8011
  kind: "hooks-json",
6791
- path: path15.join(qoderCnConfigDir(home, env), "settings.json"),
6792
- content: hookConfig5()
8012
+ path: path16.join(qoderCnConfigDir(home, env), "settings.json"),
8013
+ content: hookConfig6()
6793
8014
  }];
6794
8015
  },
6795
8016
  sourcePaths(home, env) {
6796
8017
  const base = qoderCnConfigDir(home, env);
6797
8018
  return [
6798
- path15.join(base, "projects"),
6799
- path15.join(base, ".qoder.json"),
6800
- path15.join(home, ".qoder.json")
8019
+ path16.join(base, "projects"),
8020
+ path16.join(base, ".qoder.json"),
8021
+ path16.join(home, ".qoder.json")
6801
8022
  ];
6802
8023
  },
6803
8024
  parseSessionFile: parseQoderCnSessionFile
@@ -6805,11 +8026,11 @@ function createQoderCnAdapter() {
6805
8026
  }
6806
8027
 
6807
8028
  // src/adapters/qoder.ts
6808
- import { readdir as readdir7, readFile as readFile10, stat as stat8 } from "node:fs/promises";
8029
+ import { readdir as readdir8, readFile as readFile11, stat as stat9 } from "node:fs/promises";
6809
8030
  import os8 from "node:os";
6810
- import path16 from "node:path";
8031
+ import path17 from "node:path";
6811
8032
  function parseQoderPaths(filePath) {
6812
- const parts = filePath.split(path16.sep);
8033
+ const parts = filePath.split(path17.sep);
6813
8034
  const subagentsIdx = parts.lastIndexOf("subagents");
6814
8035
  let sessionId = "";
6815
8036
  let projectName = "";
@@ -6818,20 +8039,20 @@ function parseQoderPaths(filePath) {
6818
8039
  sessionId = parts[subagentsIdx - 1];
6819
8040
  projectName = parts[subagentsIdx - 2];
6820
8041
  const projectsIdx = parts.lastIndexOf("projects");
6821
- configDir2 = parts.slice(0, projectsIdx).join(path16.sep);
8042
+ configDir2 = parts.slice(0, projectsIdx).join(path17.sep);
6822
8043
  } else {
6823
8044
  const filename = parts.at(-1) || "";
6824
- sessionId = path16.basename(filename, ".jsonl");
8045
+ sessionId = path17.basename(filename, ".jsonl");
6825
8046
  projectName = parts.at(-2) || "";
6826
8047
  const projectsIdx = parts.lastIndexOf("projects");
6827
- configDir2 = parts.slice(0, projectsIdx).join(path16.sep);
8048
+ configDir2 = parts.slice(0, projectsIdx).join(path17.sep);
6828
8049
  }
6829
8050
  return { configDir: configDir2, projectName, sessionId };
6830
8051
  }
6831
8052
  async function loadQoderModelNames(configDir2) {
6832
8053
  try {
6833
- const dynamicTextsPath = path16.join(configDir2, ".auth", "dynamic-texts.json");
6834
- const content = await readFile10(dynamicTextsPath, "utf8");
8054
+ const dynamicTextsPath = path17.join(configDir2, ".auth", "dynamic-texts.json");
8055
+ const content = await readFile11(dynamicTextsPath, "utf8");
6835
8056
  const json = JSON.parse(content);
6836
8057
  const texts = json.texts || {};
6837
8058
  const map = {};
@@ -6848,15 +8069,15 @@ async function loadQoderModelNames(configDir2) {
6848
8069
  }
6849
8070
  async function loadQoderSegmentModelCalls(filePath, isSubagentSession, modelMap) {
6850
8071
  const { configDir: configDir2, projectName, sessionId } = parseQoderPaths(filePath);
6851
- const segmentsPath = path16.join(configDir2, "logs", "sessions", projectName, sessionId, "segments");
8072
+ const segmentsPath = path17.join(configDir2, "logs", "sessions", projectName, sessionId, "segments");
6852
8073
  const modelCalls = [];
6853
8074
  try {
6854
- const files = await readdir7(segmentsPath);
8075
+ const files = await readdir8(segmentsPath);
6855
8076
  for (const file of files) {
6856
8077
  if (!file.endsWith(".jsonl")) {
6857
8078
  continue;
6858
8079
  }
6859
- const content = await readFile10(path16.join(segmentsPath, file), "utf8");
8080
+ const content = await readFile11(path17.join(segmentsPath, file), "utf8");
6860
8081
  let currentTurnIsSubagent = false;
6861
8082
  for (const line of content.split("\n").filter(Boolean)) {
6862
8083
  const raw = parseJsonLine(line);
@@ -6889,7 +8110,7 @@ async function loadQoderSegmentModelCalls(filePath, isSubagentSession, modelMap)
6889
8110
  return modelCalls.filter((call) => call.isSubagent === isSubagentSession);
6890
8111
  }
6891
8112
  async function parseQoderSessionFile(filePath, options) {
6892
- const text = await readFile10(filePath, "utf8");
8113
+ const text = await readFile11(filePath, "utf8");
6893
8114
  const lines = text.split("\n").filter(Boolean);
6894
8115
  const { configDir: configDir2 } = parseQoderPaths(filePath);
6895
8116
  const projectContext = await qoderProjectContextFromLines(filePath, lines, options, configDir2);
@@ -6924,7 +8145,7 @@ async function parseQoderSessionFile(filePath, options) {
6924
8145
  sessionId = stringField(raw, "sessionId") || sessionId;
6925
8146
  state.sessionId = sessionId;
6926
8147
  cwd = stringField(raw, "cwd") || cwd;
6927
- project = projectContext.project || (cwd ? path16.basename(cwd) : project || await qoderProjectFromFilePath(filePath, options));
8148
+ project = projectContext.project || (cwd ? path17.basename(cwd) : project || await qoderProjectFromFilePath(filePath, options));
6928
8149
  if (!ts) {
6929
8150
  continue;
6930
8151
  }
@@ -7225,7 +8446,7 @@ function fileActivitiesFromQoderToolUse(tool, input, ts, cwd) {
7225
8446
  const metrics = fileMetricsFromQoderToolInput(tool, input);
7226
8447
  addResolvedPathActivity(changes, filePath, operation, ts, cwd, workdir, metrics);
7227
8448
  }
7228
- for (const edit of arrayField4(input, "edits")) {
8449
+ for (const edit of arrayField5(input, "edits")) {
7229
8450
  if (!isPlainObject(edit)) {
7230
8451
  continue;
7231
8452
  }
@@ -7269,17 +8490,17 @@ function fileMetricsFromQoderToolInput(tool, input) {
7269
8490
  }
7270
8491
  return {};
7271
8492
  }
7272
- function arrayField4(object, key) {
8493
+ function arrayField5(object, key) {
7273
8494
  if (!isPlainObject(object) || !Array.isArray(object[key])) {
7274
8495
  return [];
7275
8496
  }
7276
8497
  return object[key];
7277
8498
  }
7278
8499
  function qoderToolUseItems(message) {
7279
- return arrayField4(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
8500
+ return arrayField5(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_use");
7280
8501
  }
7281
8502
  function qoderToolResultItems(message) {
7282
- return arrayField4(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
8503
+ return arrayField5(message, "content").filter((item) => isPlainObject(item) && item.type === "tool_result");
7283
8504
  }
7284
8505
  function isQoderToolResultMessage(message) {
7285
8506
  return qoderToolResultItems(message).length > 0;
@@ -7319,28 +8540,28 @@ function qoderExtractText(value) {
7319
8540
  }
7320
8541
  async function qoderProjectContextFromLines(filePath, lines, options, configDir2) {
7321
8542
  const { projectName: projectDir, sessionId } = parseQoderPaths(filePath);
7322
- const isSubagent = filePath.includes(`${path16.sep}subagents${path16.sep}`);
8543
+ const isSubagent = filePath.includes(`${path17.sep}subagents${path17.sep}`);
7323
8544
  const inherited = isSubagent ? await readPersistedSessionContextFromOptions(options, sessionId) : void 0;
7324
8545
  let cwds = [];
7325
8546
  for (const line of lines) {
7326
8547
  const raw = parseJsonLine(line);
7327
8548
  const cwd = raw ? stringField(raw, "cwd") : void 0;
7328
- if (cwd && path16.isAbsolute(cwd)) {
8549
+ if (cwd && path17.isAbsolute(cwd)) {
7329
8550
  cwds.push(cwd);
7330
8551
  }
7331
8552
  }
7332
8553
  if (isSubagent) {
7333
- if (inherited?.cwd && path16.isAbsolute(inherited.cwd)) {
8554
+ if (inherited?.cwd && path17.isAbsolute(inherited.cwd)) {
7334
8555
  cwds = [inherited.cwd];
7335
8556
  } else {
7336
- const parentSessionPath = path16.join(configDir2, "projects", projectDir, `${sessionId}.jsonl`);
8557
+ const parentSessionPath = path17.join(configDir2, "projects", projectDir, `${sessionId}.jsonl`);
7337
8558
  try {
7338
- const parentText = await readFile10(parentSessionPath, "utf8");
8559
+ const parentText = await readFile11(parentSessionPath, "utf8");
7339
8560
  const parentCwds = [];
7340
8561
  for (const line of parentText.split("\n").filter(Boolean)) {
7341
8562
  const raw = parseJsonLine(line);
7342
8563
  const cwd = raw ? stringField(raw, "cwd") : void 0;
7343
- if (cwd && path16.isAbsolute(cwd)) {
8564
+ if (cwd && path17.isAbsolute(cwd)) {
7344
8565
  parentCwds.push(cwd);
7345
8566
  }
7346
8567
  }
@@ -7352,7 +8573,7 @@ async function qoderProjectContextFromLines(filePath, lines, options, configDir2
7352
8573
  }
7353
8574
  }
7354
8575
  const root = await gitRootFromCwds3(cwds) || qoderProjectRootFromCwds(projectDir, cwds);
7355
- const project = inherited?.project || (cwds.length > 0 ? path16.basename(cwds[0]) : root ? path16.basename(root) : await qoderProjectFromFilePath(filePath, options));
8576
+ const project = inherited?.project || (cwds.length > 0 ? path17.basename(cwds[0]) : root ? path17.basename(root) : await qoderProjectFromFilePath(filePath, options));
7356
8577
  return {
7357
8578
  project,
7358
8579
  workspaceId: createWorkspaceId({ projectName: project, repoRoot: root })
@@ -7361,15 +8582,15 @@ async function qoderProjectContextFromLines(filePath, lines, options, configDir2
7361
8582
  async function gitRootFromCwds3(cwds) {
7362
8583
  const seen = /* @__PURE__ */ new Set();
7363
8584
  for (const cwd of cwds) {
7364
- let current = path16.resolve(cwd);
8585
+ let current = path17.resolve(cwd);
7365
8586
  while (!seen.has(current)) {
7366
8587
  seen.add(current);
7367
8588
  try {
7368
- await stat8(path16.join(current, ".git"));
8589
+ await stat9(path17.join(current, ".git"));
7369
8590
  return current;
7370
8591
  } catch {
7371
8592
  }
7372
- const parent = path16.dirname(current);
8593
+ const parent = path17.dirname(current);
7373
8594
  if (parent === current) {
7374
8595
  break;
7375
8596
  }
@@ -7380,12 +8601,12 @@ async function gitRootFromCwds3(cwds) {
7380
8601
  }
7381
8602
  function qoderProjectRootFromCwds(projectDir, cwds) {
7382
8603
  for (const cwd of cwds) {
7383
- let current = path16.resolve(cwd);
8604
+ let current = path17.resolve(cwd);
7384
8605
  while (true) {
7385
8606
  if (encodeQoderProjectPath(current) === projectDir) {
7386
8607
  return current;
7387
8608
  }
7388
- const parent = path16.dirname(current);
8609
+ const parent = path17.dirname(current);
7389
8610
  if (parent === current) {
7390
8611
  break;
7391
8612
  }
@@ -7395,10 +8616,10 @@ function qoderProjectRootFromCwds(projectDir, cwds) {
7395
8616
  return void 0;
7396
8617
  }
7397
8618
  function encodeQoderProjectPath(value) {
7398
- return path16.resolve(value).split(path16.sep).join("-").replace(/_/g, "-");
8619
+ return path17.resolve(value).split(path17.sep).join("-").replace(/_/g, "-");
7399
8620
  }
7400
8621
  function rawQoderProjectPath(value) {
7401
- return path16.resolve(value).split(path16.sep).join("-");
8622
+ return path17.resolve(value).split(path17.sep).join("-");
7402
8623
  }
7403
8624
  function qoderEncodedVariants(value) {
7404
8625
  const raw = rawQoderProjectPath(value);
@@ -7414,11 +8635,11 @@ function qoderEncodedProjectSuffix(projectDir, home) {
7414
8635
  return void 0;
7415
8636
  }
7416
8637
  async function qoderProjectFromFilePath(filePath, options) {
7417
- const projectDir = path16.basename(path16.dirname(filePath));
7418
- const home = options ? path16.resolve(stringOption(options.home) || os8.homedir()) : os8.homedir();
8638
+ const projectDir = path17.basename(path17.dirname(filePath));
8639
+ const home = options ? path17.resolve(stringOption(options.home) || os8.homedir()) : os8.homedir();
7419
8640
  const resolved = await resolveQoderProjectPath(projectDir, home);
7420
8641
  if (resolved) {
7421
- return path16.basename(resolved);
8642
+ return path17.basename(resolved);
7422
8643
  }
7423
8644
  const suffix = qoderEncodedProjectSuffix(projectDir, home);
7424
8645
  if (suffix) {
@@ -7439,12 +8660,12 @@ async function resolveQoderProjectPath(projectDir, home) {
7439
8660
  while (currentEncodedVariants.some((prefix) => projectDir.startsWith(`${prefix}-`))) {
7440
8661
  let matchedChild;
7441
8662
  try {
7442
- const entries = await readdir7(current, { withFileTypes: true });
8663
+ const entries = await readdir8(current, { withFileTypes: true });
7443
8664
  for (const entry of entries) {
7444
8665
  if (!entry.isDirectory()) {
7445
8666
  continue;
7446
8667
  }
7447
- const candidate = path16.join(current, entry.name);
8668
+ const candidate = path17.join(current, entry.name);
7448
8669
  const candidateVariants = qoderEncodedVariants(candidate);
7449
8670
  if (candidateVariants.includes(projectDir)) {
7450
8671
  return candidate;
@@ -7466,7 +8687,7 @@ async function resolveQoderProjectPath(projectDir, home) {
7466
8687
  return void 0;
7467
8688
  }
7468
8689
  var qoderHandler = (msg) => hookHandler("qoder", msg);
7469
- function hookConfig6() {
8690
+ function hookConfig7() {
7470
8691
  const anyTool = [{ matcher: ".*", hooks: [qoderHandler("Reporting tool activity")] }];
7471
8692
  return {
7472
8693
  hooks: {
@@ -7489,9 +8710,9 @@ function hookConfig6() {
7489
8710
  function qoderConfigDir(home, env) {
7490
8711
  const override = env?.QODER_CONFIG_DIR;
7491
8712
  if (override && override.trim()) {
7492
- return path16.resolve(override);
8713
+ return path17.resolve(override);
7493
8714
  }
7494
- return path16.join(home, ".qoder");
8715
+ return path17.join(home, ".qoder");
7495
8716
  }
7496
8717
  function createQoderAdapter() {
7497
8718
  return {
@@ -7503,27 +8724,27 @@ function createQoderAdapter() {
7503
8724
  return qoderConfigDir(home, env);
7504
8725
  },
7505
8726
  installedPath(home, env) {
7506
- return path16.join(qoderConfigDir(home, env), "settings.json");
8727
+ return path17.join(qoderConfigDir(home, env), "settings.json");
7507
8728
  },
7508
8729
  async isInstalled(home, env) {
7509
8730
  return isHooksJsonInstalled(
7510
- path16.join(qoderConfigDir(home, env), "settings.json"),
8731
+ path17.join(qoderConfigDir(home, env), "settings.json"),
7511
8732
  "vibetime hook --agent qoder"
7512
8733
  );
7513
8734
  },
7514
8735
  installEntries(home, env) {
7515
8736
  return [{
7516
8737
  kind: "hooks-json",
7517
- path: path16.join(qoderConfigDir(home, env), "settings.json"),
7518
- content: hookConfig6()
8738
+ path: path17.join(qoderConfigDir(home, env), "settings.json"),
8739
+ content: hookConfig7()
7519
8740
  }];
7520
8741
  },
7521
8742
  sourcePaths(home, env) {
7522
8743
  const base = qoderConfigDir(home, env);
7523
8744
  return [
7524
- path16.join(base, "projects"),
7525
- path16.join(base, ".qoder.json"),
7526
- path16.join(home, ".qoder.json")
8745
+ path17.join(base, "projects"),
8746
+ path17.join(base, ".qoder.json"),
8747
+ path17.join(home, ".qoder.json")
7527
8748
  ];
7528
8749
  },
7529
8750
  parseSessionFile: parseQoderSessionFile
@@ -7558,21 +8779,21 @@ function normalizeId(id) {
7558
8779
  }
7559
8780
 
7560
8781
  // src/adapters/workbuddy.ts
7561
- import { readFile as readFile11, readdir as readdir8, stat as stat9 } from "node:fs/promises";
7562
- import path17 from "node:path";
8782
+ import { readFile as readFile12, readdir as readdir9, stat as stat10 } from "node:fs/promises";
8783
+ import path18 from "node:path";
7563
8784
  init_fs();
7564
8785
  function workbuddyProjectsDir(home, env) {
7565
8786
  const override = env?.WORKBUDDY_PROJECTS_DIR || env?.WORKBUDDY_HOME;
7566
8787
  if (override && override.trim()) {
7567
- return path17.resolve(override, override.endsWith("projects") ? "" : "projects");
8788
+ return path18.resolve(override, override.endsWith("projects") ? "" : "projects");
7568
8789
  }
7569
- return path17.join(home, ".workbuddy", "projects");
8790
+ return path18.join(home, ".workbuddy", "projects");
7570
8791
  }
7571
8792
  function projectFromCwd(cwd, fallback) {
7572
8793
  if (!cwd) {
7573
8794
  return fallback;
7574
8795
  }
7575
- return path17.basename(cwd) || fallback;
8796
+ return path18.basename(cwd) || fallback;
7576
8797
  }
7577
8798
  function sourceHash(filePath) {
7578
8799
  return `sha256:${createStableHash(filePath)}`;
@@ -7654,7 +8875,7 @@ function contentLength(value) {
7654
8875
  return 0;
7655
8876
  }
7656
8877
  async function readWorkbuddyLines(filePath) {
7657
- const text = await readFile11(filePath, "utf8");
8878
+ const text = await readFile12(filePath, "utf8");
7658
8879
  return text.split(/\r?\n/).map((line, index) => {
7659
8880
  if (!line.trim()) {
7660
8881
  return void 0;
@@ -7674,8 +8895,8 @@ async function parseWorkbuddySessionFile(filePath, options) {
7674
8895
  }
7675
8896
  const events = [];
7676
8897
  const first = lines[0].record;
7677
- const sessionId = stringField(first, "sessionId") || path17.basename(filePath, ".jsonl");
7678
- const fallbackProject = path17.basename(path17.dirname(filePath));
8898
+ const sessionId = stringField(first, "sessionId") || path18.basename(filePath, ".jsonl");
8899
+ const fallbackProject = path18.basename(path18.dirname(filePath));
7679
8900
  const cwd = lines.map((line) => stringField(line.record, "cwd")).find(Boolean);
7680
8901
  const project = projectFromCwd(cwd, fallbackProject);
7681
8902
  const workspaceId = createWorkspaceId({ projectName: project, repoRoot: cwd });
@@ -7844,17 +9065,17 @@ async function workbuddyBackfillFiles(sourceRoot, home, env) {
7844
9065
  const base = sourceRoot || workbuddyProjectsDir(home, env);
7845
9066
  const files = [];
7846
9067
  try {
7847
- const projects = await readdir8(base, { withFileTypes: true });
9068
+ const projects = await readdir9(base, { withFileTypes: true });
7848
9069
  for (const project of projects) {
7849
9070
  if (!project.isDirectory()) {
7850
9071
  continue;
7851
9072
  }
7852
- const projectDir = path17.join(base, project.name);
7853
- const entries = await readdir8(projectDir, { withFileTypes: true });
9073
+ const projectDir = path18.join(base, project.name);
9074
+ const entries = await readdir9(projectDir, { withFileTypes: true });
7854
9075
  for (const entry of entries) {
7855
9076
  if (entry.isFile() && entry.name.endsWith(".jsonl")) {
7856
- const filePath = path17.join(projectDir, entry.name);
7857
- const info = await stat9(filePath);
9077
+ const filePath = path18.join(projectDir, entry.name);
9078
+ const info = await stat10(filePath);
7858
9079
  files.push({ path: filePath, modifiedAt: info.mtime.toISOString() });
7859
9080
  }
7860
9081
  }
@@ -7891,26 +9112,26 @@ function createWorkbuddyAdapter() {
7891
9112
 
7892
9113
  // src/adapters/zcode.ts
7893
9114
  import { execFile } from "node:child_process";
7894
- import { readFile as readFile12, stat as stat10 } from "node:fs/promises";
7895
- import path18 from "node:path";
9115
+ import { readFile as readFile13, stat as stat11 } from "node:fs/promises";
9116
+ import path19 from "node:path";
7896
9117
  import { promisify as promisify2 } from "node:util";
7897
9118
  init_fs();
7898
9119
  var execFileAsync = promisify2(execFile);
7899
9120
  function zcodeCliDir(home, env) {
7900
9121
  const override = env?.ZCODE_CLI_DIR || env?.ZCODE_HOME;
7901
9122
  if (override && override.trim()) {
7902
- return path18.resolve(override, override.endsWith("cli") ? "" : "cli");
9123
+ return path19.resolve(override, override.endsWith("cli") ? "" : "cli");
7903
9124
  }
7904
- return path18.join(home, ".zcode", "cli");
9125
+ return path19.join(home, ".zcode", "cli");
7905
9126
  }
7906
9127
  function zcodeDbPath(home, env) {
7907
- return path18.join(zcodeCliDir(home, env), "db", "db.sqlite");
9128
+ return path19.join(zcodeCliDir(home, env), "db", "db.sqlite");
7908
9129
  }
7909
9130
  var providerNameCache = null;
7910
9131
  async function loadProviderNames(configPath2) {
7911
9132
  let fileMtime = 0;
7912
9133
  try {
7913
- const info = await stat10(configPath2);
9134
+ const info = await stat11(configPath2);
7914
9135
  fileMtime = info.mtimeMs;
7915
9136
  } catch {
7916
9137
  return /* @__PURE__ */ new Map();
@@ -7920,7 +9141,7 @@ async function loadProviderNames(configPath2) {
7920
9141
  }
7921
9142
  const map = /* @__PURE__ */ new Map();
7922
9143
  try {
7923
- const raw = await readFile12(configPath2, "utf-8");
9144
+ const raw = await readFile13(configPath2, "utf-8");
7924
9145
  const config = JSON.parse(raw);
7925
9146
  const providers = config?.provider;
7926
9147
  if (isPlainObject(providers)) {
@@ -7938,7 +9159,7 @@ function sourceHash2(filePath) {
7938
9159
  return `sha256:${createStableHash(filePath)}`;
7939
9160
  }
7940
9161
  function projectFromDirectory(directory) {
7941
- return directory ? path18.basename(directory) || "zcode" : "zcode";
9162
+ return directory ? path19.basename(directory) || "zcode" : "zcode";
7942
9163
  }
7943
9164
  function isoFromMs(value) {
7944
9165
  return timestampFrom(typeof value === "number" ? value : Number(value));
@@ -8094,16 +9315,16 @@ async function parseZCodeDb(filePath, options) {
8094
9315
  if (rows.length === 0) {
8095
9316
  return [];
8096
9317
  }
8097
- let candidate = path18.resolve(filePath);
9318
+ let candidate = path19.resolve(filePath);
8098
9319
  let configPath2 = "";
8099
9320
  for (let i = 0; i < 12; i++) {
8100
- const probe = path18.join(candidate, ".zcode", "v2", "config.json");
9321
+ const probe = path19.join(candidate, ".zcode", "v2", "config.json");
8101
9322
  try {
8102
- await stat10(probe);
9323
+ await stat11(probe);
8103
9324
  configPath2 = probe;
8104
9325
  break;
8105
9326
  } catch {
8106
- const parent = path18.dirname(candidate);
9327
+ const parent = path19.dirname(candidate);
8107
9328
  if (parent === candidate) break;
8108
9329
  candidate = parent;
8109
9330
  }
@@ -8319,9 +9540,9 @@ async function parseZCodeDb(filePath, options) {
8319
9540
  }
8320
9541
  async function zcodeBackfillFiles(sourceRoot, home, env) {
8321
9542
  const candidate = sourceRoot || zcodeDbPath(home, env);
8322
- const filePath = candidate.endsWith(".sqlite") ? candidate : path18.join(candidate, "db", "db.sqlite");
9543
+ const filePath = candidate.endsWith(".sqlite") ? candidate : path19.join(candidate, "db", "db.sqlite");
8323
9544
  try {
8324
- const info = await stat10(filePath);
9545
+ const info = await stat11(filePath);
8325
9546
  return [{ path: filePath, modifiedAt: info.mtime.toISOString() }];
8326
9547
  } catch {
8327
9548
  return [];
@@ -8352,6 +9573,404 @@ function createZCodeAdapter() {
8352
9573
  };
8353
9574
  }
8354
9575
 
9576
+ // src/adapters/zed.ts
9577
+ import os9 from "node:os";
9578
+ import path20 from "node:path";
9579
+ function zedThreadsCandidates(home, env) {
9580
+ const candidates = [];
9581
+ const platform2 = process.platform;
9582
+ if (platform2 === "darwin") {
9583
+ candidates.push(path20.join(home, "Library", "Application Support", "Zed", "threads", "threads.db"));
9584
+ } else if (platform2 === "win32") {
9585
+ const appdata = env?.APPDATA;
9586
+ if (appdata && appdata.trim()) {
9587
+ candidates.push(path20.join(path20.resolve(appdata), "Zed", "threads", "threads.db"));
9588
+ }
9589
+ candidates.push(path20.join(home, "AppData", "Roaming", "Zed", "threads", "threads.db"));
9590
+ } else {
9591
+ const xdgData = env?.XDG_DATA_HOME;
9592
+ if (xdgData && xdgData.trim()) {
9593
+ candidates.push(path20.join(path20.resolve(xdgData), "zed", "threads", "threads.db"));
9594
+ }
9595
+ candidates.push(path20.join(home, ".local", "share", "zed", "threads", "threads.db"));
9596
+ const xdgConfig = env?.XDG_CONFIG_HOME;
9597
+ if (xdgConfig && xdgConfig.trim()) {
9598
+ candidates.push(path20.join(path20.resolve(xdgConfig), "zed", "threads", "threads.db"));
9599
+ }
9600
+ candidates.push(path20.join(home, ".config", "zed", "threads", "threads.db"));
9601
+ }
9602
+ return candidates;
9603
+ }
9604
+ function zedConfigDir(home, env) {
9605
+ const platform2 = process.platform;
9606
+ if (platform2 === "darwin") {
9607
+ return path20.join(home, "Library", "Application Support", "Zed");
9608
+ }
9609
+ if (platform2 === "win32") {
9610
+ const appdata = env?.APPDATA;
9611
+ if (appdata && appdata.trim()) {
9612
+ return path20.join(path20.resolve(appdata), "Zed");
9613
+ }
9614
+ return path20.join(home, "AppData", "Roaming", "Zed");
9615
+ }
9616
+ const xdgConfig = env?.XDG_CONFIG_HOME;
9617
+ if (xdgConfig && xdgConfig.trim()) {
9618
+ return path20.join(path20.resolve(xdgConfig), "zed");
9619
+ }
9620
+ return path20.join(home, ".config", "zed");
9621
+ }
9622
+ function baseZedEvent(event) {
9623
+ return {
9624
+ schemaVersion: AGENT_TIME_SCHEMA_VERSION,
9625
+ source: "zed",
9626
+ agent: "zed",
9627
+ workspaceId: createWorkspaceId({ projectName: event.project, repoRoot: event.cwd }),
9628
+ ...event
9629
+ };
9630
+ }
9631
+ function zedUsageFromRequest(entry) {
9632
+ const input = Math.max(0, numberField(entry, "input_tokens") || 0);
9633
+ const output = Math.max(0, numberField(entry, "output_tokens") || 0);
9634
+ if (input <= 0 && output <= 0) {
9635
+ return void 0;
9636
+ }
9637
+ return {
9638
+ tokensInput: input || void 0,
9639
+ tokensOutput: output || void 0,
9640
+ tokensTotal: input + output
9641
+ };
9642
+ }
9643
+ function filePathFromToolInput(tool, input) {
9644
+ if (!isPlainObject(input)) {
9645
+ return void 0;
9646
+ }
9647
+ const direct = stringField(input, "path") || stringField(input, "file_path") || stringField(input, "filePath");
9648
+ if (direct) {
9649
+ return direct;
9650
+ }
9651
+ if (tool === "save_file") {
9652
+ const paths = arrayField(input, "paths");
9653
+ if (paths && paths.length > 0) {
9654
+ const first = paths[0];
9655
+ if (typeof first === "string") {
9656
+ return first;
9657
+ }
9658
+ }
9659
+ }
9660
+ return void 0;
9661
+ }
9662
+ async function parseZedSessionFile(dbPath, options) {
9663
+ const { DatabaseSync } = await import("node:sqlite");
9664
+ const fzstd = await Promise.resolve().then(() => (init_esm(), esm_exports));
9665
+ const decompress2 = fzstd.decompress;
9666
+ if (!dbPath.endsWith(".db")) {
9667
+ return [];
9668
+ }
9669
+ const db = new DatabaseSync(dbPath, { readOnly: true });
9670
+ const events = [];
9671
+ try {
9672
+ const rows = db.prepare(
9673
+ "SELECT id, data, data_type, updated_at, created_at, summary, folder_paths FROM threads ORDER BY updated_at"
9674
+ ).all();
9675
+ for (const row of rows) {
9676
+ const sessionId = row.id;
9677
+ const threadTs = row.updated_at;
9678
+ if (!threadTs) {
9679
+ continue;
9680
+ }
9681
+ const folderRaw = row.folder_paths || "";
9682
+ const folder = folderRaw.split(/[\n,]/).map((s) => s.trim()).find(Boolean);
9683
+ const cwd = folder || void 0;
9684
+ const project = cwd ? path20.basename(cwd) : row.summary ? row.summary.slice(0, 40) : void 0;
9685
+ let json;
9686
+ try {
9687
+ const bytes = row.data_type === "zstd" ? decompress2(new Uint8Array(row.data)) : new Uint8Array(row.data);
9688
+ json = JSON.parse(new TextDecoder().decode(bytes));
9689
+ } catch {
9690
+ continue;
9691
+ }
9692
+ if (!isPlainObject(json)) {
9693
+ continue;
9694
+ }
9695
+ const modelObj = objectField(json, "model");
9696
+ const model = modelObj ? stringField(modelObj, "model") : void 0;
9697
+ const provider = modelObj ? stringField(modelObj, "provider") : void 0;
9698
+ const requestUsage = objectField(json, "request_token_usage");
9699
+ const messages = arrayField(json, "messages") || [];
9700
+ events.push(baseZedEvent({
9701
+ ts: row.created_at || threadTs,
9702
+ type: "session.started",
9703
+ sessionId,
9704
+ cwd,
9705
+ project,
9706
+ model,
9707
+ provider,
9708
+ operation: "session start",
9709
+ confidence: "partial"
9710
+ }));
9711
+ let currentTurnId;
9712
+ let turnStarted = false;
9713
+ let msgIndex = 0;
9714
+ for (const msg of messages) {
9715
+ msgIndex++;
9716
+ if (!isPlainObject(msg)) {
9717
+ continue;
9718
+ }
9719
+ const userPayload = objectField(msg, "User");
9720
+ const agentPayload = objectField(msg, "Agent");
9721
+ if (userPayload) {
9722
+ if (turnStarted && currentTurnId) {
9723
+ events.push(baseZedEvent({
9724
+ ts: threadTs,
9725
+ type: "turn.completed",
9726
+ sessionId,
9727
+ turnId: currentTurnId,
9728
+ cwd,
9729
+ project,
9730
+ model,
9731
+ provider,
9732
+ operation: "turn completed",
9733
+ confidence: "partial"
9734
+ }));
9735
+ }
9736
+ const requestId = stringField(userPayload, "id") || `${sessionId}:${msgIndex}`;
9737
+ currentTurnId = `turn_${createStableHash([sessionId, requestId]).slice(0, 24)}`;
9738
+ turnStarted = true;
9739
+ events.push(baseZedEvent({
9740
+ ts: threadTs,
9741
+ type: "turn.started",
9742
+ sessionId,
9743
+ turnId: currentTurnId,
9744
+ cwd,
9745
+ project,
9746
+ model,
9747
+ provider,
9748
+ operation: "turn start",
9749
+ confidence: "partial"
9750
+ }));
9751
+ const content = arrayField(userPayload, "content") || [];
9752
+ let promptText = "";
9753
+ for (const part of content) {
9754
+ if (!isPlainObject(part)) {
9755
+ continue;
9756
+ }
9757
+ const text = stringField(part, "Text");
9758
+ if (text) {
9759
+ promptText += text;
9760
+ }
9761
+ }
9762
+ if (promptText) {
9763
+ events.push(baseZedEvent({
9764
+ ts: threadTs,
9765
+ type: "prompt.submitted",
9766
+ sessionId,
9767
+ turnId: currentTurnId,
9768
+ cwd,
9769
+ project,
9770
+ model,
9771
+ provider,
9772
+ operation: "prompt submitted",
9773
+ confidence: "partial",
9774
+ metrics: { prompts: 1, promptChars: promptText.length },
9775
+ refs: stringRefs({ promptHash: `sha256:${createStableHash(promptText)}` })
9776
+ }));
9777
+ }
9778
+ const usageEntry = requestUsage ? objectField(requestUsage, requestId) : void 0;
9779
+ if (usageEntry) {
9780
+ const usage = zedUsageFromRequest(usageEntry);
9781
+ if (usage) {
9782
+ const metrics = {
9783
+ tokensInput: usage.tokensInput,
9784
+ tokensOutput: usage.tokensOutput,
9785
+ tokensTotal: usage.tokensTotal
9786
+ };
9787
+ events.push(baseZedEvent({
9788
+ ts: threadTs,
9789
+ type: "model.usage",
9790
+ sessionId,
9791
+ turnId: currentTurnId,
9792
+ cwd,
9793
+ project,
9794
+ model,
9795
+ provider,
9796
+ operation: "model usage",
9797
+ confidence: "partial",
9798
+ metrics
9799
+ }));
9800
+ }
9801
+ }
9802
+ }
9803
+ if (agentPayload) {
9804
+ const content = arrayField(agentPayload, "content") || [];
9805
+ for (const part of content) {
9806
+ if (!isPlainObject(part)) {
9807
+ continue;
9808
+ }
9809
+ const toolUse = objectField(part, "ToolUse");
9810
+ if (!toolUse) {
9811
+ continue;
9812
+ }
9813
+ const tool = stringField(toolUse, "name") || "unknown";
9814
+ const callId = stringField(toolUse, "id") || `call_${createStableHash([sessionId, currentTurnId || "", tool, msgIndex]).slice(0, 16)}`;
9815
+ const input = objectField(toolUse, "input");
9816
+ events.push(baseZedEvent({
9817
+ ts: threadTs,
9818
+ type: "tool.started",
9819
+ sessionId,
9820
+ turnId: currentTurnId,
9821
+ cwd,
9822
+ project,
9823
+ model,
9824
+ provider,
9825
+ tool,
9826
+ operation: `${tool} started`,
9827
+ metrics: { toolCalls: 1 },
9828
+ refs: stringRefs({ sourceId: callId }),
9829
+ confidence: "exact"
9830
+ }));
9831
+ const toolResults = objectField(agentPayload, "tool_results");
9832
+ const resultEntry = toolResults ? objectField(toolResults, callId) : void 0;
9833
+ const isError = resultEntry ? Boolean(numberField(resultEntry, "is_error")) : false;
9834
+ const success = !isError;
9835
+ events.push(baseZedEvent({
9836
+ ts: threadTs,
9837
+ type: success ? "tool.completed" : "tool.failed",
9838
+ sessionId,
9839
+ turnId: currentTurnId,
9840
+ cwd,
9841
+ project,
9842
+ model,
9843
+ provider,
9844
+ tool,
9845
+ success,
9846
+ operation: success ? `${tool} completed` : `${tool} failed`,
9847
+ refs: stringRefs({ sourceId: callId }),
9848
+ confidence: "exact"
9849
+ }));
9850
+ if (tool === "terminal") {
9851
+ const command = input ? stringField(input, "command") : void 0;
9852
+ events.push(baseZedEvent({
9853
+ ts: threadTs,
9854
+ type: success ? "command.completed" : "command.failed",
9855
+ sessionId,
9856
+ turnId: currentTurnId,
9857
+ cwd,
9858
+ project,
9859
+ model,
9860
+ provider,
9861
+ tool: "terminal",
9862
+ success,
9863
+ operation: success ? "command completed" : "command failed",
9864
+ metrics: { commandCalls: 1 },
9865
+ refs: stringRefs({
9866
+ sourceId: callId,
9867
+ commandHash: command ? `sha256:${createStableHash(String(command))}` : void 0
9868
+ }),
9869
+ confidence: "partial"
9870
+ }));
9871
+ }
9872
+ const filePath = filePathFromToolInput(tool, input);
9873
+ if (filePath) {
9874
+ events.push(baseZedEvent({
9875
+ ts: threadTs,
9876
+ type: toolFileActivityType(tool),
9877
+ sessionId,
9878
+ turnId: currentTurnId,
9879
+ cwd,
9880
+ project,
9881
+ model,
9882
+ provider,
9883
+ tool,
9884
+ success,
9885
+ operation: `${tool} file activity`,
9886
+ fileActivities: [{
9887
+ ts: threadTs,
9888
+ path: filePath,
9889
+ operation: operationForTool(tool)
9890
+ }],
9891
+ refs: stringRefs({ sourceId: callId }),
9892
+ confidence: "partial"
9893
+ }));
9894
+ }
9895
+ }
9896
+ }
9897
+ }
9898
+ if (turnStarted && currentTurnId) {
9899
+ events.push(baseZedEvent({
9900
+ ts: threadTs,
9901
+ type: "turn.completed",
9902
+ sessionId,
9903
+ turnId: currentTurnId,
9904
+ cwd,
9905
+ project,
9906
+ model,
9907
+ provider,
9908
+ operation: "turn completed",
9909
+ confidence: "partial"
9910
+ }));
9911
+ }
9912
+ events.push(baseZedEvent({
9913
+ ts: threadTs,
9914
+ type: "session.ended",
9915
+ sessionId,
9916
+ cwd,
9917
+ project,
9918
+ model,
9919
+ provider,
9920
+ operation: "session end",
9921
+ confidence: "partial"
9922
+ }));
9923
+ }
9924
+ } finally {
9925
+ db.close();
9926
+ }
9927
+ return events.filter((event) => matchesBackfillFilters(event, options));
9928
+ }
9929
+ async function zedBackfillFiles(sourceRoot, home = os9.homedir(), env) {
9930
+ const { stat: stat14 } = await import("node:fs/promises");
9931
+ if (sourceRoot) {
9932
+ if (!sourceRoot.endsWith(".db")) {
9933
+ return [];
9934
+ }
9935
+ const info = await stat14(sourceRoot).catch(() => null);
9936
+ if (!info) {
9937
+ return [];
9938
+ }
9939
+ return [{ path: sourceRoot, modifiedAt: info.mtime.toISOString() }];
9940
+ }
9941
+ for (const candidatePath of zedThreadsCandidates(home, env)) {
9942
+ const info = await stat14(candidatePath).catch(() => null);
9943
+ if (info) {
9944
+ return [{ path: candidatePath, modifiedAt: info.mtime.toISOString() }];
9945
+ }
9946
+ }
9947
+ return [];
9948
+ }
9949
+ function createZedAdapter() {
9950
+ return {
9951
+ id: "zed",
9952
+ label: "Zed",
9953
+ agentName: "zed",
9954
+ kind: "ide",
9955
+ detectPath(home, env) {
9956
+ return zedConfigDir(home, env);
9957
+ },
9958
+ installedPath(home, env) {
9959
+ return path20.join(zedConfigDir(home, env), "vibetime-marker");
9960
+ },
9961
+ async isInstalled() {
9962
+ return false;
9963
+ },
9964
+ installEntries(_home, _env) {
9965
+ return [];
9966
+ },
9967
+ sourcePaths(home, env) {
9968
+ return zedThreadsCandidates(home, env);
9969
+ },
9970
+ parseSessionFile: parseZedSessionFile
9971
+ };
9972
+ }
9973
+
8355
9974
  // src/lib/pricing.ts
8356
9975
  function estimateEventCostUsd(event) {
8357
9976
  if (event.type !== "model.usage") {
@@ -8583,11 +10202,11 @@ function buildSessionRollup(rollupKey, events) {
8583
10202
  bucket.activityCount += 1;
8584
10203
  }
8585
10204
  for (const file of event.fileActivities || []) {
8586
- const displayPath = displayBackfillPath(file.path);
8587
- const pathHash = `sha256:${createStableHash(displayPath)}`;
10205
+ const displayPath2 = displayBackfillPath(file.path);
10206
+ const pathHash = `sha256:${createStableHash(displayPath2)}`;
8588
10207
  const fileRollup = fileRollups.get(pathHash) || {
8589
10208
  pathHash,
8590
- displayPath,
10209
+ displayPath: displayPath2,
8591
10210
  reads: 0,
8592
10211
  writes: 0,
8593
10212
  linesAdded: 0,
@@ -8796,15 +10415,15 @@ function hookCommandFromGroup(group) {
8796
10415
  import { randomUUID } from "node:crypto";
8797
10416
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
8798
10417
  import { homedir, hostname } from "node:os";
8799
- import path19 from "node:path";
10418
+ import path21 from "node:path";
8800
10419
  function configDir(home = homedir()) {
8801
- return path19.join(home, ".vibetime");
10420
+ return path21.join(home, ".vibetime");
8802
10421
  }
8803
10422
  function configPath(home = homedir()) {
8804
- return path19.join(configDir(home), "config.json");
10423
+ return path21.join(configDir(home), "config.json");
8805
10424
  }
8806
10425
  function machineIdPath(home = homedir()) {
8807
- return path19.join(configDir(home), "machine-id");
10426
+ return path21.join(configDir(home), "machine-id");
8808
10427
  }
8809
10428
  function readConfig(home = homedir()) {
8810
10429
  const file = configPath(home);
@@ -8851,15 +10470,15 @@ function defaultMachineName() {
8851
10470
  init_fs();
8852
10471
 
8853
10472
  // src/lib/logger.ts
8854
- import { appendFile, mkdir as mkdir4, rename, stat as stat11 } from "node:fs/promises";
10473
+ import { appendFile, mkdir as mkdir4, rename, stat as stat12 } from "node:fs/promises";
8855
10474
  import { homedir as homedir2 } from "node:os";
8856
- import path20 from "node:path";
10475
+ import path22 from "node:path";
8857
10476
  var MAX_BYTES = 1 * 1024 * 1024;
8858
10477
  function logDir(home = homedir2()) {
8859
- return path20.join(home, ".vibetime", "logs");
10478
+ return path22.join(home, ".vibetime", "logs");
8860
10479
  }
8861
10480
  function logPath(home = homedir2(), name = "cli.log") {
8862
- return path20.join(logDir(home), name);
10481
+ return path22.join(logDir(home), name);
8863
10482
  }
8864
10483
  function serializeError(error) {
8865
10484
  if (error instanceof Error) {
@@ -8869,7 +10488,7 @@ function serializeError(error) {
8869
10488
  }
8870
10489
  async function rotateIfNeeded(file) {
8871
10490
  try {
8872
- const info = await stat11(file);
10491
+ const info = await stat12(file);
8873
10492
  if (info.size > MAX_BYTES) {
8874
10493
  await rename(file, `${file}.1`).catch(() => {
8875
10494
  });
@@ -9034,8 +10653,8 @@ function buildHeaders(token, machine) {
9034
10653
  ...machine?.platform ? { "x-machine-platform": machine.platform } : {}
9035
10654
  };
9036
10655
  }
9037
- function joinUrl(base, path22) {
9038
- return new URL(path22, base.endsWith("/") ? base : `${base}/`).toString();
10656
+ function joinUrl(base, path24) {
10657
+ return new URL(path24, base.endsWith("/") ? base : `${base}/`).toString();
9039
10658
  }
9040
10659
  async function postRollupBatch(remote, rollups, options = {}) {
9041
10660
  const response = await remote.fetchImpl(joinUrl(remote.baseUrl, "/v3/agent/ingest"), {
@@ -9117,6 +10736,8 @@ function createRegistry() {
9117
10736
  registry.register(createQoderCnAdapter());
9118
10737
  registry.register(createWorkbuddyAdapter());
9119
10738
  registry.register(createZCodeAdapter());
10739
+ registry.register(createGrokBuildAdapter());
10740
+ registry.register(createZedAdapter());
9120
10741
  return registry;
9121
10742
  }
9122
10743
  var defaultContext = {
@@ -9629,11 +11250,17 @@ async function listBackfillSourceFiles(source, options, ctx) {
9629
11250
  if (source.id === "copilot") {
9630
11251
  return copilotBackfillFiles(stringOption(options["source-root"]), resolveHome3(options, ctx), ctx.env);
9631
11252
  }
11253
+ if (source.id === "grok-build") {
11254
+ return grokBackfillFiles(stringOption(options["source-root"]), resolveHome3(options, ctx), ctx.env);
11255
+ }
11256
+ if (source.id === "zed") {
11257
+ return zedBackfillFiles(stringOption(options["source-root"]), resolveHome3(options, ctx), ctx.env);
11258
+ }
9632
11259
  const roots = stringOption(options["source-root"]) ? [requiredOption(options, "source-root")] : source.paths;
9633
11260
  const fileLists = await Promise.all(roots.map((r) => listJsonlFiles(r)));
9634
11261
  const files = fileLists.flat().sort().slice(0, numberOption(options.limit) || void 0);
9635
11262
  return Promise.all(files.map(async (filePath) => {
9636
- const info = await stat12(filePath);
11263
+ const info = await stat13(filePath);
9637
11264
  return { path: filePath, modifiedAt: info.mtime.toISOString() };
9638
11265
  }));
9639
11266
  }
@@ -9946,13 +11573,13 @@ function selectBackfillFilesForImport(files, watermarkTs) {
9946
11573
  });
9947
11574
  }
9948
11575
  function backfillIncrementalStatePath(home) {
9949
- return path21.join(home, ".vibetime", "backfill-state.json");
11576
+ return path23.join(home, ".vibetime", "backfill-state.json");
9950
11577
  }
9951
11578
  function syncLocalTriggerStatePath(home) {
9952
- return path21.join(home, ".vibetime", "sync-local-trigger.json");
11579
+ return path23.join(home, ".vibetime", "sync-local-trigger.json");
9953
11580
  }
9954
11581
  function syncLocalTriggerLockPath(home) {
9955
- return path21.join(home, ".vibetime", "sync-local-trigger.lock");
11582
+ return path23.join(home, ".vibetime", "sync-local-trigger.lock");
9956
11583
  }
9957
11584
  function backfillRemoteKey(baseUrl) {
9958
11585
  try {
@@ -10014,7 +11641,7 @@ async function readBackfillIncrementalStateFile(home, ctx) {
10014
11641
  }
10015
11642
  async function writeBackfillIncrementalStateFile(home, file) {
10016
11643
  const statePath = backfillIncrementalStatePath(home);
10017
- await mkdir5(path21.dirname(statePath), { recursive: true });
11644
+ await mkdir5(path23.dirname(statePath), { recursive: true });
10018
11645
  await writeFile4(statePath, `${JSON.stringify(file, null, 2)}
10019
11646
  `, "utf8");
10020
11647
  }
@@ -10063,7 +11690,7 @@ async function readSyncLocalTriggerState(statePath) {
10063
11690
  return nextState;
10064
11691
  }
10065
11692
  async function writeSyncLocalTriggerState(statePath, state) {
10066
- await mkdir5(path21.dirname(statePath), { recursive: true });
11693
+ await mkdir5(path23.dirname(statePath), { recursive: true });
10067
11694
  await writeFile4(statePath, `${JSON.stringify(state, null, 2)}
10068
11695
  `, "utf8");
10069
11696
  }
@@ -10078,12 +11705,12 @@ async function readSyncLocalLock(lockPath) {
10078
11705
  return { pid: lock.pid, startedAt: lock.startedAt };
10079
11706
  }
10080
11707
  async function writeSyncLocalLock(lockPath, lock) {
10081
- await mkdir5(path21.dirname(lockPath), { recursive: true });
11708
+ await mkdir5(path23.dirname(lockPath), { recursive: true });
10082
11709
  await writeFile4(lockPath, `${JSON.stringify(lock, null, 2)}
10083
11710
  `, "utf8");
10084
11711
  }
10085
11712
  async function acquireSyncLocalLock(lockPath, lock) {
10086
- await mkdir5(path21.dirname(lockPath), { recursive: true });
11713
+ await mkdir5(path23.dirname(lockPath), { recursive: true });
10087
11714
  try {
10088
11715
  const handle = await open(lockPath, "wx");
10089
11716
  try {
@@ -10163,10 +11790,10 @@ function syncLocalRunnerEntryArgs(cliPath) {
10163
11790
  if (cliPath.endsWith(".ts")) {
10164
11791
  return ["--import", "tsx", cliPath];
10165
11792
  }
10166
- return [path21.resolve(path21.dirname(cliPath), "../bin/vibetime.mjs")];
11793
+ return [path23.resolve(path23.dirname(cliPath), "../bin/vibetime.mjs")];
10167
11794
  }
10168
11795
  function resolveHome3(options, ctx) {
10169
- return path21.resolve(stringOption(options.home) || ctx.env.HOME || os9.homedir());
11796
+ return path23.resolve(stringOption(options.home) || ctx.env.HOME || os10.homedir());
10170
11797
  }
10171
11798
  function requestedTargets(options) {
10172
11799
  const value = options.target || options.targets;