mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { truncate } from '../cli/utils'
|
|
import type { LoopSessionOutput } from '../services/loop'
|
|
|
|
export function formatTokens(n: number): string {
|
|
return n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`
|
|
}
|
|
|
|
export function formatSessionOutput(sessionOutput: LoopSessionOutput): string[] {
|
|
const lines: string[] = []
|
|
|
|
if (sessionOutput.messages.length > 0) {
|
|
lines.push('Recent Activity:')
|
|
for (const msg of sessionOutput.messages) {
|
|
const preview = truncate(msg.text.replace(/\n/g, ' ').trim(), 1000)
|
|
lines.push(` [assistant] ${preview}`)
|
|
}
|
|
lines.push('')
|
|
}
|
|
|
|
const costStr = `$${sessionOutput.totalCost.toFixed(4)}`
|
|
const t = sessionOutput.totalTokens
|
|
const tokensStr = `${formatTokens(t.input)} in / ${formatTokens(t.output)} out / ${formatTokens(t.reasoning)} reasoning / ${formatTokens(t.cacheRead)} cache read / ${formatTokens(t.cacheWrite)} cache write`
|
|
lines.push(` Cost: ${costStr} | Tokens: ${tokensStr}`)
|
|
|
|
if (sessionOutput.fileChanges) {
|
|
const fc = sessionOutput.fileChanges
|
|
lines.push(` Files changed: ${fc.files} (+${fc.additions}/-${fc.deletions} lines)`)
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
export function formatAuditResult(auditResult: string): string[] {
|
|
const auditPreview = truncate(auditResult, 300)
|
|
return ['', 'Last Audit:', ` ${auditPreview}`]
|
|
}
|