mirror of
https://git.sync.wtf/troed/oc-ls-stats.git
synced 2026-08-31 09:43:38 +03:00
fix: v0.0.45 - use Node.js fs for debug logging
This commit is contained in:
+1
-1
@@ -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": {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user