fix: v0.0.44 - switch debug logging to file

This commit is contained in:
Troed Sångberg
2026-06-13 23:15:07 +02:00
parent 2d040ed833
commit f2a3aa6e96
2 changed files with 34 additions and 6 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@troed/oc-ls-stats",
"version": "0.0.43",
"version": "0.0.44",
"type": "module",
"exports": {
"./tui": {
+33 -5
View File
@@ -2,6 +2,32 @@
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
import { createMemo, createSignal } from "solid-js"
const DEBUG_LOG = "/tmp/oc-ls-stats-debug.log"
let debugBuf: string[] = []
let debugFlushTimer: ReturnType<typeof setInterval> | null = null
async function debugFlush() {
if (debugBuf.length === 0) return
const data = debugBuf.join("")
debugBuf = []
try {
await fetch(`file://${DEBUG_LOG}`, {
method: "PUT",
body: data,
mode: "no-cors",
})
} catch {}
}
function debug(...args: unknown[]) {
const line = `${args.map(a => typeof a === "object" ? JSON.stringify(a) : String(a)).join(" ")}\n`
debugBuf.push(line)
if (debugBuf.length >= 20) {
debugFlush()
}
if (!debugFlushTimer) {
debugFlushTimer = setInterval(() => { debugFlush(); debugFlushTimer = null }, 5000)
}
}
type StreamSample = {
at: number
tokens: number
@@ -381,7 +407,7 @@ const tui: TuiPlugin = async (api) => {
const now = Date.now()
const nd = generateSlot.next_token?.[0]?.n_decoded ?? 0
console.log(`[oc-ls-stats] gen slot=${slotId} nd=${nd} prevNd=${tracker.generateCapturedDecoded} same=${tracker.generateSlotId === slotId} tps=${tracker.lastGeneratedTps}`)
debug(`gen slot=${slotId} nd=${nd} prevNd=${tracker.generateCapturedDecoded} same=${tracker.generateSlotId === slotId} tps=${tracker.lastGeneratedTps}`)
if (tracker.generateSlotId === slotId) {
if (tracker.generateCapturedDecoded !== null) {
@@ -389,11 +415,11 @@ const tui: TuiPlugin = async (api) => {
const delta = nd - tracker.generateCapturedDecoded
if (dt > 0 && delta > 0) {
tracker.lastGeneratedTps = delta / dt
console.log(`[oc-ls-stats] gen delta=${delta} dt=${dt.toFixed(2)} tps=${tracker.lastGeneratedTps.toFixed(1)}`)
debug(`gen delta=${delta} dt=${dt.toFixed(2)} tps=${tracker.lastGeneratedTps.toFixed(1)}`)
} else if (delta <= 0) {
tracker.lastGeneratedTps = 0
genEnded = true
console.log(`[oc-ls-stats] gen stalled delta=${delta}`)
debug(`gen stalled delta=${delta}`)
}
}
} else {
@@ -401,7 +427,7 @@ const tui: TuiPlugin = async (api) => {
tracker.generateCapturedDecoded = nd
tracker.generateStartAt = now
tracker.lastGeneratedTps = 0
console.log(`[oc-ls-stats] gen new slot id=${slotId} nd=${nd}`)
debug(`gen new slot id=${slotId} nd=${nd}`)
}
} else {
if (tracker.isGenerating) {
@@ -410,7 +436,7 @@ const tui: TuiPlugin = async (api) => {
tracker.generateStartAt = 0
tracker.lastGeneratedTps = 0
genEnded = true
console.log(`[oc-ls-stats] gen no slot found ending`)
debug(`gen no slot found ending`)
}
}
@@ -523,6 +549,8 @@ const tui: TuiPlugin = async (api) => {
onPart()
clearInterval(timer)
clearInterval(slotTimer)
if (debugFlushTimer) clearInterval(debugFlushTimer)
debugFlush()
})
try {