Skip to content

Commit a7c7176

Browse files
authored
Merge pull request #74 from Two-Weeks-Team/chore/release-prep
chore: release prep — review feedback + metadata
2 parents 36cb573 + 302d93e commit a7c7176

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opencode-status-hud",
33
"version": "0.1.0",
4-
"description": "Bootstrap package skeleton for OpenCode HUD implementation",
4+
"description": "Real-time usage HUD plugin for OpenCode CLI — shows provider API utilization, context tokens, cost, and agent info",
55
"type": "module",
66
"main": "dist/src/index.js",
77
"types": "dist/src/index.d.ts",

src/fetch-openai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ async function refreshAccessToken(
6060

6161
const data = result.data as Record<string, unknown>
6262
const accessToken = data.access_token
63-
if (typeof accessToken === "string" && accessToken.length > 0) {
64-
return accessToken
63+
if (typeof accessToken === "string" && accessToken.trim().length > 0) {
64+
return accessToken.trim()
6565
}
6666

6767
return null

src/plugin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,21 @@ export function createHudPluginHooks(
544544
runtimeConfig: HudRuntimeConfig = resolveRuntimeConfig(),
545545
runtimeOptions: HudPluginRuntimeOptions = {}
546546
): HudPluginHooks {
547+
const MAX_SESSION_ENTRIES = 50
547548
const sessionRuntimes = new Map<string, SessionRuntime>()
548549
const sessionAgentMap = new Map<string, string>()
549550
let latestSessionKey: string | null = null
550551

552+
function pruneMap<V>(map: Map<string, V>): void {
553+
if (map.size <= MAX_SESSION_ENTRIES) return
554+
const excess = map.size - MAX_SESSION_ENTRIES
555+
const iter = map.keys()
556+
for (let i = 0; i < excess; i++) {
557+
const key = iter.next().value
558+
if (key !== undefined) map.delete(key)
559+
}
560+
}
561+
551562
const registry = createModelRegistry()
552563
const aggregator = createUsageAggregator()
553564
const diskCache = createDiskCache()
@@ -801,6 +812,7 @@ export function createHudPluginHooks(
801812
lastCompletedUsage: null
802813
}
803814
sessionRuntimes.set(sessionKey, created)
815+
pruneMap(sessionRuntimes)
804816
return created
805817
}
806818

@@ -971,6 +983,7 @@ export function createHudPluginHooks(
971983
: undefined
972984
if (name) {
973985
sessionAgentMap.set(toSessionKey(input.sessionID), name)
986+
pruneMap(sessionAgentMap)
974987
}
975988
}
976989
if (input.model && input.provider) {

0 commit comments

Comments
 (0)