From 012746359a6560f84c5465cb4486abc620365b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troed=20S=C3=A5ngberg?= Date: Wed, 8 Jul 2026 13:12:14 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20v1.2.1=20=E2=80=94=20remove=20debug=20?= =?UTF-8?q?logging=20and=20dead=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- tui.tsx | 128 +++++++++++++++++++-------------------------------- 2 files changed, 49 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index 6614bda..625fe71 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tui.tsx b/tui.tsx index 83b7137..dba8236 100644 --- a/tui.tsx +++ b/tui.tsx @@ -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 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)) { - total++ if (val && typeof val === "object") { const opts = (val as Record).options if (opts && typeof opts === "object") { const baseURL = (opts as Record).baseURL || (opts as Record).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[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 ( + { + textRef = ref + sync() + }} + fg={props.api.theme.current.textMuted} + > + {getStatusText()} + + ) + + 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()} : 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 + return { + listeners.add(listener) + return () => { + listeners.delete(listener) + } + }} /> }, }, })