chore: v1.2.1 — remove debug logging and dead code

This commit is contained in:
Troed Sångberg
2026-07-08 13:12:14 +02:00
parent 205701f418
commit 012746359a
2 changed files with 49 additions and 81 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "@troed/oc-ls-stats",
"version": "1.1.5",
"version": "1.2.1",
"type": "module",
"exports": {
"./tui": {
+48 -80
View File
@@ -1,19 +1,9 @@
/** @jsxImportSource @opentui/solid */
import type { TextRenderable } from "@opentui/core"
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
import { createMemo, createSignal } from "solid-js"
import { appendFileSync } from "fs"
import { onCleanup } from "solid-js"
import { processPoll } from "./src/stats.ts"
const DEBUG_ENABLED = false
const DEBUG_LOG = "/tmp/oc-ls-stats-debug.log"
function debug(...args: unknown[]) {
if (!DEBUG_ENABLED) return
try {
const line = `${args.map(a => typeof a === "object" ? JSON.stringify(a) : String(a)).join(" ")}\n`
appendFileSync(DEBUG_LOG, line)
} catch {}
}
type StreamSample = {
at: number
tokens: number
@@ -61,32 +51,23 @@ function stripBaseUrlPath(baseURL: string): string {
}
function extractProviderUrls(config: unknown): string[] {
if (!config || typeof config !== "object") { debug("extractProviderUrls: config is null/undefined or not object"); return [] }
if (!config || typeof config !== "object") return []
const obj = config as Record<string, unknown>
const provider = obj.provider
if (!provider || typeof provider !== "object") { debug("extractProviderUrls: no provider in config"); return [] }
if (!provider || typeof provider !== "object") return []
const urls: string[] = []
let total = 0
let matched = 0
for (const [key, val] of Object.entries(provider as Record<string, unknown>)) {
total++
if (val && typeof val === "object") {
const opts = (val as Record<string, unknown>).options
if (opts && typeof opts === "object") {
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
debug(`extractProviderUrls: provider="${key}" baseURL=${baseURL}`)
if (typeof baseURL === "string" && key.toLowerCase().includes("llama") && !key.toLowerCase().includes("ollama")) {
urls.push(stripBaseUrlPath(baseURL))
matched++
debug(`extractProviderUrls: MATCH provider="${key}" -> ${urls[urls.length-1]}`)
} else {
debug(`extractProviderUrls: SKIP provider="${key}" (llama=${key.toLowerCase().includes("llama")} ollama=${key.toLowerCase().includes("ollama")})`)
}
}
}
}
debug(`extractProviderUrls: total=${total} matched=${matched} urls=${JSON.stringify(urls)}`)
return urls
}
@@ -123,46 +104,46 @@ function SessionPromptRight(props: {
api: Parameters<TuiPlugin>[0]
sessionID: string
tracker: TrackerState
version: () => number
clock: () => number
subscribe: (listener: () => void) => () => void
}) {
const liveTps = createMemo(() => {
props.version()
props.clock()
const rate = props.tracker.lastGeneratedTps
if (!Number.isFinite(rate) || rate <= 0) return undefined
return rate
})
let textRef: TextRenderable | undefined
const prefillRate = createMemo(() => {
props.version()
if (!props.tracker.isPrefilling) return undefined
const rate = props.tracker.lastPrefillRate
if (!Number.isFinite(rate) || rate <= 0) return undefined
return rate
})
const sync = () => {
if (!textRef) return
textRef.content = getStatusText()
props.api.renderer.requestRender()
}
const text = createMemo(() => {
props.clock()
if (props.tracker.failure) return props.tracker.failure
const pp = prefillRate()
const tps = liveTps()
if (props.tracker.isPrefilling && pp) {
const result = `${formatPps(pp)} tps (PP)`
debug(`UI_TEXT="${result}" isPrefilling=${props.tracker.isPrefilling} isGenerating=${props.tracker.isGenerating} failure=${props.tracker.failure} pp=${pp} tps=${tps}`)
return result
const unsubscribe = props.subscribe(sync)
onCleanup(unsubscribe)
return (
<text
ref={(ref: TextRenderable) => {
textRef = ref
sync()
}}
fg={props.api.theme.current.textMuted}
>
{getStatusText()}
</text>
)
function getStatusText() {
const s = props.tracker
if (s.failure) {
return s.failure
}
if (props.tracker.isGenerating && tps) {
const result = `${formatTps(tps)} tps (TG)`
debug(`UI_TEXT="${result}" isPrefilling=${props.tracker.isPrefilling} isGenerating=${props.tracker.isGenerating} failure=${props.tracker.failure} pp=${pp} tps=${tps}`)
return result
const pp = s.isPrefilling && s.lastPrefillRate > 0 ? formatPps(s.lastPrefillRate) : undefined
const tps = s.isGenerating && s.lastGeneratedTps > 0 ? formatTps(s.lastGeneratedTps) : undefined
let result = "- tps (TG)"
if (s.isPrefilling && pp) {
result = `${pp} tps (PP)`
} else if (s.isGenerating && tps) {
result = `${tps} tps (TG)`
}
const result = `- tps (TG)`
debug(`UI_TEXT="${result}" isPrefilling=${props.tracker.isPrefilling} isGenerating=${props.tracker.isGenerating} failure=${props.tracker.failure} pp=${pp} tps=${tps}`)
return result
})
return <>{text() ? <text fg={props.api.theme.current.textMuted}>{text()}</text> : null}</>
}
}
const tui: TuiPlugin = async (api) => {
@@ -184,10 +165,11 @@ const tui: TuiPlugin = async (api) => {
prevPromptTokensBySlot: {},
failure: null,
}
const [version, setVersion] = createSignal(0)
const [clock, setClock] = createSignal(Date.now())
const listeners = new Set<() => void>()
const bump = () => setVersion((value) => value + 1)
const bump = () => {
for (const listener of listeners) listener()
}
const pruneSamples = (now = Date.now()) => {
let changed = false
@@ -247,13 +229,9 @@ const tui: TuiPlugin = async (api) => {
}
}
debug(`pollMetrics: urls=${JSON.stringify(llamaServerUrls)} model=${model}`)
for (const baseUrl of llamaServerUrls) {
debug(`pollMetrics: polling ${baseUrl}`)
const slots = await fetchSlots(baseUrl, model)
debug(`pollMetrics: ${baseUrl} response=${JSON.stringify(slots)}`)
const slotList = Array.isArray(slots) ? slots : slots ? Object.values(slots) : []
debug(`pollMetrics: ${baseUrl} slotList.length=${slotList.length}`)
if (slotList.length === 0) {
tracker.failure = "n/a"
bump()
@@ -264,19 +242,6 @@ const tui: TuiPlugin = async (api) => {
const result = processPoll(slotList, tracker)
bump()
if (result.isPrefilling) {
debug(`PP rate=${Math.round(result.lastPrefillRate)} tps`)
}
if (result.isGenerating) {
debug(`TG rate=${Math.round(result.lastGeneratedTps)} tps`)
}
if (result.ppEnded) {
debug(`PP ended rate=${Math.round(result.lastPrefillRate)} tps`)
}
if (result.tgEnded) {
debug(`TG ended rate=${Math.round(result.lastGeneratedTps)} tps`)
}
}
}
@@ -337,7 +302,6 @@ const tui: TuiPlugin = async (api) => {
})
const timer = setInterval(() => {
setClock(Date.now())
pruneSamples()
}, 1000)
@@ -364,8 +328,12 @@ const tui: TuiPlugin = async (api) => {
api.slots.register({
slots: {
session_prompt_right(_ctx, value) {
debug(`slot_callback: session=${value.session_id}`)
return <SessionPromptRight api={api} sessionID={value.session_id} tracker={tracker} version={version} clock={clock} />
return <SessionPromptRight api={api} sessionID={value.session_id} tracker={tracker} subscribe={(listener) => {
listeners.add(listener)
return () => {
listeners.delete(listener)
}
}} />
},
},
})