From f2a3aa6e968239e3983dbaf2ad5d2486b08337c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troed=20S=C3=A5ngberg?= Date: Sat, 13 Jun 2026 23:15:07 +0200 Subject: [PATCH] fix: v0.0.44 - switch debug logging to file --- package.json | 2 +- tui.tsx | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 81d440a..1020cf5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tui.tsx b/tui.tsx index 84f8f4e..35b5be2 100644 --- a/tui.tsx +++ b/tui.tsx @@ -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 | 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 {