fix: v0.0.45 - use Node.js fs for debug logging

This commit is contained in:
Troed Sångberg
2026-06-13 23:17:55 +02:00
parent f2a3aa6e96
commit a8bf568b94
2 changed files with 6 additions and 25 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@troed/oc-ls-stats",
"version": "0.0.44",
"version": "0.0.45",
"type": "module",
"exports": {
"./tui": {
+5 -24
View File
@@ -1,31 +1,14 @@
/** @jsxImportSource @opentui/solid */
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
import { createMemo, createSignal } from "solid-js"
import { writeFileSync, appendFileSync } from "fs"
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)
}
try {
const line = `${args.map(a => typeof a === "object" ? JSON.stringify(a) : String(a)).join(" ")}\n`
appendFileSync(DEBUG_LOG, line)
} catch {}
}
type StreamSample = {
@@ -549,8 +532,6 @@ const tui: TuiPlugin = async (api) => {
onPart()
clearInterval(timer)
clearInterval(slotTimer)
if (debugFlushTimer) clearInterval(debugFlushTimer)
debugFlush()
})
try {