@ramarivera/coding-agent-langfuse 0.1.54 → 0.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backfill.js +46 -5
- package/package.json +1 -1
package/dist/backfill.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { existsSync, mkdirSync, renameSync, readdirSync, readFileSync, statSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { closeSync, existsSync, mkdirSync, openSync, renameSync, readdirSync, readFileSync, readSync, statSync, writeFileSync, } from "node:fs";
|
|
5
5
|
import { hostname, homedir } from "node:os";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
const allAgents = ["claude", "codex", "grok", "opencode", "pi"];
|
|
@@ -769,10 +769,51 @@ function listFiles(root, predicate) {
|
|
|
769
769
|
return out.sort();
|
|
770
770
|
}
|
|
771
771
|
function parseJsonl(path) {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
772
|
+
const rows = [];
|
|
773
|
+
let fd;
|
|
774
|
+
try {
|
|
775
|
+
fd = openSync(path, "r");
|
|
776
|
+
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
777
|
+
let carry = "";
|
|
778
|
+
let bytesRead = 0;
|
|
779
|
+
do {
|
|
780
|
+
bytesRead = readSync(fd, buffer, 0, buffer.length, null);
|
|
781
|
+
if (bytesRead === 0)
|
|
782
|
+
break;
|
|
783
|
+
carry += buffer.subarray(0, bytesRead).toString("utf8");
|
|
784
|
+
const lines = carry.split(/\r?\n/);
|
|
785
|
+
carry = lines.pop() ?? "";
|
|
786
|
+
for (const line of lines)
|
|
787
|
+
pushJsonlRow(rows, line);
|
|
788
|
+
} while (bytesRead > 0);
|
|
789
|
+
pushJsonlRow(rows, carry);
|
|
790
|
+
}
|
|
791
|
+
catch {
|
|
792
|
+
return rows;
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
if (fd !== undefined) {
|
|
796
|
+
try {
|
|
797
|
+
closeSync(fd);
|
|
798
|
+
}
|
|
799
|
+
catch {
|
|
800
|
+
// Ignore close failures; the caller can still use rows parsed so far.
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return rows;
|
|
805
|
+
}
|
|
806
|
+
function pushJsonlRow(rows, line) {
|
|
807
|
+
const trimmed = line.trim();
|
|
808
|
+
if (trimmed.length === 0)
|
|
809
|
+
return;
|
|
810
|
+
try {
|
|
811
|
+
rows.push(JSON.parse(trimmed));
|
|
812
|
+
}
|
|
813
|
+
catch {
|
|
814
|
+
// Session files may be actively written or partially corrupted.
|
|
815
|
+
// One bad line should not abort the whole collector.
|
|
816
|
+
}
|
|
776
817
|
}
|
|
777
818
|
function asRecord(value) {
|
|
778
819
|
return value && typeof value === "object"
|