@ramarivera/coding-agent-langfuse 0.1.54 → 0.1.56
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/dist/service.js +18 -3
- 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"
|
package/dist/service.js
CHANGED
|
@@ -368,15 +368,30 @@ function renderWindowsScript(command) {
|
|
|
368
368
|
const commandArray = command.map(powershellString).join(", ");
|
|
369
369
|
return `param(
|
|
370
370
|
[switch]$Install,
|
|
371
|
+
[switch]$Run,
|
|
371
372
|
[string]$TaskName = "CodingAgentLangfuse"
|
|
372
373
|
)
|
|
373
374
|
|
|
374
375
|
$Command = @(${commandArray})
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
376
|
+
|
|
377
|
+
function Quote-PowerShellLiteral([string]$Value) {
|
|
378
|
+
return "'" + $Value.Replace("'", "''") + "'"
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if ($Run) {
|
|
382
|
+
& $Command[0] @($Command | Select-Object -Skip 1)
|
|
383
|
+
exit $LASTEXITCODE
|
|
384
|
+
}
|
|
378
385
|
|
|
379
386
|
if ($Install) {
|
|
387
|
+
$ScriptPath = if ($PSCommandPath) { $PSCommandPath } else { $MyInvocation.MyCommand.Path }
|
|
388
|
+
$RunCommand = "& " + (Quote-PowerShellLiteral $ScriptPath) + " -Run"
|
|
389
|
+
$EncodedRunCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($RunCommand))
|
|
390
|
+
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -EncodedCommand $EncodedRunCommand"
|
|
391
|
+
$Trigger = New-ScheduledTaskTrigger -AtLogOn
|
|
392
|
+
$Settings = New-ScheduledTaskSettingsSet -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) -Hidden
|
|
393
|
+
|
|
394
|
+
Stop-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
|
380
395
|
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Settings $Settings -Force | Out-Null
|
|
381
396
|
Start-ScheduledTask -TaskName $TaskName
|
|
382
397
|
}
|